From 1e760c256d41211bc49ead502c87ac8951d1791f Mon Sep 17 00:00:00 2001 From: Sean DeNigris Date: Fri, 25 Jul 2014 14:43:53 -0400 Subject: [PATCH] =?UTF-8?q?Fixes=20Issue=20#39.=20A=20bit=20simpler=20than?= =?UTF-8?q?=20sforster=E2=80=99s=20proposal=20in=20df68106df68106,=20but?= =?UTF-8?q?=20missing=20tests=20because=20could=20not=20get=20the=20line?= =?UTF-8?q?=20endings=20right=20on=20that=20file,=20so=20should=20use=20hi?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- path.js | 12 +++++++----- path.min.js | 8 +++++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/path.js b/path.js index d56a2d8..d6488d2 100644 --- a/path.js +++ b/path.js @@ -53,7 +53,7 @@ var Path = { } }, 'match': function (path, parameterize) { - var params = {}, route = null, possible_routes, slice, i, j, compare; + var params = {}, route = null, possible_routes, slice, i, j, compare, compare_parts; for (route in Path.routes.defined) { if (route !== null && route !== undefined) { route = Path.routes.defined[route]; @@ -63,9 +63,11 @@ var Path = { compare = path; if (slice.search(/:/) > 0) { for (i = 0; i < slice.split("/").length; i++) { - if ((i < compare.split("/").length) && (slice.split("/")[i].charAt(0) === ":")) { - params[slice.split('/')[i].replace(/:/, '')] = compare.split("/")[i]; - compare = compare.replace(compare.split("/")[i], slice.split("/")[i]); + compare_parts = compare.split("/"); + if ((i < compare_parts.length) && (slice.split("/")[i].charAt(0) === ":")) { + params[slice.split('/')[i].replace(/:/, '')] = compare_parts[i]; + compare_parts[i] = slice.split("/")[i]; + compare = compare_parts.join("/"); } } } @@ -189,4 +191,4 @@ Path.core.route.prototype = { Path.routes.defined[this.path].action(); } } -}; \ No newline at end of file +}; diff --git a/path.min.js b/path.min.js index f44e647..ffe2609 100644 --- a/path.min.js +++ b/path.min.js @@ -1 +1,7 @@ -var Path={version:"0.8.4",map:function(a){if(Path.routes.defined.hasOwnProperty(a)){return Path.routes.defined[a]}else{return new Path.core.route(a)}},root:function(a){Path.routes.root=a},rescue:function(a){Path.routes.rescue=a},history:{initial:{},pushState:function(a,b,c){if(Path.history.supported){if(Path.dispatch(c)){history.pushState(a,b,c)}}else{if(Path.history.fallback){window.location.hash="#"+c}}},popState:function(a){var b=!Path.history.initial.popped&&location.href==Path.history.initial.URL;Path.history.initial.popped=true;if(b)return;Path.dispatch(document.location.pathname)},listen:function(a){Path.history.supported=!!(window.history&&window.history.pushState);Path.history.fallback=a;if(Path.history.supported){Path.history.initial.popped="state"in window.history,Path.history.initial.URL=location.href;window.onpopstate=Path.history.popState}else{if(Path.history.fallback){for(route in Path.routes.defined){if(route.charAt(0)!="#"){Path.routes.defined["#"+route]=Path.routes.defined[route];Path.routes.defined["#"+route].path="#"+route}}Path.listen()}}}},match:function(a,b){var c={},d=null,e,f,g,h,i;for(d in Path.routes.defined){if(d!==null&&d!==undefined){d=Path.routes.defined[d];e=d.partition();for(h=0;h0){for(g=0;g=8)){window.onhashchange=a}else{setInterval(a,50)}if(location.hash!==""){Path.dispatch(location.hash)}},core:{route:function(a){this.path=a;this.action=null;this.do_enter=[];this.do_exit=null;this.params={};Path.routes.defined[a]=this}},routes:{current:null,root:null,rescue:null,previous:null,defined:{}}};Path.core.route.prototype={to:function(a){this.action=a;return this},enter:function(a){if(a instanceof Array){this.do_enter=this.do_enter.concat(a)}else{this.do_enter.push(a)}return this},exit:function(a){this.do_exit=a;return this},partition:function(){var a=[],b=[],c=/\(([^}]+?)\)/g,d,e;while(d=c.exec(this.path)){a.push(d[1])}b.push(this.path.split("(")[0]);for(e=0;e0){for(b=0;b