Browse files

Calls to the .live() method (now deprecated) were replaced by

their .delegate() equivalent in order to support jquery 1.7
  • Loading branch information...
1 parent 51c05f1 commit cb8442f4c4f4b5a8e7631bb21b2e709a4b298f4d @azicchetti committed Feb 23, 2012
Showing with 10 additions and 7 deletions.
  1. +9 −6 js/jquery.mobile.router.js
  2. +1 −1 js/jquery.mobile.router.min.js
View
15 js/jquery.mobile.router.js
@@ -171,12 +171,14 @@ $(document).bind("mobileinit",function(){
}
this._detachEvents();
if (evtList.length>0){
- this._liveData={
+ this._eventData={
events: evtList.join(" "),
+ selectors: ":jqmData(role='page'),:jqmData(role='dialog')",
handler: function(e,ui){ _self._processRoutes(e,ui,this); }
};
- $(":jqmData(role='page'),:jqmData(role='dialog')").live(
- this._liveData.events, this._liveData.handler
+ $(document).delegate(
+ this._eventData.selectors,
+ this._eventData.events, this._eventData.handler
);
}
}
@@ -244,9 +246,10 @@ $(document).bind("mobileinit",function(){
},
_detachEvents: function(){
- if (this._liveData){
- $(":jqmData(role='page'),:jqmData(role='dialog')").die(
- this._liveData.events, this._liveData.handler
+ if (this._eventData){
+ $(document).undelegate(
+ this._eventData.selectors,
+ this._eventData.events, this._eventData.handler
);
}
} ,
View
2 js/jquery.mobile.router.min.js
@@ -7,4 +7,4 @@
* http://github.com/azicchetti/jquerymobile-router/blob/master/MIT-LICENSE.txt
* http://github.com/azicchetti/jquerymobile-router/blob/master/GPL-LICENSE.txt
*/
-(function(a){a(document).bind("mobileinit",function(){var d=a.extend({fixFirstPageDataUrl:false,firstPageDataUrl:"index.html",ajaxApp:false},a.mobile.jqmRouter||{});var c=true;function b(g){if(c){console.log(g)}}var e=null,f=null;a(document).bind("pagebeforechange",function(k,j){var h=(typeof j.toPage==="string")?j.toPage:j.toPage.jqmData("url")||"";if(j.options.hasOwnProperty("_jqmrouter_handled")){return}j.options._jqmrouter_handled=true;var g=a.mobile.path.parseUrl(h);e=f;f=g;if(g.hash.indexOf("?")!==-1){var i=g.hash.replace(/\?.*$/,"");j.options.dataUrl=g.href;if(a.mobile.activePage&&i.replace(/^#/,"")==a.mobile.activePage.jqmData("url")){j.options.allowSamePageTransition=true;a.mobile.changePage(a(i),j.options)}else{a.mobile.changePage(a(i),j.options)}k.preventDefault()}});if(d.fixFirstPageDataUrl){a(document).ready(function(){if(!window.location.pathname.match("/$")){return}var h=a(":jqmData(role='page')").first();var i=h.jqmData("url"),g=window.location.pathname+d.firstPageDataUrl+window.location.search+window.location.hash;if(i!=g){h.attr("data-url",g).jqmData("url",g)}})}a.mobile.Router=function(k,h,j){this.routes={pagebeforecreate:null,pagecreate:null,pagebeforeshow:null,pageshow:null,pagebeforehide:null,pagehide:null,pageinit:null,pageremove:null};this.evtLookup={bc:"pagebeforecreate",c:"pagecreate",bs:"pagebeforeshow",s:"pageshow",bh:"pagebeforehide",h:"pagehide",i:"pageinit",rm:"pageremove"};this.routesRex={};this.conf=a.extend({},d,j||{});this.defaultHandlerEvents={};if(this.conf.defaultHandlerEvents){var g=this.conf.defaultHandlerEvents.split(",");for(var l=0;l<g.length;l++){this.defaultHandlerEvents[this.evtLookup[g[l]]]=g[l]}}this.add(k,h)};a.extend(a.mobile.Router.prototype,{add:function(j,i){if(!j){return}var g=this,h=[];if(j instanceof Array){a.each(j,a.proxy(function(m,l){this.add(l,i)},this))}else{a.each(j,function(o,m){if(typeof(m)=="string"||typeof(m)=="function"){if(g.routes.pagebeforeshow===null){g.routes.pagebeforeshow={}}g.routes.pagebeforeshow[o]=m;if(!g.routesRex.hasOwnProperty(o)){g.routesRex[o]=new RegExp(o)}}else{var l,n=m.events.split(","),k;for(l=0;l<n.length;l++){k=g.evtLookup[n[l]];if(g.routes.hasOwnProperty(k)){if(g.routes[k]===null){g.routes[k]={}}g.routes[k][o]=m.handler;if(!g.routesRex.hasOwnProperty(o)){g.routesRex[o]=new RegExp(o)}}else{b("can't set unsupported route "+n[l])}}}});a.each(g.routes,function(k,l){if(l!==null){h.push(k)}});if(!this.userHandlers){this.userHandlers=i||{}}else{a.extend(this.userHandlers,i||{})}this._detachEvents();if(h.length>0){this._liveData={events:h.join(" "),handler:function(l,k){g._processRoutes(l,k,this)}};a(":jqmData(role='page'),:jqmData(role='dialog')").live(this._liveData.events,this._liveData.handler)}}},_processRoutes:function(l,p,m){var n=this,o,h,k,g=0;if(l.type in {pagebeforehide:true,pagehide:true,pageremove:true}){o=e}else{o=f}do{if(!o){if(m){k=a(m);o=k.jqmData("url");if(o){if(k.attr("id")==o){o="#"+o}o=a.mobile.path.parseUrl(o)}}}else{if(m&&!a(m).jqmData("url")){return}}if(!o){return}h=(!this.conf.ajaxApp?o.hash:o.pathname+o.search+o.hash);if(h.length==0){o=""}g++}while(h.length==0&&g<=1);var j=false;a.each(this.routes[l.type],function(q,s){var r,u;if((r=h.match(n.routesRex[q]))){if(typeof(s)=="function"){u=s}else{if(typeof(n.userHandlers[s])=="function"){u=n.userHandlers[s]}}if(u){try{u.apply(n.userHandlers,[l.type,r,p,m,l]);j=true}catch(t){b(t)}}}});if(!j&&this.conf.defaultHandler&&this.defaultHandlerEvents[l.type]){if(typeof(this.conf.defaultHandler)=="function"){try{this.conf.defaultHandler.apply(n.userHandlers,[l.type,p,m,l])}catch(i){b(i)}}}},_detachEvents:function(){if(this._liveData){a(":jqmData(role='page'),:jqmData(role='dialog')").die(this._liveData.events,this._liveData.handler)}},destroy:function(){this._detachEvents();this.routes=this.routesRex=null},getParams:function(g){if(!g){return null}var j={},h;var i=g.slice(g.indexOf("?")+1).split("&");a.each(i,function(m,l){h=l.split("=");if(j[h[0]]){if(!(j[h[0]] instanceof Array)){j[h[0]]=[j[h[0]]]}j[h[0]].push(h[1])}else{j[h[0]]=h[1]}});if(a.isEmptyObject(j)){return null}return j}})})})(jQuery);
+(function(a){a(document).bind("mobileinit",function(){var d=a.extend({fixFirstPageDataUrl:false,firstPageDataUrl:"index.html",ajaxApp:false},a.mobile.jqmRouter||{});var c=true;function b(g){if(c){console.log(g)}}var e=null,f=null;a(document).bind("pagebeforechange",function(k,j){var h=(typeof j.toPage==="string")?j.toPage:j.toPage.jqmData("url")||"";if(j.options.hasOwnProperty("_jqmrouter_handled")){return}j.options._jqmrouter_handled=true;var g=a.mobile.path.parseUrl(h);e=f;f=g;if(g.hash.indexOf("?")!==-1){var i=g.hash.replace(/\?.*$/,"");j.options.dataUrl=g.href;if(a.mobile.activePage&&i.replace(/^#/,"")==a.mobile.activePage.jqmData("url")){j.options.allowSamePageTransition=true;a.mobile.changePage(a(i),j.options)}else{a.mobile.changePage(a(i),j.options)}k.preventDefault()}});if(d.fixFirstPageDataUrl){a(document).ready(function(){if(!window.location.pathname.match("/$")){return}var h=a(":jqmData(role='page')").first();var i=h.jqmData("url"),g=window.location.pathname+d.firstPageDataUrl+window.location.search+window.location.hash;if(i!=g){h.attr("data-url",g).jqmData("url",g)}})}a.mobile.Router=function(k,h,j){this.routes={pagebeforecreate:null,pagecreate:null,pagebeforeshow:null,pageshow:null,pagebeforehide:null,pagehide:null,pageinit:null,pageremove:null};this.evtLookup={bc:"pagebeforecreate",c:"pagecreate",bs:"pagebeforeshow",s:"pageshow",bh:"pagebeforehide",h:"pagehide",i:"pageinit",rm:"pageremove"};this.routesRex={};this.conf=a.extend({},d,j||{});this.defaultHandlerEvents={};if(this.conf.defaultHandlerEvents){var g=this.conf.defaultHandlerEvents.split(",");for(var l=0;l<g.length;l++){this.defaultHandlerEvents[this.evtLookup[g[l]]]=g[l]}}this.add(k,h)};a.extend(a.mobile.Router.prototype,{add:function(j,i){if(!j){return}var g=this,h=[];if(j instanceof Array){a.each(j,a.proxy(function(m,l){this.add(l,i)},this))}else{a.each(j,function(o,m){if(typeof(m)=="string"||typeof(m)=="function"){if(g.routes.pagebeforeshow===null){g.routes.pagebeforeshow={}}g.routes.pagebeforeshow[o]=m;if(!g.routesRex.hasOwnProperty(o)){g.routesRex[o]=new RegExp(o)}}else{var l,n=m.events.split(","),k;for(l=0;l<n.length;l++){k=g.evtLookup[n[l]];if(g.routes.hasOwnProperty(k)){if(g.routes[k]===null){g.routes[k]={}}g.routes[k][o]=m.handler;if(!g.routesRex.hasOwnProperty(o)){g.routesRex[o]=new RegExp(o)}}else{b("can't set unsupported route "+n[l])}}}});a.each(g.routes,function(k,l){if(l!==null){h.push(k)}});if(!this.userHandlers){this.userHandlers=i||{}}else{a.extend(this.userHandlers,i||{})}this._detachEvents();if(h.length>0){this._eventData={events:h.join(" "),selectors:":jqmData(role='page'),:jqmData(role='dialog')",handler:function(l,k){g._processRoutes(l,k,this)}};a(document).delegate(this._eventData.selectors,this._eventData.events,this._eventData.handler)}}},_processRoutes:function(l,p,m){var n=this,o,h,k,g=0;if(l.type in {pagebeforehide:true,pagehide:true,pageremove:true}){o=e}else{o=f}do{if(!o){if(m){k=a(m);o=k.jqmData("url");if(o){if(k.attr("id")==o){o="#"+o}o=a.mobile.path.parseUrl(o)}}}else{if(m&&!a(m).jqmData("url")){return}}if(!o){return}h=(!this.conf.ajaxApp?o.hash:o.pathname+o.search+o.hash);if(h.length==0){o=""}g++}while(h.length==0&&g<=1);var j=false;a.each(this.routes[l.type],function(q,s){var r,u;if((r=h.match(n.routesRex[q]))){if(typeof(s)=="function"){u=s}else{if(typeof(n.userHandlers[s])=="function"){u=n.userHandlers[s]}}if(u){try{u.apply(n.userHandlers,[l.type,r,p,m,l]);j=true}catch(t){b(t)}}}});if(!j&&this.conf.defaultHandler&&this.defaultHandlerEvents[l.type]){if(typeof(this.conf.defaultHandler)=="function"){try{this.conf.defaultHandler.apply(n.userHandlers,[l.type,p,m,l])}catch(i){b(i)}}}},_detachEvents:function(){if(this._eventData){a(document).undelegate(this._eventData.selectors,this._eventData.events,this._eventData.handler)}},destroy:function(){this._detachEvents();this.routes=this.routesRex=null},getParams:function(g){if(!g){return null}var j={},h;var i=g.slice(g.indexOf("?")+1).split("&");a.each(i,function(m,l){h=l.split("=");if(j[h[0]]){if(!(j[h[0]] instanceof Array)){j[h[0]]=[j[h[0]]]}j[h[0]].push(h[1])}else{j[h[0]]=h[1]}});if(a.isEmptyObject(j)){return null}return j}})})})(jQuery);

0 comments on commit cb8442f

Please sign in to comment.