β

zepto小插件imageloader,cookie

xiaofancn 127 阅读
// Zepto.cookie plugin
// 
// Copyright (c) 2010, 2012 
// @author Klaus Hartl (stilbuero.de)
// @author Daniel Lacy (daniellacy.com)
// 
// Dual licensed under the MIT and GPL licenses:
// http://www.opensource.org/licenses/mit-license.php
// http://www.gnu.org/licenses/gpl.html
;(function($){		
		; function cookie (key, value, options) {
            var days, time, result, decode

            // A key and value were given. Set cookie.
            if (arguments.length > 1 && String(value) !== "[object Object]") {
                // Enforce object
                options = $.extend({}, options)

                if (value === null || value === undefined) options.expires = -1

                if (typeof options.expires === 'number') {
                    days = (options.expires * 24 * 60 * 60 * 1000)
                    time = options.expires = new Date()

                    time.setTime(time.getTime() + days)
                }

                value = String(value)

                return (document.cookie = [
                    encodeURIComponent(key), '=',
                    options.raw ? value : encodeURIComponent(value),
                    options.expires ? '; expires=' + options.expires.toUTCString() : '',
                    options.path ? '; path=' + options.path : '',
                    options.domain ? '; domain=' + options.domain : '',
                    options.secure ? '; secure' : ''
                ].join(''))
            }

            // Key and possibly options given, get cookie
            options = value || {}

            decode = options.raw ? function (s) { return s } : decodeURIComponent

            return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null
        }
     
     ; function xcookie(key, value, options){
     			arguments[0] = "xx"+arguments[0];
     			return cookie.apply(null,arguments);
     }
        
     ; $.cookie  = cookie  
     ; $.xcookie = xcookie  
             
})(Zepto)
$.fn.imageloader = function(){
	 this.each(function(ind,ele){
			 var imgSrc = ele.getAttribute('data-src');
			 if(!imgSrc) return;
			 var img = $('<img>').attr('src', imgSrc);		  
       onload = function(){
				 	ele.src =  imgSrc;
				 	delete img;
			 }; 
       onload.call(img[0].onload);
	});
}

jquery 也可以哦。

<script type="text/javascript" crossorigin>
//全局代码异常收集
window.onerror = function (msg, url, lineNo, columnNo, error) {
  var error = 'Error: ' + msg + ' Script: ' + url + ' Position:[' + lineNo + ' / ' + columnNo+ ']StackTrace: ' +  error;
  try{
      $.ajax({url:"http://myhost.com",async:true,dataType:'jsonp',cache:false,data:{"error":error}});
  }catch (error){}
  return false;
};
</script>

//var en = encodeURI('<script src="http://cdn.bootcss.com/jquery/3.2.0/jquery.min.js" type="text/javascript"></script>');

//把上面的en结果填写到下面的en中,才能写入成功。奇怪?????????

document.write(unescape(en));



已有 0 人发表留言,猛击->> 这里 <<-参与讨论


ITeye推荐



作者:xiaofancn
喜欢挑战,对技术有些偏爱。
原文地址:zepto小插件imageloader,cookie, 感谢原作者分享。