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/angular-mocks.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'src/angular-mocks.js') diff --git a/src/angular-mocks.js b/src/angular-mocks.js index 066ccea5..8410dc8c 100644 --- a/src/angular-mocks.js +++ b/src/angular-mocks.js @@ -89,19 +89,19 @@ function MockBrowser() { requests = []; this.isMock = true; - self.url = "http://server"; - self.lastUrl = self.url; // used by url polling fn + self.$$url = "http://server"; + self.$$lastUrl = self.$$url; // used by url polling fn self.pollFns = []; // register url polling fn - self.onHashChange = function(listener) { + self.onUrlChange = function(listener) { self.pollFns.push( function() { - if (self.lastUrl != self.url) { - self.lastUrl = self.url; - listener(); + if (self.$$lastUrl != self.$$url) { + self.$$lastUrl = self.$$url; + listener(self.$$url); } } ); @@ -326,12 +326,13 @@ MockBrowser.prototype = { hover: function(onHover) { }, - getUrl: function(){ - return this.url; - }, + url: function(url, replace) { + if (url) { + this.$$url = url; + return this; + } - setUrl: function(url){ - this.url = url; + return this.$$url; }, cookies: function(name, value) { -- cgit v1.2.3