-
Notifications
You must be signed in to change notification settings - Fork 0
/
Quipo.min.js
3 lines (3 loc) · 12.1 KB
/
Quipo.min.js
1
2
3
// QuipoJS 1.1 ~ Copyright (c) 2012 Cedrik Boudreau. Released under MIT license.
// http://www.studioquipo.com
var Qjs=function(){function v(a,c){a=a||b;a.__proto__=v.prototype;a.selector=c||"";return a}function w(a,b){return a?v(w.getDomainSelector(a,b),a):v()}function x(a){return a.filter(function(a){return a!==undefined&&a!==null})}function y(a){return a.length>0?[].concat.apply([],a):a}function z(){var a=navigator.userAgent;var b={};b.browser=A(a);b.os=B(a);b.isMobile=b.os?true:false;b.screen=C();return b}function A(a){var b=a.match(s);return b?b[0]:a}function B(a){var b;for(os in t){var c=a.match(t[os]);if(c){b={name:os==="iphone"||os==="ipad"?"ios":os,version:c[2].replace("_",".")};break}}return b}function C(){return{width:window.innerWidth,height:window.innerHeight}}function D(a){var b=[];while(a.length>0){a=w.map(a,function(a){if((a=a.parentNode)&&a!==document&&b.indexOf(a)<0){b.push(a);return a}})}return b}function E(a,b){return b===undefined?w(a):w(a).filter(b)}function F(a,b){var c=b.split(/\s+/g);return c.indexOf(a)>=0}function G(a,b){return document.defaultView.getComputedStyle(a,"")[b]}function H(a,b){if(a.status===200||a.status===0){if(b.async){var c=M(a,b);I(c,a,b)}}else{J("QjsJS » $.ajax",a,b)}}function I(a,b,c){c.success.call(c.context,a,b)}function J(a,b,c){c.error.call(c.context,a,b,c)}function K(a,b){if(b.contentType)b.headers["Content-Type"]=b.contentType;if(b.dataType)b.headers["Accept"]=f[b.dataType];for(header in b.headers){a.setRequestHeader(header,b.headers[header])}}function L(a,b){a.onreadystatechange={};a.abort();J("QjsJS » $.ajax : timeout exceeded",a,b)}function M(a,b){var c=a.responseText;if(c){if(b.dataType===e.MIME){try{c=JSON.parse(c)}catch(d){c=d;J("Parse Error",a,b)}}else if(b.dataType==="xml"){c=a.responseXML}}return c}function N(a){return/=\?/.test(a)}function O(a,b,c,d,e){b=R(b);var f=Q(a);var g=l[f]||(l[f]=[]);var h=e&&e(c,b);var i={event:b,callback:c,selector:d,proxy:S(h,c,a),delegate:h,index:g.length};g.push(i);a.addEventListener(i.event,i.proxy,false)}function P(a,b,c,d){b=R(b);var e=Q(a);T(e,b,c,d).forEach(function(b){delete l[e][b.index];a.removeEventListener(b.event,b.proxy,false)})}function Q(a){return a._id||(a._id=k++)}function R(a){var b=w.isMobile()?a:n[a];return b||a}function S(a,b,c){var b=a||b;var d=function(a){var d=b.apply(c,[a].concat(a.data));if(d===false){a.preventDefault()}return d};return d}function T(a,b,c,d){return(l[a]||[]).filter(function(a){return a&&(!b||a.event==b)&&(!c||a.fn==c)&&(!d||a.selector==d)})}function U(a){var b=w.extend({originalEvent:a},a);w.each(m,function(c,d){b[c]=function(){this[d]=function(){return true};return a[c].apply(a,arguments)};b[d]=function(){return false}});return b}function V(){var a=w(document.body);a.bind("touchstart",W);a.bind("touchmove",X);a.bind("touchend",Y);a.bind("touchcancel",Z)}function W(a){var b=Date.now();var c=b-(o.last||b);var d=w.isMobile()?a.touches[0]:a;p&&clearTimeout(p);o={el:w($(d.target)),x1:d.pageX,y1:d.pageY,isDoubleTap:c>0&&c<=250?true:false,last:b};setTimeout(ab,q)}function X(a){var b=w.isMobile()?a.touches[0]:a;o.x2=b.pageX;o.y2=b.pageY}function Y(a){if(o.isDoubleTap){o.el.trigger("doubleTap");o={}}else if(o.x2>0||o.y2>0){(Math.abs(o.x1-o.x2)>30||Math.abs(o.y1-o.y2)>30)&&o.el.trigger("swipe")&&o.el.trigger("swipe"+_(o.x1,o.x2,o.y1,o.y2));o.x1=o.x2=o.y1=o.y2=o.last=0;o={}}else{if(o.el!==undefined){o.el.trigger("tap")}p=setTimeout(function(){p=null;o={}},250)}}function Z(a){o={};clearTimeout(p)}function $(a){return"tagName"in a?a:a.parentNode}function _(a,b,c,d){var e=Math.abs(a-b);var f=Math.abs(c-d);if(e>=f){return a-b>0?"Left":"Right"}else{return c-d>0?"Up":"Down"}}function ab(){if(o.last&&Date.now()-o.last>=q){o.el.trigger("longTap");o={}}}var a=Object.prototype,b=[],c="parentNode",d=b.slice,e={TYPE:"GET",MIME:"json"},f={script:"text/javascript, application/javascript",json:"application/json",xml:"application/xml, text/xml",html:"text/html",text:"text/plain"},g=0,h=["touch","tap"],i={touch:"touchstart",tap:"tap"},j=/complete|loaded|interactive/,k=1,l={},m={preventDefault:"isDefaultPrevented",stopImmediatePropagation:"isImmediatePropagationStopped",stopPropagation:"isPropagationStopped"},n={touchstart:"mousedown",touchmove:"mousemove",touchend:"mouseup",tap:"click",doubletap:"dblclick",orientationchange:"resize"},o={},p,q=750,r=["swipe","swipeLeft","swipeRight","swipeUp","swipeDown","doubleTap","longTap"],s=/WebKit\/([\d.]+)/,t={android:/(Android)\s+([\d.]+)/,ipad:/(iPad).*OS\s([\d_]+)/,iphone:/(iPhone\sOS)\s([\d_]+)/,blackberry:/(BlackBerry).*Version\/([\d.]+)/,webos:/(webOS|hpwOS)[\s\/]([\d.]+)/},u=null;w.extend=function(a,b){Array.prototype.slice.call(arguments,1).forEach(function(b){for(key in b)a[key]=b[key]});return a};w.each=function(a,b){var c,d;if(w.toType(a)==="array")for(c=0;c<a.length;c++){if(b.call(a[c],c,a[c])===false)return a}else for(d in a){if(b.call(a[d],d,a[d])===false)return a}return a};w.mix=function(){var a={};for(var b=0,c=arguments.length;b<c;b++){var d=arguments[b];for(var e in d){if(w.isOwnProperty(d,e)&&d[e]!==undefined){a[e]=d[e]}}}return a};w.toType=function(b){return a.toString.call(b).match(/\s([a-z|A-Z]+)/)[1].toLowerCase()};w.isOwnProperty=function(b,c){return a.hasOwnProperty.call(b,c)};w.getDomainSelector=function(a,b){var c=null;var d=[1,9,11];var e=w.toType(a);if(e==="array"){c=x(a)}else if(e==="string"){c=w.query(b||document,a)}else if(d.indexOf(a.nodeType)>=0||a===window){c=[a];a=null}return c};w.map=function(a,b){var c=[];var d;var e;if(w.toType(a)==="array"){for(d=0;d<a.length;d++){var f=b(a[d],d);if(f!=null)c.push(f)}}else{for(e in a){f=b(a[e],e);if(f!=null)c.push(f)}}return y(c)};w.isMobile=function(){u=u||z();return u.isMobile};w.environment=function(){u=u||z();return u};w.isOnline=function(){return navigator.onLine};w.query=function(a,b){if(w.toType(a)==="array"){var c=[];for(var d=0,e=a.length;d<e;d++){c=c.concat(Array.prototype.slice.call(a[d].querySelectorAll(b)))}return c}return Array.prototype.slice.call(a.querySelectorAll(b))};w.ajaxSettings={type:e.TYPE,async:true,success:{},error:{},context:null,dataType:e.MIME,headers:{},xhr:function(){return new window.XMLHttpRequest},crossDomain:false,timeout:0};w.ajax=function(a){var b=w.mix(w.ajaxSettings,a);if(N(b.url))return w.jsonp(b);var c=b.xhr();c.onreadystatechange=function(){if(c.readyState===4){clearTimeout(d);H(c,b)}};c.open(b.type,b.url,b.async);K(c,b);if(b.timeout>0){var d=setTimeout(function(){L(c,b)},b.timeout)}c.send(b.data);return b.async?c:M(c,b)};w.jsonp=function(a){var b="jsonp"+ ++g;var c=document.createElement("script");var d={abort:function(){w(c).remove();if(b in window)window[b]={}}};var e;window[b]=function(f){clearTimeout(e);w(c).remove();delete window[b];I(f,d,a)};c.src=a.url.replace(/=\?/,"="+b);w("head").append(c);if(a.timeout>0){e=setTimeout(function(){L(d,a)},a.timeout)}return d};w.get=function(a,b,c,d){a+=w.serializeParameters(b);return w.ajax({url:a,success:c,dataType:d})};w.post=function(a,b,c,d){return w.ajax({type:"POST",url:a,data:b,success:c,dataType:d,contentType:"application/x-www-form-urlencoded"})};w.json=function(a,b,c){a+=w.serializeParameters(b);return w.ajax({url:a,success:c,dataType:e.MIME})};w.serializeParameters=function(a){var b="?";for(var c in a){if(a.hasOwnProperty(c)){if(b!=="?")b+="&";b+=c+"="+a[c]}}return b==="?"?"":b};w.Event=function(a,b){var c=document.createEvent("Events");c.initEvent(a,true,true,null,null,null,null,null,null,null,null,null,null,null,null);return c};v.prototype=w.fn={forEach:b.forEach,indexOf:b.indexOf,map:function(a){return w.map(this,function(b,c){return a.call(b,c,b)})},slice:function(){return w(d.apply(this,arguments))},instance:function(a){return this.map(function(){return this[a]})},filter:function(a){return w([].filter.call(this,function(b){return b.parentNode&&w.query(b.parentNode,a).indexOf(b)>=0}))},attr:function(a,b){if(w.toType(a)==="string"&&b===undefined){return this[0].getAttribute(a)}else{return this.each(function(){this.setAttribute(a,b)})}},removeAttr:function(a){return this.each(function(){if(this.nodeType===1)this.removeAttribute(a)})},data:function(a,b){return this.attr("data-"+a,b)},val:function(a){if(w.toType(a)==="string"){return this.each(function(){this.value=a})}else{return this.length>0?this[0].value:null}},show:function(){return this.style("display","block")},hide:function(){return this.style("display","none")},height:function(){var a=this.offset();return a.height},width:function(){var a=this.offset();return a.width},offset:function(){var a=this[0].getBoundingClientRect();return{left:a.left+window.pageXOffset,top:a.top+window.pageYOffset,width:a.width,height:a.height}},remove:function(){return this.each(function(){if(this.parentNode!=null){this.parentNode.removeChild(this)}})},text:function(a){return!a?this[0].textContent:this.each(function(){this.textContent=a})},html:function(a){return w.toType(a)==="string"?this.each(function(){this.innerHTML=a}):this[0].innerHTML},append:function(a){return this.each(function(){if(w.toType(a)==="string"){if(a){var b=document.createElement();b.innerHTML=a;this.appendChild(b.firstChild)}}else{this.insertBefore(a)}})},prepend:function(a){return this.each(function(){if(w.toType(a)==="string"){this.innerHTML=a+this.innerHTML}else{var b=this.parentNode;b.insertBefore(a,b.firstChild)}})},empty:function(){return this.each(function(){this.innerHTML=null})},parent:function(a){var b=a?D(this):this.instance(c);return E(b,a)},siblings:function(a){var b=this.map(function(a,b){return Array.prototype.slice.call(b.parentNode.children).filter(function(a){return a!==b})});return E(b,a)},children:function(a){var b=this.map(function(){return Array.prototype.slice.call(this.children)});return E(b,a)},eq:function(a){return a===-1?this.slice(a):this.slice(a,+a+1)},index:function(a){return a?this.indexOf(w(a)[0]):this.parent().children().indexOf(this[0])},get:function(a){return a===undefined?this:this[a]},first:function(){return w(this[0])},last:function(){var a=this.length-1;return w(this[a])},closest:function(a,b){var c=this[0];var d=w(a);if(!d.length)c=null;while(c&&d.indexOf(c)<0){c=c!==b&&c!==document&&c.parentNode}return w(c)},each:function(a){this.forEach(function(b,c){a.call(b,c,b)});return this},addClass:function(a){return this.each(function(){if(!F(a,this.className)){this.className+=" "+a}})},removeClass:function(a){return this.each(function(){if(F(a,this.className)){this.className=this.className.replace(a," ").replace(/\s+/gi," ")}})},toggleClass:function(a){return this.each(function(){if(F(a,this.className)){this.className=this.className.replace(a," ")}else{this.className+=" "+a}})},hasClass:function(a){return F(a,this[0].className)},style:function(a,b){return!b?this[0].style[a]||G(this[0],a):this.each(function(){this.style[a]=b})},on:function(a,b,c){return b===undefined||w.toType(b)==="function"?this.bind(a,b):this.delegate(b,a,c)},off:function(a,b,c){return b===undefined||w.toType(b)==="function"?this.unbind(a,b):this.undelegate(b,a,c)},ready:function(a){if(j.test(document.readyState)){a(w)}else{document.addEventListener("DOMContentLoaded",function(){a(w)},false)}return this},bind:function(a,b){return this.each(function(){O(this,a,b)})},unbind:function(a,b){return this.each(function(){P(this,a,b)})},delegate:function(a,b,c){return this.each(function(d,e){O(e,b,c,a,function(b){return function(c){var d=w(c.target).closest(a,e).get(0);if(d){var f=w.extend(U(c),{currentTarget:d,liveFired:e});return b.apply(d,[f].concat([].slice.call(arguments,1)))}}})})},undelegate:function(a,b,c){return this.each(function(){P(this,b,c,a)})},trigger:function(a){if(w.toType(a)==="string")a=w.Event(a);return this.each(function(){this.dispatchEvent(a)})},serializeArray:function(){var a=[],b;w(d.call(this.get(0).elements)).each(function(){b=w(this);var c=b.attr("type");if(this.nodeName.toLowerCase()!="fieldset"&&!this.disabled&&c!="submit"&&c!="reset"&&c!="button"&&(c!="radio"&&c!="checkbox"||this.checked)){a.push({name:b.attr("name"),value:b.val()})}});return a},serialize:function(){var a=[];this.serializeArray().forEach(function(b){a.push(encodeURIComponent(b.name)+"="+encodeURIComponent(b.value))});return a.join("&")}};h.forEach(function(a){w.fn[a]=function(b){w(document.body).delegate(this.selector,i[a],b);return this}});r.forEach(function(a){w.fn[a]=function(b){return this.on(a,b)}});w(document).ready(function(){V()});return w}();window.Qjs=Qjs;"$"in window||(window.$=Qjs)