From 988ed451b508b9d7ea4690b150993ec62d8a3743 Mon Sep 17 00:00:00 2001 From: Vojta Jina Date: Wed, 22 Jun 2011 19:57:22 +0200 Subject: feat($browser): jQuery style url method, onUrlChange event This is just basic implementation of $browser.url, $browser.onUrlChange methods: $browser.url() - returns current location.href $browser.url('/new') - set url to /new If supported, history.pushState is used, location.href property otherwise. $browser.url('/new', true) - replace current url with /new If supported, history.replaceState is used, location.replace otherwise. $browser.onUrlChange is only fired when url is changed from the browser: - user types into address bar - user clicks on back/forward button - user clicks on link It's not fired when url is changed using $browser.url() Breaks Removed $browser.setUrl(), $browser.getUrl(), use $browser.url() Breaks Removed $browser.onHashChange(), use $browser.onUrlChange() --- src/service/location.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/service') diff --git a/src/service/location.js b/src/service/location.js index 6e646b8b..2f53f520 100644 --- a/src/service/location.js +++ b/src/service/location.js @@ -72,8 +72,8 @@ angularServiceInject("$location", function($browser) { var location = {update: update, updateHash: updateHash}; var lastLocation = {}; // last state since last update(). - $browser.onHashChange(bind(this, this.$apply, function() { //register - update($browser.getUrl()); + $browser.onUrlChange(bind(this, this.$apply, function() { //register + update($browser.url()); }))(); //initialize this.$watch(sync); @@ -120,7 +120,7 @@ angularServiceInject("$location", function($browser) { location.href = composeHref(location); } - $browser.setUrl(location.href); + $browser.url(location.href); copy(location, lastLocation); } -- cgit v1.2.3