diff --git a/dist/lightrouter.js b/dist/lightrouter.js index b3217d2..90defc1 100644 --- a/dist/lightrouter.js +++ b/dist/lightrouter.js @@ -180,7 +180,7 @@ run: function() { var url = this.getUrl(), route; - for (var i in this.routes) + for (var i = 0, len = this.routes.length; i < len; i++) { // Get the route route = this.routes[i]; @@ -236,11 +236,14 @@ t = 1; params = route.match(this.router.namedParam.match); } - - for (i in params) + + if (params) { - name = t ? params[i].replace(this.router.namedParam.match, '$1') : i; - obj[name] = values[i]; + for (var i = 0, len = params.length; i < len; i++) + { + name = t ? params[i].replace(this.router.namedParam.match, '$1') : i; + obj[name] = values[i]; + } } return obj; diff --git a/dist/lightrouter.min.js b/dist/lightrouter.min.js index 4006476..e634e02 100644 --- a/dist/lightrouter.min.js +++ b/dist/lightrouter.min.js @@ -1 +1 @@ -/* lightrouter.js - Copyright 2014 Gary Green. Licensed under the Apache License, Version 2.0 */!function(t){"undefined"!=typeof exports?module.exports=t():window.LightRouter=t(window)}(function(t){function e(t){this.pathRoot="",this.routes=[],this.type="path",this.path=null,this.hash=null;var e="([\\w-]+)";if(this.namedParam={match:new RegExp("{("+e+")}","g"),replace:e},t=t||{},t.type&&this.setType(t.type),t.path&&this.setPath(t.path),t.pathRoot&&this.setPathRoot(t.pathRoot),t.hash&&this.setHash(t.hash),t.routes){var s;for(s in t.routes)this.add(s,t.routes[s])}}function s(t,e){this.options=t,this.router=e,this.values=[]}return e.prototype={add:function(t,e){return this.routes.push(new s({route:t,callback:e},this)),this},empty:function(){return this.routes=[],this},setType:function(t){return this.type=t,this},setPathRoot:function(t){return this.pathRoot=t,this},setPath:function(t){return this.path=t,this},setHash:function(t){return this.hash=t,this},getUrl:function(e){var s;if(e=e||this.type,"path"==e){var r=new RegExp("^"+this.pathRoot+"/?");s=this.path||t.location.pathname.substring(1),s=s.replace(r,"")}else"hash"==e&&(s=this.hash||t.location.hash.substring(1));return decodeURI(s)},run:function(){var t,e=this.getUrl();for(var s in this.routes)t=this.routes[s],t.test(e)&&t.run();return this}},s.prototype={regex:function(){var t=this.options.route;return"string"==typeof t?new RegExp("^"+t.replace(/\//g,"\\/").replace(this.router.namedParam.match,this.router.namedParam.replace)+"$"):t},params:function(){var t,e,s={},r=this.values,h=r,i=0,a=this.options.route;"string"==typeof a&&(i=1,h=a.match(this.router.namedParam.match));for(e in h)t=i?h[e].replace(this.router.namedParam.match,"$1"):e,s[t]=r[e];return s},test:function(t){var e;return(e=t.match(this.regex()))?(this.values=e.slice(1),!0):!1},run:function(){return this.options.callback.apply(void 0,[this.params()])}},e}); \ No newline at end of file +/* lightrouter.js - Copyright 2014 Gary Green. Licensed under the Apache License, Version 2.0 */!function(t){"undefined"!=typeof exports?module.exports=t():window.LightRouter=t(window)}(function(t){function e(t){this.pathRoot="",this.routes=[],this.type="path",this.path=null,this.hash=null;var e="([\\w-]+)";if(this.namedParam={match:new RegExp("{("+e+")}","g"),replace:e},t=t||{},t.type&&this.setType(t.type),t.path&&this.setPath(t.path),t.pathRoot&&this.setPathRoot(t.pathRoot),t.hash&&this.setHash(t.hash),t.routes){var s;for(s in t.routes)this.add(s,t.routes[s])}}function s(t,e){this.options=t,this.router=e,this.values=[]}return e.prototype={add:function(t,e){return this.routes.push(new s({route:t,callback:e},this)),this},empty:function(){return this.routes=[],this},setType:function(t){return this.type=t,this},setPathRoot:function(t){return this.pathRoot=t,this},setPath:function(t){return this.path=t,this},setHash:function(t){return this.hash=t,this},getUrl:function(e){var s;if(e=e||this.type,"path"==e){var h=new RegExp("^"+this.pathRoot+"/?");s=this.path||t.location.pathname.substring(1),s=s.replace(h,"")}else"hash"==e&&(s=this.hash||t.location.hash.substring(1));return decodeURI(s)},run:function(){for(var t,e=this.getUrl(),s=0,h=this.routes.length;h>s;s++)t=this.routes[s],t.test(e)&&t.run();return this}},s.prototype={regex:function(){var t=this.options.route;return"string"==typeof t?new RegExp("^"+t.replace(/\//g,"\\/").replace(this.router.namedParam.match,this.router.namedParam.replace)+"$"):t},params:function(){var t,e,s={},h=this.values,r=h,i=0,a=this.options.route;if("string"==typeof a&&(i=1,r=a.match(this.router.namedParam.match)),r)for(var e=0,n=r.length;n>e;e++)t=i?r[e].replace(this.router.namedParam.match,"$1"):e,s[t]=h[e];return s},test:function(t){var e;return(e=t.match(this.regex()))?(this.values=e.slice(1),!0):!1},run:function(){return this.options.callback.apply(void 0,[this.params()])}},e}); \ No newline at end of file diff --git a/src/lightrouter.js b/src/lightrouter.js index b3217d2..90defc1 100644 --- a/src/lightrouter.js +++ b/src/lightrouter.js @@ -180,7 +180,7 @@ run: function() { var url = this.getUrl(), route; - for (var i in this.routes) + for (var i = 0, len = this.routes.length; i < len; i++) { // Get the route route = this.routes[i]; @@ -236,11 +236,14 @@ t = 1; params = route.match(this.router.namedParam.match); } - - for (i in params) + + if (params) { - name = t ? params[i].replace(this.router.namedParam.match, '$1') : i; - obj[name] = values[i]; + for (var i = 0, len = params.length; i < len; i++) + { + name = t ? params[i].replace(this.router.namedParam.match, '$1') : i; + obj[name] = values[i]; + } } return obj;