From 846f57051eb451e2aa0d5d5b43b12266f3305d59 Mon Sep 17 00:00:00 2001 From: Olivier Vaillancourt Date: Wed, 4 Jul 2012 21:39:03 -0400 Subject: [PATCH 1/3] - Fixed route matching not working for paths containing query strings. - Added tests for route matching + param extraction for paths containing query strings. --- build/page.js | 6 +++-- build/page.min.js | 2 +- lib/page.js | 6 +++-- test/tests.js | 58 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 67 insertions(+), 5 deletions(-) diff --git a/build/page.js b/build/page.js index 858cb7a4..c9c501a3 100755 --- a/build/page.js +++ b/build/page.js @@ -264,8 +264,10 @@ Route.prototype.match = function(path, params){ var keys = this.keys - , m = this.regexp.exec(path); - + , qsIndex = path.indexOf('?') + , pathname = ~qsIndex ? path.slice(0, qsIndex) : path + , m = this.regexp.exec(pathname); + if (!m) return false; for (var i = 1, len = m.length; i < len; ++i) { diff --git a/build/page.min.js b/build/page.min.js index ba6307d7..1329637a 100644 --- a/build/page.min.js +++ b/build/page.min.js @@ -1 +1 @@ -(function(){var dispatch=!0,base="",running;function page(path,fn){if("function"==typeof fn){var route=new Route(path);for(var i=1;i Date: Wed, 4 Jul 2012 21:56:23 -0400 Subject: [PATCH 2/3] Adding query string support for the initial url when dispatch is set to true --- build/page.js | 2 +- build/page.min.js | 2 +- lib/page.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build/page.js b/build/page.js index c9c501a3..faf66d4f 100755 --- a/build/page.js +++ b/build/page.js @@ -88,7 +88,7 @@ if (false !== options.popstate) addEventListener('popstate', onpopstate, false); if (false !== options.click) addEventListener('click', onclick, false); if (!dispatch) return; - page.replace(location.pathname, null, true, dispatch); + page.replace(location.pathname + location.search, null, true, dispatch); }; /** diff --git a/build/page.min.js b/build/page.min.js index 1329637a..ce36b4db 100644 --- a/build/page.min.js +++ b/build/page.min.js @@ -1 +1 @@ -(function(){var dispatch=!0,base="",running;function page(path,fn){if("function"==typeof fn){var route=new Route(path);for(var i=1;i Date: Wed, 4 Jul 2012 23:03:35 -0400 Subject: [PATCH 3/3] Adding query string support for link clicking events. --- build/page.js | 2 +- build/page.min.js | 2 +- lib/page.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build/page.js b/build/page.js index faf66d4f..e90d71e9 100755 --- a/build/page.js +++ b/build/page.js @@ -350,7 +350,7 @@ while (el && 'A' != el.nodeName) el = el.parentNode; if (!el || 'A' != el.nodeName) return; var href = el.href; - var path = el.pathname; + var path = el.pathname + el.search; if (el.hash) return; if (!sameOrigin(href)) return; var orig = path; diff --git a/build/page.min.js b/build/page.min.js index ce36b4db..3f39c8f2 100644 --- a/build/page.min.js +++ b/build/page.min.js @@ -1 +1 @@ -(function(){var dispatch=!0,base="",running;function page(path,fn){if("function"==typeof fn){var route=new Route(path);for(var i=1;i