-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathchocolatechip-lite-min.js
18 lines (15 loc) · 9.18 KB
/
chocolatechip-lite-min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/*
pO\
6 /\
/OO\
/OOOO\
/OOOOOOOO\
((OOOOOOOO))
\:~=++=~:/
ChocolateChip-Lite.js: It's really tiny, but delicious
A JavaScript library for mobile Web app development.
Copyright 2011 Robert Biggs: www.choclatechip-ui.com
License: BSD
Version 1.0
*/
(function(){var $=function(a,b){if(typeof a==='undefined'){return document}if(a===window||a===document){return a}if(typeof a==='object'&&a.nodeType===1){return a}if(!!b){if(typeof b==='string'){return document.querySelector(b+' '+a)}else if(b.nodeType===1){return b.querySelector(a)}}else if(typeof a==='function'){$.ready(function(){return a.call(a)})}else{if(document.querySelector(a)){return document.querySelector(a)}else{return}}return false};$.extend=function(a,b,c){c=c||false;if(!b){b=a;a=$}if(Object.keys){Object.keys(b).forEach(function(p){if(b.hasOwnProperty(p)){Object.defineProperty(a,p,{value:b[p],writable:true,enumerable:c,configurable:true})}})}else{if(!b){b=a;a=this}for(var i in b){a[i]=b[i]}return a}return this};if(!Object.keys){Object.keys=(function(){var hasOwnProperty=Object.prototype.hasOwnProperty,hasDontEnumBug=!({toString:null}).propertyIsEnumerable('toString'),dontEnums=['toString','toLocaleString','valueOf','hasOwnProperty','isPrototypeOf','propertyIsEnumerable','constructor'],dontEnumsLength=dontEnums.length;return function(a){if(typeof a!=='object'&&typeof a!=='function'||a===null)throw new TypeError('Object.keys called on non-object');var b=[];for(var c in a){if(hasOwnProperty.call(a,c))b.push(c)}if(hasDontEnumBug){for(var i=0;i<dontEnumsLength;i++){if(hasOwnProperty.call(a,dontEnums[i]))b.push(dontEnums[i])}}return b}})()};$.extend(Array.prototype,{each:function(a,b){if(typeof a!="function")return;var i,l=this.length;var b=arguments[1];for(i=0;i<l;i++){if(i in this){a.call(b,this[i],i,this)}}}});$.extend($,{version:"1.1",libraryName:"ChocolateChip-Lite",$$:function(a,b){if(!!b){if(typeof b==="string"){return[].slice.apply(document.querySelectorAll(b+" "+a))}else if(b.nodeType===1){return[].slice.apply(b.querySelectorAll(a))}}else{return[].slice.apply(document.querySelectorAll(a))}},make:function(a){var b=[];var c=document.createElement("div");c.innerHTML=a;var i=0;var d=c.childNodes.length;while(i<d){b[i]=c.childNodes[i];i++}return b},replace:function(a,b){b.parentNode.replaceChild(a,b)},processJSON:function(b){var c=document.createElement("script");c.setAttribute("type","text/javascript");var d=$.UIUuid();c.setAttribute("id",d);c.insert(b);$("head").insert(c,"last");$.defer(function(){var a="#"+d;$(a).remove()})}});$.extend(Object.prototype,{each:function(a,b){for(key in this){if(a(key,this[key])===false){return this}}}});$.extend(HTMLElement.prototype,{find:function(a){return $(a,this)},findAll:function(a){return $$(a,this)},previous:function(){return this.previousElementSibling},next:function(){return this.nextElementSibling},first:function(){return this.firstElementChild},last:function(){return this.lastElementChild},ancestor:function(a){if(!a){return false}var b=new RegExp("^#");var c=new RegExp("^.");var d=null;var e=null;var p=this.parentNode;if(!p){return false}if(typeof a==="string"){a.trim()}if(typeof a==="number"){d=a||1;for(var i=1;i<d;i++){if(p.nodeName==="HTML"){return p}else{if(p!==null){p=p.parentNode}}}return p}else if(a.substr(0,1)==="."){e=a.split(".")[1];if(p.nodeName==="BODY"){return false}if(p.hasClass(e)){return p}else{return p.ancestor(a)}}else if(a.substr(0,1)==="#"){e=a.split("#")[1];if(p.getAttribute("id")===e){return p}else{return p.ancestor(a)}}else{if(p.tagName.toLowerCase()===a){return p}else{return p.ancestor(a)}}},text:function(a){if(!!a||a===0){this.innerText=a;return this}else{return this.innerText}},fill:function(a){this.empty();if(typeof a==="string"){this.textContent=a}else{this.insert(a)}return this},empty:function(){this.removeEvents();this.textContent="";return this},remove:function(){this.unbind();this.removeEvents();this.parentNode.removeChild(this)},insert:function(a,b){var c="";if(typeof a==="string"){c=$.make(a)}else if(a.nodeType===1){c=[];c.push(a)}else{c=a}var i=0;var d=c.length;if(!b||b>(this.children.length+1)||b==="last"){while(i<d){this.appendChild(c[i]);i++}}else if(b===1||b==="first"){while(i<d){this.insertBefore(c[i],this.firstElementChild);i++}}else{while(i<d){this.insertBefore(c[i],this.children[b-1]);i++}}return this},prepend:function(a){this.insertAdjacentHTML("afterBegin",a);return this},append:function(a){this.insertAdjacentHTML("beforeEnd",a);return this},before:function(a){this.insertAdjacentHTML("beforeBgin",a);return this},after:function(a){this.inserAdjacentHTML("afterEnd",a);return this},hasClass:function(a){return new RegExp('(?:^|\\s+)'+a+'(?:\\s+|$)').test(this.className)},addClass:function(a){if(!this.hasClass(a)){this.className=[this.className,a].join(' ').replace(/^\s*|\s*$/g,"");return this}},removeClass:function(a){if(this.hasClass(a)){var b=this.className;this.className=b.replace(new RegExp('(?:^|\\s+)'+a+'(?:\\s+|$)','g'),' ').replace(/^\s*|\s*$/g,"");return this}},toggleClass:function(a,b){if(!b){if(!this.hasClass(a)){this.addClass(a)}else{this.removeClass(a)}}else if(b){if(!this.hasClass(a)){this.addClass(a);this.removeClass(b)}else{this.removeClass(a);this.addClass(b)}}return this},css:function(a,b){if(a instanceof Object){for(var c in a){this.style[c]=a[c]}}else if(typeof a==="string"&&(/:/).test(a)&&!b){this.style.cssText+=a}else if(!b){return document.defaultView.getComputedStyle(this,null).getPropertyValue(a.toLowerCase())}else if(b){this.style.cssText+=a+":"+b+";";return this}else{return false}return this},bind:function(a,b){this.addEventListener(a,b,false)},unbind:function(a,b){this.removeEventListener(a,b,false)},removeEvents:function(){var i=0,len=$.events.length;while(i<len){this[$.events[i]]=null;i++}},delegate:function(d,f,g){this.addEventListener(f,function(e){var c=e.target;$.$$(d,this).each(function(a){if(a.isSameNode(c)){g.apply(this,arguments)}else{try{var b=c.ancestor(d);if(a.isSameNode(b)){e.stopPropagation();g.call(this,b)}}catch(err){}}})},false)},trigger:function(a){if(document.createEvent){var b=document.createEvent('Events');b.initEvent(a,true,false);this.dispatchEvent(b)}},xhr:function(b){var o=b?b:{};var c=null;var d=b.error||$.noop;if(!!b){if(!!o.successCallback||!!o.success){c=o.successCallback||o.success}}var e=new XMLHttpRequest(),method=o.method||'get',async=o.async||false,params=o.data||null,i=0;e.queryString=params;e.open(method,o.url,async);if(!!o.headers){for(var f in o.headers){if(o.headers.hasOwnProperty(f)){e.setRequestHeader(f,o.headers[f])}}}e.handleResp=(c!==null)?c:$.noop;function hdl(){if(e.status===0||e.status==200&&e.readyState==4){$.responseText=e.responseText;e.handleResp(e.responseText)}else{if(!!o.errorCallback||!!o.error){var a=o.errorCallback||o.error;a(e)}}}if(async)e.onreadystatechange=hdl;e.send(params);if(!async)hdl();return this},ajax:function(a){return $.xhr(a)},xhrjson:function(b,d){if(d==="undefined"){return this}var c=d.callback;if(typeof c!='function'){c=function(x){return x}}var e=function(){var o=JSON.parse(this.responseText);for(var a in o){$(d[a]).fill(c(o[a]))}};d.successCallback=e;this.xhr(b,d);return this}});$.extend($,{delay:function(a,b){var c=Array.prototype.slice.call(arguments,2);return setTimeout(function(){return a.apply(a,c)},b)},defer:function(a){return $.delay.apply($,[a,1].concat(Array.prototype.slice.call(arguments,1)))},events:['onmousedown','onmouseup','onmouseover','onmouseout','onclick','onmousemove','ondblclick','onerror','onresize','onscroll','onkeydown','onkeyup','onkeypress','onchange','onsubmit','onload','ontouchstart','ontouchmove','ontouchend','ontouchcancel','ongesturestart','ongesturechange','ongestureend','onorientationchange'],loadEvent:function(F){var a=window.onload;if(typeof window.onload!=='function'){window.onload=F}else{window.onload=function(){a();F()}}},DOMReadyList:[],executeWhenDOMReady:function(){var a=$.DOMReadyList.length;var i=0;while(i<a){$.DOMReadyList[i]();i++}$.DOMReadyList=null;document.removeEventListener('DOMContentLoaded',$.executeWhenDOMReady,false)},ready:function(a){if($.DOMReadyList.length===0){document.addEventListener('DOMContentLoaded',$.executeWhenDOMReady,false)}$.DOMReadyList.push(a)},importScript:function(a){var b=document.createElement("script");b.setAttribute("type","text/javascript");b.setAttribute("src",a);$("head").appendChild(b)},templates:{},template:function(c,d){if($.ajaxStatus===null||$.ajaxStatus===false){return d}if($.templates[c]){c=$.templates[c]}else{c=c}var e='var p=[],print=function(){p.push.apply(p,arguments);};with(obj||{}){p.push(\'';var f;var g;if(/\{\{/.test(c)||(/$\{/).test(c)){f=/\$\{([\s\S]+?)\}/g;g=/\{\{([\s\S]+?)\}\}/g}else if(/\[\[/.test(c)||(/$\[/).test(c)){f=/\$\[([\s\S]+?)\]/g;g=/\[\[([\s\S]+?)\]\]/g}else if(/<%=/.test(c)||(/<%/).test(c)){f=/<%=([\s\S]+?)%>/g;g=/<%([\s\S]+?)%>/g}e+=c.replace(/\\/g,'\\\\').replace(/'/g,"\\'").replace(f,function(a,b){return"',"+b.replace(/\\'/g,"'")+",'"}).replace(g||null,function(a,b){return"');"+b.replace(/\\'/g,"'").replace(/[\r\n\t]/g,' ')+"p.push('"}).replace(/\r/g,'\\r').replace(/\n/g,'\\n').replace(/\t/g,'\\t')+"');} return p.join('');";var h=new Function('obj',e);return d?h(d):h}});window.$chocolatechip=$;window.$$chocolatechip=$.$$;if(typeof window.$==='undefined'){window.$chocolatechip=window.$=$;window.$$chocolatechip=window.$$=$.$$}})();