samhuri.net/public/Chalk/zepto.min.js

13 lines
5.8 KiB
JavaScript

var Zepto=function(){function h(a){return a.filter(function(c){return c!==l&&c!==null})}function i(a,c){this.dom=a;this.selector=c}function b(a,c){return c!==l?b(c).find(a):new i(h(a instanceof i?a.dom:a instanceof Array?a:a instanceof Element?[a]:d.call(e.querySelectorAll(a))),a)}var d=[].slice,e=document,g={append:"beforeEnd",prepend:"afterBegin",before:"beforeBegin",after:"afterEnd"},f,m,l;if(String.prototype.trim===l)String.prototype.trim=function(){return this.replace(/^\s+/,"").replace(/\s+$/,
"")};i.prototype=b.fn;b.extend=function(a,c){for(f in c)a[f]=c[f]};camelize=function(a){return a.replace(/-+(.)?/g,function(c,j){return j?j.toUpperCase():""})};b.fn={compact:function(){this.dom=h(this.dom);return this},get:function(a){return a===l?this.dom:this.dom[a]},remove:function(){return this.each(function(a){a.parentNode.removeChild(a)})},each:function(a){this.dom.forEach(a);return this},filter:function(a){return b(this.dom.filter(function(c){return d.call(c.parentNode.querySelectorAll(a)).indexOf(c)>=
0}))},is:function(a){return this.dom.length>0&&b(this.dom[0]).filter(a).dom.length>0},first:function(){this.dom=h([this.dom[0]]);return this},find:function(a){return b(this.dom.map(function(c){return d.call(c.querySelectorAll(a))}).reduce(function(c,j){return c.concat(j)},[]))},closest:function(a){var c=this.dom[0].parentNode;for(a=d.call(e.querySelectorAll(a));c&&a.indexOf(c)<0;)c=c.parentNode;return b(c&&c!==e?c:[])},pluck:function(a){return this.dom.map(function(c){return c[a]})},show:function(){return this.css("display",
"block")},hide:function(){return this.css("display","none")},prev:function(){return b(this.pluck("previousElementSibling"))},next:function(){return b(this.pluck("nextElementSibling"))},html:function(a){return a===l?this.dom.length>0?this.dom[0].innerHTML:null:this.each(function(c){c.innerHTML=a})},attr:function(a,c){return typeof a=="string"&&c===l?this.dom.length>0?this.dom[0].getAttribute(a)||undefined:null:this.each(function(j){if(typeof a=="object")for(f in a)j.setAttribute(f,a[f]);else j.setAttribute(a,
c)})},offset:function(){var a=this.dom[0].getBoundingClientRect();return{left:a.left+e.body.scrollLeft,top:a.top+e.body.scrollTop,width:a.width,height:a.height}},css:function(a,c){if(c===l&&typeof a=="string")return this.dom[0].style[camelize(a)];m="";for(f in a)m+=f+":"+a[f]+";";if(typeof a=="string")m=a+":"+c;return this.each(function(j){j.style.cssText+=";"+m})},index:function(a){return this.dom.indexOf(b(a).get(0))},bind:function(a,c){return this.each(function(j){a.split(/\s/).forEach(function(n){j.addEventListener(n,
c,false)})})},delegate:function(a,c,j){return this.each(function(n){n.addEventListener(c,function(o){for(var k=o.target,p=d.call(n.querySelectorAll(a));k&&p.indexOf(k)<0;)k=k.parentNode;k&&k!==n&&k!==e&&j(k,o)},false)})},live:function(a,c){b(e.body).delegate(this.selector,a,c);return this},hasClass:function(a){return RegExp("(^|\\s)"+a+"(\\s|$)").test(this.dom[0].className)},addClass:function(a){return this.each(function(c){!b(c).hasClass(a)&&(c.className+=(c.className?" ":"")+a)})},removeClass:function(a){return this.each(function(c){c.className=
c.className.replace(RegExp("(^|\\s)"+a+"(\\s|$)")," ").trim()})},trigger:function(a){return this.each(function(c){var j;c.dispatchEvent(j=e.createEvent("Events"),j.initEvent(a,true,false))})}};["width","height"].forEach(function(a){b.fn[a]=function(){return this.offset()[a]}});for(f in g)b.fn[f]=function(a){return function(c){return this.each(function(j){j["insertAdjacent"+(c instanceof Element?"Element":"HTML")](a,c)})}}(g[f]);i.prototype=b.fn;return b}();"$"in window||(window.$=Zepto);
(function(h){function i(b){var d={},e=b.match(/(Android)\s+([0-9\.]+)/),g=b.match(/(iPhone\sOS)\s([0-9_]+)/),f=b.match(/(iPad).*OS\s([0-9_]+)/);b=b.match(/(webOS)\/([0-9\.]+)/);if(e){d.android=true;d.version=e[2]}if(g){d.ios=true;d.version=g[2].replace(/_/g,".");d.iphone=true}if(f){d.ios=true;d.version=f[2].replace(/_/g,".");d.ipad=true}if(b){d.webos=true;d.version=b[2]}return d}h.os=i(navigator.userAgent);h.__detect=i})(Zepto);
(function(h){h.fn.anim=function(i,b,d){var e=[],g,f;for(f in i)f==="opacity"?g=i[f]:e.push(f+"("+i[f]+")");return this.css({"-webkit-transition":"all "+(b||0.5)+"s "+(d||""),"-webkit-transform":e.join(" "),opacity:g})}})(Zepto);
(function(h){var i=document,b={},d;i.ontouchstart=function(e){var g=Date.now(),f=g-(b.last||g);b.target="tagName"in e.touches[0].target?e.touches[0].target:e.touches[0].target.parentNode;d&&clearTimeout(d);b.x1=e.touches[0].pageX;if(f>0&&f<=250)b.isDoubleTap=true;b.last=g};i.ontouchmove=function(e){b.x2=e.touches[0].pageX};i.ontouchend=function(){if(b.isDoubleTap){h(b.target).trigger("doubleTap");b={}}else if(b.x2>0){Math.abs(b.x1-b.x2)>30&&h(b.target).trigger("swipe");b.x1=b.x2=b.last=0}else if("last"in
b)d=setTimeout(function(){d=null;h(b.target).trigger("tap");b={}},250)};i.ontouchcancel=function(){b={}};["swipe","doubleTap","tap"].forEach(function(e){h.fn[e]=function(g){return this.bind(e,g)}})})(Zepto);
(function(h){function i(b,d,e){var g=new XMLHttpRequest;g.onreadystatechange=function(){if(g.readyState==4&&(g.status==200||g.status==0))e(g.responseText)};g.open(b,d,true);g.setRequestHeader("X-Requested-With","XMLHttpRequest");g.send(null)}h.get=function(b,d){i("GET",b,d)};h.post=function(b,d){i("POST",b,d)};h.getJSON=function(b,d){h.get(b,function(e){d(JSON.parse(e))})};h.fn.load=function(b,d){var e=this,g=b.split(/\s/),f;if(!this.length)return this;if(g.length>1){b=g[0];f=g[1]}h.get(b,function(m){e.html(f?
h(document.createElement("div")).html(m).find(f).html():m);d&&d()});return this}})(Zepto);(function(h){var i=[],b;h.fn.remove=function(){return this.each(function(d){if(d.tagName=="IMG"){i.push(d);d.src="data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=";b&&clearTimeout(b);b=setTimeout(function(){i=[]},6E4)}d.parentNode.removeChild(d)})}})(Zepto);