forked from intel/appframework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjq.mobi.min.js
22 lines (22 loc) · 10.8 KB
/
jq.mobi.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
var jq=function(){function m(a){return a in k?k[a]:k[a]=RegExp("(^|\\s)"+a+"(\\s|$)")}function i(a,b){return b===void 0?d(a):d(a).filter(b)}function g(){}var f=[],l=f.slice,k=[],j=[],o=1,p=1,d=function(a,b){return new h(a,b)},h=function(a,b){this.length=0;if(a)if(a instanceof h)return a;else if(typeof a=="function")return d(document).ready(a);else if(typeof a=="object")return this[this.length++]=a,this;else if(b!==void 0){if(b instanceof h)return d(b).find(a)}else b=document;else return f;if(dom=
this.selector(a,b)){if(dom.length==void 0)return this[this.length++]=dom,this}else return this;for(var c=0;c<dom.length;c++)this[this.length++]=dom[c];return this};d.map=function(a,b){var c,e=[],d;if(typeof a.length=="number")for(d=0;d<a.length;d++)c=b(a[d],d),c!=null&&e.push(c);else for(d in a)c=b(a[d],d),c!=null&&e.push(c);return e.length>0?[].concat.apply([],e):e};d.each=function(a,b){var c;if(typeof a.length=="number")for(c=0;c<a.length;c++){if(b(c,a[c])===!1)break}else for(c in a)if(b(c,a[c])===
!1)break;return a};d.extend=function(a){if(a==null||typeof a==="undefined")a=this;if(arguments.length==1){for(key in a)this[key]=a[key];return this}else l.call(arguments,1).forEach(function(b){for(key in b)a[key]=b[key]});return a};d.isArray=function(a){return Array.isArray(a)};d.isFunction=function(a){return typeof a=="function"};d.fn=h.prototype={constructor:h,forEach:f.forEach,reduce:f.reduce,push:f.push,indexOf:f.indexOf,concat:f.concat,selector:function(a,b){var c;try{if(a[0]=="#"&&a.indexOf(" ")==
-1)c=b.getElementById(a.replace("#",""));else if(a[0]=a[a.length-1]==">"){var e=document.createElement("div");e.innerHTML=a;c=e.childNodes}else c=b.querySelectorAll(a)}catch(d){}return c},map:function(a){return d.map(this,function(b,c){return a.call(b,c,b)})},each:function(a){this.forEach(function(b,c){a.call(b,c,b)});return this},ready:function(a){(document.readyState=="complete"||document.readyState=="loaded")&&a();document.addEventListener("DOMContentLoaded",a,!1);return this},find:function(a){if(this.length==
0)return null;return d(a,this[0])},html:function(a){if(this.length==0)return null;if(a===void 0)return this[0].innerHTML;for(var b=0;b<this.length;b++)this[b].innerHTML=a;return this},text:function(a){if(this.length==0)return null;if(a===void 0)return this[0].textContent;for(var b=0;b<this.length;b++)this[b].textContent=a;return this},css:function(a,b){if(this.length==0)return null;if(b===void 0&&typeof a=="string")return this[0].style[a];for(var c=0;c<this.length;c++)if(typeof a=="object")for(var e in a)this[c].style[e]=
a[e];else this[c].style[a]=b;return this},empty:function(){for(var a=0;a<this.length;a++)this[a].innerHTML="";return this},hide:function(){return this.css("display","none")},show:function(){return this.css("display","block")},toggle:function(){for(var a=0;a<this.length;a++)this[0].style.display=this[0].style.display=="none"?"block":"none";return this},val:function(a){if(this.length==0)return null;if(a===void 0)return this[0].value;for(var b=0;b<this.length;b++)this[b].value=a;return this},attr:function(a,
b){if(this.length==0)return null;if(b===void 0)return this[0].getAttribute(a);for(var c=0;c<this.length;c++)this[c].setAttribute(a,b);return this},removeAttr:function(a){for(var b=0;b<this.length;b++)this[b].removeAttribute(a);return this},remove:function(){for(var a=0;a<this.length;a++)this[a].parentNode.removeChild(this[a]);return this},addClass:function(a){for(var b=0;b<this.length;b++){var c=this[b].className,e=[],d=this;a.split(/\s+/g).forEach(function(a){d.hasClass(a,d[b])||e.push(a)});this[b].className+=
(c?" ":"")+e.join(" ")}return this},removeClass:function(a){for(var b=0;b<this.length;b++){if(a===void 0){this[b].className="";break}var c=this[b].className;a.split(/\s+/g).forEach(function(a){c=c.replace(m(a),"")});this[b].className=c.trim()}return this},hasClass:function(a,b){if(this.length==0)return!1;b||(b=this[0]);return m(a).test(b.className)},bind:function(a,b){if(!(a==""||a==null)){for(var c=0;c<this.length;c++)(function(c){var d=c._eventID?c._eventID:o++;c._eventID=d;a.split(/\s+/g).forEach(function(a){var f=
function(a){a.originalEvent=a;var d=b.call(c,a);d===!1&&a.preventDefault();return d};j[d+"_"+a]=f;c.addEventListener(a,f,!1)})})(this[c]);return this}},unbind:function(a){if(!(a==""||a==null)){for(var b=0;b<this.length;b++)(function(b){var d=b._eventID;a.split(/s+g/).forEach(function(a){if(j[d+"_"+a]){var f=j[d+"_"+a];delete j[d+"_"+a];b.removeEventListener(a,f,!1)}})})(this[b]);return this}},trigger:function(a,b){if(this.length==0)return this;if(typeof a=="string"){var c=a,a=document.createEvent("Event");
a.type=c;a.target=this[0];a.initEvent(c,!1,!0)}a.data=b;this[0].dispatchEvent(a);return this},append:function(a){var b;for(b=0;b<this.length;b++)a.length&&typeof a!=="string"&&(a=a[0]),typeof a=="string"?this[b].innerHTML+=a:this[b].appendChild(a);return this},prepend:function(a){var b;for(b=0;b<this.length;b++)a.length&&typeof a!=="string"&&(a=a[0]),typeof a=="string"?this[b].innerHTML=a+this[b].innerHTML:this[b].insertBefore(a,this[b].firstChild);return this},get:function(a){a=a==void 0?0:a;return this[a]?
this[a]:null},offset:function(){if(this.length==0)return null;var a=this[0].getBoundingClientRect();return{left:a.left+window.pageXOffset,top:a.top+window.pageYOffset}},data:function(a,b){return this.attr("data-"+a,b)},filter:function(a){return d([].filter.call(this,function(b){return b.parentNode&&d(b.parentNode,a).indexOf(b)>=0}))},is:function(a){return this.length>0&&d(this[0]).filter(a).length>0},submit:function(a){return this.bind("submit",a)},end:function(){return this.prevObject||d()},closest:function(a,
b){var c=this[0],e=d(b||document,a);for(e.length||(c=null);c&&e.indexOf(c)<0;)c=c!==b&&c!==document&&c.parentNode;return d(c)},parents:function(a){for(var b=[],c=this;c.length>0;)c=d.map(c,function(a){if((a=a.parentNode)&&a!==document&&b.indexOf(a)<0)return b.push(a),a});return i(b,a)},parent:function(a){return i(uniq(this.pluck("parentNode")),a)},children:function(a){return i(this.map(function(){return l.call(this.children)}),a)},siblings:function(a){return i(this.map(function(a,c){return l.call(c.parentNode.children).filter(function(a){return a!==
c})}),a)}};"filter,find,closest,parents,parent,children,siblings".split(",").forEach(function(a){var b=d.fn[a];d.fn[a]=function(){var a=b.apply(this,arguments);a.prevObject=this;return a}});var n={type:"GET",beforeSend:g,success:g,error:g,complete:g,context:null,timeout:0};d.jsonP=function(a){var b="jsonp_callback"+ ++p,c="",e=document.createElement("script");abort=function(){d(e).remove();window[b]&&(window[b]=g)};window[b]=function(f){clearTimeout(c);d(e).remove();delete window[b];a.success.call(void 0,
f)};e.src=a.url.replace(/=\?/,"="+b);d("head").append(e);a.timeout>0&&(c=setTimeout(function(){xhr.abort();a.error.call(void 0,xhr,"timeout")},a.timeout));return{}};d.ajax=function(a){try{var b=new window.XMLHttpRequest;settings=a||{};for(key in n)settings[key]||(settings[key]=n[key]);if(!settings.url)settings.url=window.location;if(!settings.contentType)settings.contentType="application/x-www-form-urlencoded";if(!settings.headers)settings.headers={};settings.headers=d.extend({"X-Requested-With":"XMLHttpRequest"},
settings.headers);if(settings.dataType)switch(settings.dataType){case "script":settings.dataType="text/javascript, application/javascript";break;case "json":settings.dataType="application/json";break;case "xml":settings.dataType="application/xml, text/xml";break;case "html":settings.dataType="text/html";break;case "text":settings.dataType="text/plain";break;default:settings.dataType="text/html";break;case "jsonp":return d.jsonP(a)}else settings.dataType="text/html";if(typeof settings.data=="object")settings.data=
d.serialize(settings.data);settings.type.toLowerCase()=="get"&&settings.data&&(settings.url+=settings.url.indexOf("?")==-1?"?"+settings.data:"&"+settings.data);if(/=\?/.test(settings.url))return d.jsonP(settings);var c=settings.dataType,e,f=settings.context;b.onreadystatechange=function(){if(b.readyState==4){clearTimeout(e);var a,d=!1;if(b.status>=200&&b.status<300||b.status==0){if(c=="application/json"&&!/^\s*$/.test(b.responseText))try{a=JSON.parse(b.responseText)}catch(h){d=h}else a=b.responseText;
d?settings.error.call(f,b,"parsererror",d):settings.success.call(f,a,"success",b)}else d=!0,settings.error.call(f,b,"error");settings.complete.call(f,b,d?"error":"success")}};b.open(settings.type,settings.url,!0);if(settings.contentType)settings.headers["Content-Type"]=settings.contentType;for(name in settings.headers)b.setRequestHeader(name,settings.headers[name]);if(settings.beforeSend.call(f,b,settings)===!1)return b.abort(),!1;settings.timeout>0&&(e=setTimeout(function(){b.onreadystatechange=
g;b.abort();settings.error.call(f,b,"timeout")},settings.timeout));b.send(settings.data)}catch(h){console.log(h)}return b};d.get=function(a,b){return this.ajax({url:a,success:b})};d.post=function(a,b,c,d){typeof b=="function"&&(c=b,b={});typeof d=="undefined"&&(d="html");return this.ajax({url:a,type:"POST",data:b,dataType:d,success:c})};d.getJSON=function(a,b,c){typeof b=="function"&&(c=b,b={});return this.ajax({url:a,data:b,success:c,dataType:"json"})};d.serialize=function(a,b){var c=[];if(a instanceof
h)a.each(function(){c.push((b?b+"[]":this.id)+"="+encodeURIComponent(this.value))});else for(var e in a){var f=b?b+"["+e+"]":e,g=a[e];c.push(typeof g=="object"?d.serialize(g,f):f+"="+encodeURIComponent(g))}return c.join("&")};d.parseJSON=function(a){return JSON.parse(a)};_viewport={};d.useViewport=function(a,b){_viewport.portraitWidth=parseInt(a);_viewport.landscapeWidth=parseInt(b);!isNaN(_viewport.portraitWidth)&&!isNaN(_viewport.landscapeWidth)&&(window.addEventListener("orientationchange",function(){_updateViewportOrientation(window.orientation)},
!1),document.addEventListener("appMobi.device.orientation.change",function(){_updateViewportOrientation(AppMobi.device.orientation)},!1),_updateViewportOrientation(window.orientation))};_updateViewportContent=function(a){var b;b=document.getElementsByTagName("head");if(b.length>0){b=b[0];for(var c=document.getElementsByTagName("meta"),d=0;d<c.length;d++)if(c[d].name=="viewport")try{b.removeChild(c[d])}catch(f){}c=document.createElement("meta");c.setAttribute("name","viewport");c.setAttribute("id",
"viewport");c.setAttribute("content",a);b.appendChild(c)}};_updateViewportOrientation=function(a){a=parseInt(a);isNaN(a)&&(a=0);_updateViewportContent("width="+(a==0||a==180?_viewport.portraitWidth:_viewport.landscapeWidth)+", initial-scale=1, maximum-scale=1,user-scalable=no")};(function(a,b){a.os={};a.os.webkit=b.match(/WebKit\/([\d.]+)/)?!0:!1;a.os.android=b.match(/(Android)\s+([\d.]+)/)?!0:!1;a.os.ipad=b.match(/(iPad).*OS\s([\d_]+)/)?!0:!1;a.os.iphone=!a.os.ipad&&b.match(/(iPhone\sOS)\s([\d_]+)/)?
!0:!1;a.os.webos=b.match(/(webOS|hpwOS)[\s\/]([\d.]+)/)?!0:!1;a.os.touchpad=a.os.webos&&b.match(/TouchPad/)?!0:!1;a.os.ios=a.os.ipad||a.os.iphone})(d,navigator.userAgent);return d}();"$"in window||(window.$=jq);