twister HTML + Javascript User Interface
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

10 lines
6.7 KiB

11 years ago
/*!
* jQueryMobile-router v20130527
* http://github.com/azicchetti/jquerymobile-router
*
* Copyright 2011-2013 (c) Andrea Zicchetti
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://github.com/azicchetti/jquerymobile-router/blob/master/MIT-LICENSE.txt
* http://github.com/azicchetti/jquerymobile-router/blob/master/GPL-LICENSE.txt
*/
(function(a,b){if(typeof define==="function"&&define.amd){define(["jquery"],b)}else{b(jQuery)}}(this,function(a){a(document).on("mobileinit",function(){var c=a.extend({fixFirstPageDataUrl:false,firstPageDataUrl:"index.html",ajaxApp:false,firstMatchOnly:false,defaultArgsRe:false},a.mobile.jqmRouter||{});var d=null,e=null,b=false;a(document).on("pagebeforechange",function(j,i){if(i.options.hasOwnProperty("_jqmrouter_handled")){return}var h;if(typeof i.toPage==="string"){h=i.toPage}else{h=i.toPage.jqmData("url")||"";if(i.toPage.attr("id")==h){h="#"+h}}i.options._jqmrouter_handled=true;if(i.options.data&&(i.options.type+"").toLowerCase()=="get"){h+="?"+i.options.data}var g=a.mobile.path.parseUrl(h);d=e;e=g;if(g.hash.indexOf("?")!=-1){i.options.dataUrl=g.hash.replace(/^#/,"")}var f=/^#|\?.*$/g;if(d&&g.hash!=d.hash&&g.hash.replace(f,"")==d.hash.replace(f,"")){i.options.allowSamePageTransition=true&&!b}b=false;if(window.location.hash.indexOf("&ui-state=dialog")!=-1){b=true}});if(c.fixFirstPageDataUrl){a(document).ready(function(){if(!window.location.pathname.match("/$")){return}var g=a(":jqmData(role='page')").first();var h=g.jqmData("url"),f=window.location.pathname+c.firstPageDataUrl+window.location.search+window.location.hash;if(h!=f){g.attr("data-url",f).jqmData("url",f)}})}a.mobile.Router=function(j,g,h){this.routes={pagebeforecreate:null,pagecreate:null,pagebeforeshow:null,pageshow:null,pagebeforehide:null,pagehide:null,pageinit:null,pageremove:null,pagebeforechange:null,pagebeforeload:null,pageload:null,popupbeforeposition:null,popupafteropen:null,popupafterclose:null};this.evtLookup={bC:"pagebeforechange",bl:"pagebeforeload",l:"pageload",bc:"pagebeforecreate",c:"pagecreate",bs:"pagebeforeshow",s:"pageshow",bh:"pagebeforehide",h:"pagehide",i:"pageinit",rm:"pageremove",pbp:"popupbeforeposition",pao:"popupafteropen",pac:"popupafterclose"};this.routesRex={};this.conf=a.extend({},c,h||{});this.defaultHandlerEvents={};if(this.conf.defaultHandlerEvents){var f=this.conf.defaultHandlerEvents.split(",");for(var k=0;k<f.length;k++){this.defaultHandlerEvents[this.evtLookup[f[k]]]=f[k]}}this.add(j,g)};a.extend(a.mobile.Router.prototype,{documentEvts:{pagebeforechange:1,pagebeforeload:1,pageload:1},debug:function(g){var f=this.conf;if(f.debugHandler){f.debugHandler.apply(this,arguments)}else{if(f.debugHandler!==false&&typeof(console)!="undefined"&&console.log){console.log.apply(console,arguments);if(g.stack){console.log(g.stack)}}}},add:function(i,h,k){if(!i){return}var f=this,g=[],l=[];if(i instanceof Array){a.each(i,a.proxy(function(n,m){this.add(m,h,true)},this))}else{a.each(i,function(q,o){if(typeof(o)=="string"||typeof(o)=="function"){if(f.routes.pagebeforeshow===null){f.routes.pagebeforeshow={}}if(f.conf.defaultArgsRe){q+="(?:[?](.*))?$"}f.routes.pagebeforeshow[q]={handler:o,events:"bs"};if(!f.routesRex.hasOwnProperty(q)){f.routesRex[q]=new RegExp(q)}}else{var n,p=o.events.split(","),m;if(o.argsre!==false&&(o.argsre||f.conf.defaultArgsRe)){q+="(?:[?](.*))?$"}for(n=0;n<p.length;n++){m=f.evtLookup[p[n]];if(f.routes.hasOwnProperty(m)){if(f.routes[m]===null){f.routes[m]={}}f.routes[m][q]=o;if(!f.routesRex.hasOwnProperty(q)){f.routesRex[q]=new RegExp(q)}}else{f.debug("can't set unsupported route "+p[n])}}}})}if(k===true){return}if(!this.userHandlers){this.userHandlers=h||{}}else{a.extend(this.userHandlers,h||{})}a.each(f.routes,function(m,n){if(n!==null){if(!f.documentEvts[m]){g.push(m)}else{l.push(m)}}});this._detachEvents();var j=function(n,m){f._processRoutes(n,m,this)};if(g.length>0){this._eventData={events:g.join(" "),selectors:":jqmData(role='page'),:jqmData(role='dialog')",handler:j};a(document).on(this._eventData.events,this._eventData.selectors,this._eventData.handler)}if(l.length>0){this._docEventData={events:l.join(" "),handler:j};a(document).on(this._docEventData.events,this._docEventData.handler)}},_processRoutes:function(k,o,l){var m=this,n,h,g=0,f=null;if(k.type=="pagebeforechange"){if(o.options._jqmrouter_bC){return}f={isString:typeof o.toPage==="string",deferred:a.Deferred(),toPage:o.toPage};l=!f.isString?o.toPage: