From 0ef6df88426e7545095d2bb313cd83559b4c5e8a Mon Sep 17 00:00:00 2001 From: blackout314 Date: Wed, 10 Dec 2014 16:31:25 +0100 Subject: [PATCH] v0.2.0 --- .gitignore | 5 +++++ build/pi.min.js | 4 ++-- package.json | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e5f90d6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +*.sw* +*~ +bin/ +node_modules/ +vendor/ diff --git a/build/pi.min.js b/build/pi.min.js index ff364b7..3740b16 100644 --- a/build/pi.min.js +++ b/build/pi.min.js @@ -1,2 +1,2 @@ -/*! pi 2014-03-31 */ -var feature={version:"0.1.0",DEBUG:!0,addEventListener:!!window.addEventListener,querySelectorAll:!!document.querySelectorAll,classList:!!document.documentElement.classList},pi=document.querySelector.bind(document),pii=document.querySelectorAll.bind(document);pi.debug=function(a,b){"use strict";feature.DEBUG&&console.debug("["+a+"] "+b)},Element.prototype.on=Element.prototype.addEventListener,Element.prototype.rm=Element.prototype.removeEventListener,NodeList.prototype.on=function(a,b){"use strict";var c=0;for(c=0;cc;c++)pi.debug("PUB",a),e[c].apply(pi,f)}},pi.sub=function(a,b){"use strict";return topics[a]||(topics[a]=[]),pi.debug("SUB",a),topics[a].push(b),{topic:a,callback:b}},pi.unsub=function(a){"use strict";var b,c,d=a.topic,e=[];if(topics[d])for(e=topics[d],b=0,c=e.length;c>b;b++)e[b]===a.callback&&(pi.debug("DEL",d),e.splice(b,1))},pi.storage=function(){"use strict";return{set:function(a,b){try{localStorage.setItem(a,b)}catch(c){if("QUOTA_EXCEEDED_ERR"===c.name)throw new Exception(c.name)}},get:function(a){return localStorage.getItem(a)},del:function(a){"undefined"==typeof a?localStorage.clear():localStorage.removeItem(a)},cache:function(a,b,c){var d=(new Date).valueOf(),e="pic",f=0,g={};return g=JSON.parse(this.get(e)||"{}"),"undefined"==typeof b?(f=d-("undefined"!=typeof g[a]?g[a].ttl:0),pi.debug("AGE",f+" key: "+a),!g[a]||null===g||f>1?(this.del(g[a]),!1):g[a].d):(g[a]={d:b,ttl:d+c},void this.set(e,JSON.stringify(g)))}}}(),pi.ajax=function(a){"use strict";var b=new XMLHttpRequest,c=pi.storage.cache(a.type+a.url);return c?void a.success(c):(b.open(a.type,a.url,!0),b.onreadystatechange=function(){return 4!==b.readyState||200!==b.status?void("undefined"!=typeof a.error&&a.error(b.responseText)):(pi.storage.cache(a.type+a.url,b.responseText,a.ttl||6e4),void a.success(b.responseText))},void b.send(a.params||""))},pii.lazyload=function(a,b){"use strict";var c,d,e,f=[],g=function(){},h=function(a){var d=a.getBoundingClientRect();return(d.top>=0&&d.left>=0&&d.top)<=(window.innerHeight||b.documentElement.clientHeight)+c},i=function(){var b,c=f.length,d=0;if(c>0)for(d=0;c>d;d++)b=f[d],b&&h(b)&&("img"!==b.tagName.toLowerCase()?b.style.cssText+="background-image: url('"+b.getAttribute("data-echo")+"');":b.src=b.getAttribute("data-echo"),g(b),f.splice(d,1),c=f.length,d--);else a.removeEventListener("scroll",j),clearTimeout(e)},j=function(){clearTimeout(e),e=setTimeout(i,d)},k=function(b){var e=pii("[data-echo]"),h=b||{},k=0;for(c=parseInt(h.offset||0),d=parseInt(h.throttle||250),g=h.callback||g,k=0;kd;d++)c=this.fnArray[a][b][d],f.rm(b,c);this.eventsArray[a][b]=[],this.fnArray[a][b]=[]}}}(),pii.forEach=function(a,b){"use strict";var c,d=Array.prototype.slice.call(arguments,2),e=0;if("string"==typeof a&&(a=pii(a)),"Object"!=typeof a&&a.length<=0||"string"!=typeof b)return!1;for(d=[a[0]].concat(d);void 0!==(c=a[e++]);)d[0]=c,pi[b].apply(pi,d)},pi.C.feature.classList&&(pi.classAdd=function(a,b){"use strict";"string"==typeof a&&(a=pi(a)),a.classList.add(b)},pi.classDel=function(a,b){"use strict";"string"==typeof a&&(a=pi(a)),a.classList.remove(b)},pi.classHas=function(a,b){"use strict";"string"==typeof a&&(a=pi(a)),a.classList.contains(b)},pi.classToggle=function(a,b){"use strict";"string"==typeof a&&(a=pi(a)),a.classList.toggle(b)},pii.classAdd=function(a,b){"use strict";pii.forEach(a,"classAdd",b)},pii.classDel=function(a,b){"use strict";pii.forEach(a,"classDel",b)},pii.classToggle=function(a,b){"use strict";pii.forEach(a,"classToggle",b)}),pi.S=function(){"use strict";return{set:function(a,b){try{localStorage.setItem(a,b)}catch(c){if("QUOTA_EXCEEDED_ERR"===c.name)throw new Exception(c.name)}},get:function(a){return localStorage.getItem(a)},del:function(a){"undefined"==typeof a?localStorage.clear():localStorage.removeItem(a)},cache:function(a,b,c){var d=(new Date).valueOf(),e="pic",f=0,g={};return g=JSON.parse(this.get(e)||"{}"),"undefined"==typeof b?(f=d-("undefined"!=typeof g[a]?g[a].ttl:0),pi.D.debug("AGE",f+" key: "+a),!g[a]||null===g||f>1?(this.del(g[a]),!1):g[a].d):(g[a]={d:b,ttl:d+c},void this.set(e,JSON.stringify(g)))},namespace:function(a){return{namespace:a+"_",set:function(a,b){pi.S.set(this.namespace+a,b)},get:function(a){return pi.S.get(this.namespace+a)},del:function(a){pi.S.del(this.namespace+a)}}}}}(),pi.A=function(a){"use strict";var b=new XMLHttpRequest,c=pi.S.cache(a.type+a.url);return c?void a.success(c):(b.open(a.type,a.url,!0),b.onreadystatechange=function(){return 4!==b.readyState||200!==b.status?void("undefined"!=typeof a.error&&a.error(b.responseText)):(pi.S.cache(a.type+a.url,b.responseText,a.ttl||6e4),void a.success(b.responseText))},void b.send(a.params||""))},pi.T=function(){var a={};return{pub:function(b,c){"use strict";if(a[b]){var d,e,f=a[b],g=c||[];for(d=0,e=f.length;e>d;d++)pi.D.debug("PUB",b),f[d].apply(pi,g)}},sub:function(b,c){"use strict";return a[b]||(a[b]=[]),pi.D.debug("SUB",b),a[b].push(c),{topic:b,callback:c}},unsub:function(b){"use strict";var c,d,e=b.topic,f=[];if(a[e])for(f=a[e],c=0,d=f.length;d>c;c++)f[c]===b.callback&&(pi.D.debug("DEL",e),f.splice(c,1))}}}(),pi.R=function(){"use strict";function a(a){var c=location.hash.substr(3).split("/"),d=0,e={};for("string"==typeof a&&""===c[0]&&(c=a.split("/")),d=0;d=0&&d.left>=0&&d.top)<=(window.innerHeight||b.documentElement.clientHeight)+c},i=function(){var b,c=f.length,d=0;if(c>0)for(d=0;c>d;d++)b=f[d],b&&h(b)&&("img"!==b.tagName.toLowerCase()?b.style.cssText+="background-image: url('"+b.getAttribute("data-echo")+"');":b.src=b.getAttribute("data-echo"),g(b),f.splice(d,1),c=f.length,d--);else a.removeEventListener("scroll",j),clearTimeout(e)},j=function(){clearTimeout(e),e=setTimeout(i,d)},k=function(b){var e=pii("[data-echo]"),h=b||{},k=0;for(c=parseInt(h.offset||0,10),d=parseInt(h.throttle||250,10),g=h.callback||g,k=0;k