1 |
- (function(a,b){if(document.MBLOADED){return}if(typeof define==="function"&&(define.amd||define.cmd)){define("mobilebone",function(c){return b(a,c)})}else{a.Mobilebone=b(a,{})}})(this,function(g,b){if(document.MBLOADED){return"Don't repeat load Mobilebone!"}var i={};var e=[];var h=e.slice;var f=/^#?\w+(?:[\-_]\w+)*$/i;var c="WebkitAppearance" in document.documentElement.style||typeof document.webkitHidden!="undefined";var j="pushState" in history&&"replaceState" in history;b.support=j;var a=false;b.VERSION="2.6.2";b.captureLink=true;b.captureForm=true;b.rootTransition=g;b.mergeCallback=true;b.classAnimation="slide";b.classPage="page";b.classMask="mask";b.pushStateEnabled=true;b.evalScript=false;if((window.navigator.userAgent.indexOf("Firefox")>=0&&window.top!==window)){b.pushStateEnabled=false}if(j==false){return b}history.popstate=false;b.transition=function(G,o,y,m){if(arguments.length==0||G==o){return}if(arguments.length==3&&isNaN(y*1)==true){m=y;y=m.back}o=o||null,y=y||false,m=m||{};var s={root:this.rootTransition,form:this.form||this.classAnimation,onpagefirstinto:this.onpagefirstinto,animationstart:this.animationstart,animationend:this.animationend,preventdefault:this.preventdefault,fallback:this.fallback,callback:this.callback},F=function(J){if(!J||!J.getAttribute){return{}}var I={},K=d(J.getAttribute("data-params")||"");["title","root","form"].forEach(function(L){I[L]=J.getAttribute("data-"+L)||K[L]||m[L]||s[L]});if(typeof I.root=="string"){I.root=b.getFunction(I.root)}["onpagefirstinto","callback","fallback","animationstart","animationend","preventdefault"].forEach(function(L){if(b.mergeCallback==true&&typeof s[L]=="function"){var M=J.getAttribute("data-"+L)||K[L];if(typeof I.root[M]=="function"){I[L]=function(){s[L].apply(this,arguments);I.root[M].apply(this,arguments)}}else{if(typeof m[L]=="function"){I[L]=function(){s[L].apply(this,arguments);m[L].apply(this,arguments)}}else{I[L]=s[L]}}}else{I[L]=J.getAttribute("data-"+L)||K[L]||m[L]||s[L]}});return I};var p=F(o),l=F(G);if(o!=null&&o.classList){var w=p.preventdefault,k=false;if(typeof w=="string"){w=p.root[w]}}if(G!=null&&G.classList){var u=l.preventdefault,t=false;if(typeof u=="string"){u=l.root[u]}}if(typeof w=="function"){k=w.call(p.root,G,o,m)}if(k==true&&w===u){return false}if(typeof u=="function"){t=u.call(l.root,G,o,m)}if(t==true){return false}var v=function(J,I){if(J.flagAniBind==true){return}["animationstart","animationend"].forEach(function(N,M){var K=l[N],O="webkit"+N.replace(/^a|s|e/g,function(P){return P.toUpperCase()});var L=c?O:N;if(M){J.addEventListener(L,function(){if(this.classList.contains("in")==false){this.style.display="none";if(this.removeSelf==true){this.parentElement.removeChild(this);this.removeSelf=null}}this.classList.remove(F(this).form)})}if(typeof K=="string"&&l.root[K]){J.addEventListener(L,function(){I.root[K].call(I.root,this,this.classList.contains("in")?"into":"out",m)})}else{if(typeof K=="function"){J.addEventListener(L,function(){K.call(I.root,this,this.classList.contains("in")?"into":"out",m)})}}J.flagAniBind=true})};if(o!=null&&o.classList){if(k!=true){o.classList.add(p.form);o.offsetWidth=o.offsetWidth;o.style.display="block";o.classList.add("out");o.classList.remove("in");o.classList[y?"add":"remove"]("reverse");o.removeSelf=o.removeSelf||null;v(o,p);var z=p.fallback;if(typeof z=="string"){z=p.root[z]}if(typeof z=="function"){z.call(p.root,G,o,m)}}}if(G!=null&&G.classList){var H=l.title,C=document.querySelector("h1"),q=document.querySelector("."+this.classPage);if(H&&m.title!==false){document.title=H;if(C){C.innerHTML=H;C.title=H}}else{if(q==G&&!o&&document.title){G.setAttribute("data-title",document.title)}}var r=m.id||G.id,E=m.id||G.id;if(m.id){r=r.split("?")[0]}var A=i["_"+r];if(m.remove!==false&&i[r]&&i[r]!=G){if(A&&i[A]&&m.reload==true){delete i[A];delete i["_"+r]}if(i[r]!=o){i[r].parentElement&&i[r].parentElement.removeChild(i[r])}else{o.removeSelf=true}delete i[r]}if(o){G.classList.add(l.form)}G.offsetWidth=G.offsetWidth;G.style.display="block";G.classList.remove("out");G.classList.add("in");G.classList[y?"add":"remove"]("reverse");var D=l.onpagefirstinto;if(!G.firstintoBind){if(typeof D=="string"&&l.root[D]){l.root[D].call(l.root,G,o,m)}else{if(typeof D=="function"){D.call(l.root,G,o,m)}}h.call(G.querySelectorAll("form")).forEach(function(I){b.submit(I)});G.firstintoBind=true}v(G,l);var B=E,x="";if(B&&/^#/.test(B)==false){B="#"+B}x=B.replace(/^#/,"#&");if(j&&this.pushStateEnabled&&m.history!==false&&B&&x!=location.hash){history.popstate=false;history[o?"pushState":"replaceState"](null,document.title,B.replace(/^#/,"#&"))}if(!i[r]){i[r]=G;if(E!==r){i[E]=G;i["_"+r]=E}}var n=l.callback;if(typeof n=="string"){n=l.root[n]}if(typeof n=="function"){n.call(l.root,G,o,m)}setTimeout(function(){history.popstate=true},17)}};b.getCleanUrl=function(m,k,n){var l="",t="",q="";if(m){if(m.nodeType==1){if(m.action){l=m.getAttribute("action");if(m.method&&m.method.toUpperCase()=="POST"){return l}else{if(window.$&&$.fn&&$.fn.serialize){t=$(m).serialize()}else{t={};h.call(m.querySelectorAll("input,select,textarea")).forEach(function(v){if(v.name&&!v.disabled){var w=v.value.trim(),u=v.name;if(/^radio|checkbox/i.test(v.type)){if(v.checked){if(t[u]){t[u].push(w)}else{t[u]=[w]}}}else{t[u]=[w]}}})}}}else{l=m.getAttribute("href");t=m.getAttribute("data-formdata")||m.getAttribute("data-data")||"";var s="container",o=m.getAttribute("data-"+s);if(t.indexOf(s)==-1&&o){var r=s+"="+o;t=t?t+"&"+r:r}}}else{if(m.url){l=m.url;t=m.data}}}if(!(l=l||k)){return""}t=t||n||"";if(typeof t=="object"){var p=[];for(key in t){if(!t[key].forEach){t[key]=[t[key]]}t[key].forEach(function(u){p.push(key+"="+encodeURIComponent(u))})}if(p.length>0){t=p.join("&")}else{t=""}}q=l.split("#")[0].replace(/&+$/,"");if(q.slice(-1)=="?"){q=q.split("?")[0]}if(t!=""){if(/\?/.test(q)){t=t.replace(/^&|\?/,"");q=q+"&"+t}else{if(t!=""){t=t.replace("?","");q=q+"?"+t}}}return q};b.createPage=function(v,p,z){var s=null,m=null,q=this.classPage,x=null;if(!v){return}if(typeof z=="undefined"&&typeof p=="object"){z=p}z=z||{};var l={};var o,y,r;if(p){if(p.nodeType==1){if(p.href||p.action){o=p.getAttribute("data-title")||z.title}s=z.response;y=p.getAttribute("data-container");m=document.getElementById(y);r=p.getAttribute("data-classpage");l.target=p;x=p.getAttribute("data-reload");if(p.tagName.toLowerCase()=="form"||(x!==null&&x!="false")){l.reload=true}l.back=p.getAttribute("data-rel")=="back";if(p.getAttribute("data-history")=="false"){l.history=false}}else{s=p.response||z.response;o=p.title||z.title;m=p.container||z.container;r=p.classPage||z.classPage;l.target=p.target;l.back=p.back||z.back}if(m&&r){q=r}}var w=(q==r?m:document).querySelector(".in."+q);var t=null;var u=document.createElement("div");if(typeof v=="string"){u.innerHTML=v}else{u.appendChild(v)}if(b.evalScript==true&&v.firstintoBind!=true){h.call(u.getElementsByTagName("script")).forEach(function(B){var A=B.innerHTML.trim(),E=B.getAttribute("type");if(A.trim()==""||B.src){return}var D=document.getElementsByTagName("head")[0]||document.documentElement,C=document.createElement("script");if(E){C.type=E}C.appendChild(document.createTextNode(A));setTimeout(function(){D.insertBefore(C,D.firstChild);D.removeChild(C);C=null},17);B=null})}var k=u.getElementsByTagName("title")[0];if(!(t=u.querySelector("."+q))){u.className=q+" out";t=u}if(typeof o=="string"){t.setAttribute("data-title",o)}else{if(k&&k.innerText){t.setAttribute("data-title",k.innerText)}}l.response=s||v;l.id=this.getCleanUrl(p)||t.id||("unique"+Date.now());if(typeof z=="object"){if(typeof z.history!="undefined"){l.history=z.history}if(typeof z.remove!="undefined"){l.remove=z.remove}if(typeof z.target!="undefined"){l.target=z.target}if(typeof z.title!="undefined"){l.title=z.title}}if(q==r){l.history=false;l.classPage=q}m=m||document.body;var n=l.id.split("?")[0];if(n&&i[n]&&m.contains(i[n])){m.insertBefore(t,i[n])}else{m.appendChild(t)}u=null;this.transition(t,w,l)};b.getFunction=function(n){if(typeof n!="string"){return}var k=g,m=n.split(".");for(var l=0;l<m.length;l+=1){if(!(k=k[m[l]])){break}}return k};b.ajax=function(s){if(!s){return}var q={url:"",type:"",dataType:"",data:{},timeout:10000,async:true,username:"",password:"",success:function(){},error:function(){},complete:function(){}};var p={},k=null,n=null;var u={},v;if(s.nodeType==1){u=d(s.getAttribute("data-params")||"");for(key in q){p[key]=s.getAttribute("data-"+key)||u[key]||q[key];if(typeof q[key]=="function"&&typeof p[key]=="string"){p[key]=this.getFunction(p[key]);if(typeof p[key]!="function"){p[key]=q[key]}}}p.url=this.getCleanUrl(s,p.url);p.target=s;p.back=s.getAttribute("data-rel")=="back";var m=s.tagName.toLowerCase();if(m=="form"){p.type=s.method;n=new FormData(s)}else{if(m=="a"){var t=s.getAttribute("data-container"),o=s.getAttribute("data-classpage"),l=t&&document.getElementById(t);if(l&&o&&o!=b.classPage){p.history=false;p.title=false}}}v=s.getAttribute("data-mask");if(v=="true"||v==""){k=s.querySelector("."+this.classMask)}}else{if(s.url){for(key2 in q){p[key2]=s[key2]||q[key2]}p.url=this.getCleanUrl(null,p.url,p.data);p.title=s.title;p.back=s.back;p.container=s.container}else{return}}var r=l||document.body;if(typeof v!="string"){k=r.querySelector("."+this.classMask)}if(k==null){k=document.createElement("div");k.className=this.classMask;k.innerHTML='<i class="loading"></i>';if(typeof v=="string"){s.appendChild(k)}else{r.appendChild(k)}}k.style.display="block";var w=new XMLHttpRequest();w.open(p.type||"GET",p.url+(/\?/.test(p.url)?"&":"?")+"r="+Date.now(),p.async,p.username,p.password);w.timeout=p.timeout;w.onload=function(){var x=null;if(w.status==200){if(p.dataType=="json"||p.dataType=="JSON"){try{x=JSON.parse(w.response);p.response=x;b.createPage(b.jsonHandle(x),s,p)}catch(y){p.message="JSON parse error:"+y.message;p.error.call(p,w,w.status)}}else{if(p.dataType=="unknown"){p.history=false;try{x=JSON.parse(w.response);p.response=x;b.createPage(b.jsonHandle(x),s,p)}catch(y){x=w.response;b.createPage(x,s,p)}}else{x=w.response;b.createPage(x,s,p)}}p.success.call(p,x,w.status)}else{p.message="The status code exception!";p.error.call(p,w,w.status)}p.complete.call(p,w,w.status);k.style.display="none"};w.onerror=function(x){p.message="Illegal request address or an unexpected network error!";p.error.call(p,w,w.status);k.style.display="none"};w.ontimeout=function(){p.message="The request timeout!";p.error.call(p,w,w.status);k.style.display="none"};w.setRequestHeader("Type","ajax");w.setRequestHeader("From","mobilebone");w.send(n)};b.submit=function(k){if(!k||typeof k.action!="string"){return}var l=k.getAttribute("data-ajax");if(l=="false"||(b.captureForm==false&&l!="true")){return}k.addEventListener("submit",function(n){var o=this.getAttribute("data-preventdefault");var m=b.getFunction(o);if(typeof m=="function"&&m(this)==true){n.preventDefault();return false}b.ajax(this);n.preventDefault()})};b.isBack=function(k,l){if(history.tempBack==true){history.tempBack=null;return true}if(typeof k=="undefined"){return true}if(!l){return false}return k.compareDocumentPosition(l)==4};b.jsonHandle=function(k){return'<p style="text-align:center;">Dear master, if you see me, show that JSON parsing function is undefined!</p>'},b.init=function(){if(a==true){return"Don't repeat initialization!"}var m=location.hash.replace("#&","#"),n=null,k=null;if(m==""||m=="#"){this.transition(document.querySelector("."+this.classPage))}else{if(f.test(m)==true&&(n=document.querySelector(m))&&n.classList.contains(this.classPage)){this.transition(n)}else{if(m.split("container=").length==2){k=document.getElementById(m.split("container=")[1].split("&")[0])}this.ajax({url:m.replace("#",""),dataType:"unknown",container:k,error:function(){n=document.querySelector("."+b.classPage);b.transition(n)}})}}var l=g.$||g.jQuery||g.Zepto;if(l&&l.fn&&l.fn.tap&&("ontouchstart" in window==true)){l(document).tap(this.handleTapEvent);document.addEventListener("click",function(q){var s=q.target;if(!s){return}if(s.tagName.toLowerCase()!="a"&&!(s=s.getParentElementByTag("a"))){return}var r=s.getAttribute("data-ajax"),p=s.href;if(s.getAttribute("data-rel")=="external"||r=="false"||(p.replace("://","").split("/")[0]!==location.href.replace("://","").split("/")[0]&&r!="true")||(b.captureLink==false&&r!="true")){if(/^http/i.test(p)){location.href=p}return}q.preventDefault()})}else{document.addEventListener("click",this.handleTapEvent)}var o=!!navigator.userAgent.match(/safari/i)&&!navigator.userAgent.match(/chrome/i)&&typeof document.hidden!=="undefined"&&!window.chrome;if("ontouchstart" in window==true&&o){document.addEventListener("touchmove",function(){history.popstateswipe=true});document.addEventListener("touchend",function(){history.popstateswipe=false})}a=true};b.handleTapEvent=function(A){var B=null;if(A&&A.nodeType==1){B=A;B.preventDefault=function(){}}B=B||A.target||A.touches[0],href=B.href;if((!href||/a/i.test(B.tagName)==false)&&(B=B.getParentElementByTag("a"))){href=B.href}var m=document.querySelector(".in."+b.classPage);if(m==null||!B){return}var p={target:B};var D=B.getAttribute("data-preventdefault")||d(B.getAttribute("data-params")||"").preventdefault;var s=b.getFunction(D);if(typeof s=="function"&&s(B)==true){A.preventDefault();return false}var z=B.getElementsByClassName(b.classMask)[0];if(z&&z.style.display!="none"){A.preventDefault();return false}var y=B.getAttribute("data-container"),k=B.getAttribute("data-classpage"),t=y&&document.getElementById(y);if(t&&k&&k!=b.classPage){m=t.querySelector(".in."+k)||t.querySelector(k);p.history=false;p.title=false;p.classPage=k}var x=(b.captureLink==true);var o=B.getAttribute("data-rel");var w=false;if(o=="back"){w=true}var q=(o=="external");if(!href){return}href=href.replace("#&","#");if(B.getAttribute("href").replace(/#/g,"")===""){A.preventDefault();return}if(/^javascript/.test(href)){if(w==false){return}}else{q=q||(href.replace("://","").split("/")[0]!==location.href.replace("://","").split("/")[0]);if((q==true||x==false)&&B.getAttribute("data-ajax")!="true"){return}}if(/^#/.test(B.getAttribute("href"))==true){var l=href.split("#")[1],n=l&&document.getElementById(l);if(w==false&&o=="auto"){w=b.isBack(n,m)}if(n){b.transition(n,m,w,p)}A.preventDefault()}else{if(/^javascript/.test(href)){history.tempBack=true;history.back()}else{if(B.getAttribute("data-ajax")!="false"){var v=b.getCleanUrl(B);var C=B.getAttribute("data-reload"),u=B.getAttribute("href");if((C==null||C=="false")&&i[v]){if(w==false&&o=="auto"){w=b.isBack(i[v],m)}p.id=v;var r=t||document.body;if(r.contains(i[v])==false){r.appendChild(i[v])}b.transition(i[v],m,w,p)}else{b.ajax(B)}A.preventDefault()}}}};Element.prototype.getParentElementByTag=function(k){if(!k){return null}var m=null,n=this;var l=function(){n=n.parentElement;if(!n){return null}var o=n.tagName.toLowerCase();if(o===k){m=n}else{if(o=="body"){m=null}else{l()}}};l();return m};var d=function(k){var l={};if(typeof k=="string"){k.split("&").forEach(function(m){var n=m.split("=");if(n.length>1){l[n[0]]=m.replace(n[0]+"=","")}})}return l};window.addEventListener("DOMContentLoaded",function(){if(a==false){b.init()}});window.addEventListener("popstate",function(){if(history.popstateswipe==true){location.reload();history.popstateswipe=false;return}if(history.popstate==false){history.popstate=true;return}var n=location.hash.replace("#&","").replace(/^#/,""),l=null,k=null;if(n==""){l=document.querySelector("."+b.classPage);if(l.id){return}}else{l=i[n];if(n.split("container=").length==2){k=document.getElementById(n.split("container=")[1].split("&")[0])}if(l&&f.test(n)==false){b.transition(l,((k||document).querySelector(".in."+b.classPage)),true,{id:n,history:false,container:k});return}}if(!l){if(f.test(n)==false){b.ajax({url:n,dataType:"unknown",back:b.isBack(),container:k});return}l=document.querySelector("#"+n)}var m=document.querySelector(".in."+b.classPage);if((l&&l==m)||b.pushStateEnabled==false){return}if(l){b.transition(l,m,b.isBack(l,m),{id:n,history:false,remove:false})}});document.MBLOADED=true;return b});
|