/
iui.min.js
1 lines (1 loc) 路 8.72 KB
/
iui.min.js
1
(function(){var d=20;var b=0;var L=30000;var j=null;var m=null;var g=null;var w=0;var p=0;var a=location.hash;var s="#_";var c=[];var I=0;var C;var F=false;var e="portrait";var r="landscape";window.iui={logging:false,busy:false,animOn:true,ajaxErrHandler:null,httpHeaders:{"X-Requested-With":"XMLHttpRequest"},showPage:function(P,O){if(P){if(P==m){h("page = currentPage = "+P.id);iui.busy=false;return}if(g){g.removeAttribute("selected");A("blur",g);g=null}if(J(P,"dialog")){iui.busy=false;A("focus",P);z(P)}else{A("load",P);var Q=m;A("blur",m);m=P;A("focus",P);if(Q){setTimeout(o,0,Q,P,O)}else{l(P,Q)}}}},showPageById:function(P){var R=E(P);if(R){if(!iui.busy){iui.busy=true;var Q=c.indexOf(P);var O=Q!=-1;if(O){c.splice(Q)}iui.showPage(R,O)}}},goBack:function(){if(!iui.busy){iui.busy=true;c.pop();var O=c.pop();var P=E(O);iui.showPage(P,true)}},replacePage:function(P){var R=E(P);if(R){if(!iui.busy){iui.busy=true;var Q=c.indexOf(P);var O=Q!=-1;if(O){h("error: can't replace page with ancestor")}c.pop();iui.showPage(R,false)}}},showPageByHrefExt:function(P,Q,S,R,O){if(!iui.busy){iui.busy=true;iui.showPageByHref(P,Q,S,R,O)}},showPageByHref:function(P,Q,T,S,O){function R(U){h("xhr.readyState = "+U.readyState);if(U.readyState==4){if((U.status==200||U.status==0)&&!U.aborted){var V=document.createElement("div");V.innerHTML=U.responseText;A("beforeinsert",document.body,{fragment:V});if(S){B(S,V);iui.busy=false}else{iui.insertPages(V)}}else{iui.busy=false;if(iui.ajaxErrHandler){iui.ajaxErrHandler("Error contacting server, please try again later")}}if(O){setTimeout(O,1000,true)}}}iui.ajax(P,Q,T,R)},ajax:function(Q,P,V,O){var T=new XMLHttpRequest();V=V?V.toUpperCase():"GET";if(P&&V=="GET"){Q=Q+"?"+iui.param(P)}T.open(V,Q,true);if(O){T.onreadystatechange=function(){O(T)}}var S=null;if(P&&V!="GET"){T.setRequestHeader("Content-Type","application/x-www-form-urlencoded");S=iui.param(P)}for(var U in iui.httpHeaders){T.setRequestHeader(U,iui.httpHeaders[U])}T.send(S);T.requestTimer=setTimeout(R,L);return T;function R(){try{T.abort();T.aborted=true}catch(W){h(W)}}},param:function(Q){var P=[];for(var O in Q){P[P.length]=encodeURIComponent(O)+"="+encodeURIComponent(Q[O])}return P.join("&").replace(/%20/g,"+")},insertPages:function(U){var P=U.childNodes;var R;for(var Q=0;Q<P.length;++Q){var T=P[Q];if(T.nodeType==1){if(!T.id){T.id="__"+(++I)+"__"}var S=E(T.id);var O;if(S){S.parentNode.replaceChild(T,S);O=E(T.id)}else{O=document.body.appendChild(T)}A("afterinsert",document.body,{insertedNode:O});if(T.getAttribute("selected")=="true"||!R){R=T}--Q}}A("afterinsertend",document.body,{fragment:U});if(R){iui.showPage(R)}},getSelectedPage:function(){for(var O=document.body.firstChild;O;O=O.nextSibling){if(O.nodeType==1&&O.getAttribute("selected")=="true"){return O}}},getAllViews:function(){return document.querySelectorAll("body > *:not(.toolbar)")},isNativeUrl:function(O){for(var P=0;P<iui.nativeUrlPatterns.length;P++){if(O.match(iui.nativeUrlPatterns[P])){return true}}return false},nativeUrlPatterns:[new RegExp("^http://maps.google.com/maps?"),new RegExp("^mailto:"),new RegExp("^tel:"),new RegExp("^http://www.youtube.com/watch\\?v="),new RegExp("^http://www.youtube.com/v/"),new RegExp("^javascript:"),],hasClass:function(O,P){var Q=new RegExp("(^|\\s)"+P+"($|\\s)");return Q.exec(O.getAttribute("class"))!=null},addClass:function(O,P){if(!iui.hasClass(O,P)){O.className+=" "+P}},removeClass:function(O,P){if(iui.hasClass(O,P)){var Q=new RegExp("(\\s|^)"+P+"(\\s|$)");O.className=O.className.replace(Q," ")}}};addEventListener("load",function(P){var Q=iui.getSelectedPage();var O=D();if(Q){j=Q;iui.showPage(Q)}if(O&&(O!=Q)){iui.showPage(O)}setTimeout(f,0);if(typeof window.onorientationchange=="object"){window.onorientationchange=k;F=true;setTimeout(k,0)}setTimeout(u,0);C=setInterval(u,300)},false);addEventListener("unload",function(O){return},false);addEventListener("click",function(R){var Q=y(R.target,"a");if(Q){function O(){Q.removeAttribute("selected")}if(Q.href&&Q.hash&&Q.hash!="#"&&!Q.target){v(Q)}else{if(Q==E("backButton")){iui.goBack()}else{if(Q.getAttribute("type")=="submit"){var P=y(Q,"form");if(P.target=="_self"){P.submit();return}G(P)}else{if(Q.getAttribute("type")=="cancel"){n(y(Q,"form"))}else{if(Q.target=="_replace"){t(Q,Q)}else{if(iui.isNativeUrl(Q.href)){return}else{if(Q.target=="_webapp"){location.href=Q.href}else{if(!Q.target&&Q.href){t(Q,null)}else{return}}}}}}}}R.preventDefault()}},true);addEventListener("click",function(O){var P=y(O.target,"div");if(P&&J(P,"toggle")){P.setAttribute("toggled",P.getAttribute("toggled")!="true");O.preventDefault()}},true);function v(P){function O(){P.removeAttribute("selected")}if(!iui.busy){iui.busy=true;P.setAttribute("selected","true");iui.showPage(E(P.hash.substr(1)));setTimeout(O,500)}}function t(P,Q){function O(){P.removeAttribute("selected")}if(!iui.busy){iui.busy=true;P.setAttribute("selected","progress");iui.showPageByHref(P.href,null,"GET",Q,O)}}function A(P,R,O){if(R){var Q=document.createEvent("UIEvent");Q.initEvent(P,false,false);if(O){for(i in O){Q[i]=O[i]}}R.dispatchEvent(Q)}}function D(){var P;var O=location.hash.match(/#_([^\?_]+)/);if(O){P=O[1]}if(P){P=E(P)}return P}function k(){var O=window.orientation;switch(O){case 0:H(e);break;case 90:case -90:H(r);break}}function u(){if(!F){if((window.innerWidth!=w)||(window.innerHeight!=p)){w=window.innerWidth;p=window.innerHeight;var P=(w<p)?e:r;H(P)}}if(location.hash!=a){var O=location.hash.substr(s.length);if((O=="")&&j){O=j.id}iui.showPageById(O)}}function H(O){document.body.setAttribute("orient",O);if(O==e){iui.removeClass(document.body,r);iui.addClass(document.body,e)}else{if(O==r){iui.removeClass(document.body,e);iui.addClass(document.body,r)}else{iui.removeClass(document.body,e);iui.removeClass(document.body,r)}}setTimeout(scrollTo,100,0,1)}function z(O){g=O;O.setAttribute("selected","true");if(J(O,"dialog")){x(O)}}function x(O){O.onsubmit=function(P){P.preventDefault();G(O)};O.onclick=function(P){if(P.target==O&&J(O,"dialog")){n(O)}}}function n(O){O.removeAttribute("selected")}function l(T,U){if(!T.id){T.id="__"+(++I)+"__"}a=s+T.id;if(!U){location.replace(a)}else{location.assign(a)}c.push(T.id);var S=E("pageTitle");if(T.title){S.innerHTML=T.title}var P=T.getAttribute("ttlclass");S.className=P?P:"";if(T.localName.toLowerCase()=="form"&&!T.target){x(T)}var Q=E("backButton");if(Q){var O=E(c[c.length-2]);if(O&&!T.getAttribute("hideBackButton")){Q.style.display="inline";Q.innerHTML=O.title?O.title:"Back";var R=O.getAttribute("bbclass");Q.className=(R)?"button "+R:"button"}else{Q.style.display="none"}}iui.busy=false}function o(S,R,P){var Q=(P?S:R).getAttribute("axis");clearInterval(C);A("beforetransition",S,{out:true});A("beforetransition",R,{out:false});if(K()&&Q!="y"){M(S,R,P,O)}else{N(S,R,P,Q,O)}function O(){if(!J(R,"dialog")){S.removeAttribute("selected")}C=setInterval(u,300);setTimeout(l,0,R,S);S.removeEventListener("webkitTransitionEnd",O,false);A("aftertransition",S,{out:true});A("aftertransition",R,{out:false});if(P){A("unload",S)}}}function K(){return(iui.animOn)&&(typeof WebKitCSSMatrix=="object")}function N(U,T,Q,R,P){if(R=="y"){(Q?U:T).style.top="100%"}else{T.style.left="100%"}scrollTo(0,1);T.setAttribute("selected","true");var S=100;O();var V=setInterval(O,b);function O(){S-=d;if(S<=0){S=0;clearInterval(V);P()}if(R=="y"){Q?U.style.top=(100-S)+"%":T.style.top=S+"%"}else{U.style.left=(Q?(100-S):(S-100))+"%";T.style.left=(Q?-S:S)+"%"}}}function M(T,S,P,O){S.style.webkitTransitionDuration="0ms";var Q="translateX("+(P?"-":"")+window.innerWidth+"px)";var R="translateX("+(P?"100%":"-100%")+")";S.style.webkitTransform=Q;S.setAttribute("selected","true");S.style.webkitTransitionDuration="";function U(){T.style.webkitTransform=R;S.style.webkitTransform="translateX(0%)"}T.addEventListener("webkitTransitionEnd",O,false);setTimeout(U,0)}function f(){var O=document.createElement("div");O.id="preloader";document.body.appendChild(O)}function G(P){if(!iui.busy){iui.busy=true;iui.addClass(P,"progress");iui.showPageByHref(P.action,q(P),P.method||"GET",null,O)}function O(){iui.removeClass(P,"progress")}}function q(Q){function P(R){for(var S=0;S<R.length;++S){if(R[S].name){O[R[S].name]=R[S].value}}}var O={};P(Q.getElementsByTagName("input"));P(Q.getElementsByTagName("textarea"));P(Q.getElementsByTagName("select"));P(Q.getElementsByTagName("button"));return O}function y(P,O){while(P&&(P.nodeType!=1||P.localName.toLowerCase()!=O)){P=P.parentNode}return P}function J(O,P){return iui.hasClass(O,P)}function B(P,S){var R=P.parentNode;var Q=P;while(R.parentNode!=document.body){R=R.parentNode;Q=Q.parentNode}R.removeChild(Q);var O;while(S.firstChild){O=R.appendChild(S.firstChild);A("afterinsert",document.body,{insertedNode:O})}A("afterinsertend",document.body,{fragment:S})}function E(O){return document.getElementById(O)}function h(){if((window.console!=undefined)&&iui.logging){console.log.apply(console,arguments)}}})();