aboutsummaryrefslogtreecommitdiffstats
path: root/src/Browser.js
diff options
context:
space:
mode:
authorIgor Minar2011-05-27 20:49:57 -0700
committerIgor Minar2011-07-18 14:14:19 -0700
commit120701b9d9ebdd9352c7fca2b8a381597a808362 (patch)
tree506e5a9d760031c21dbe3258bbca4c04b6b7f780 /src/Browser.js
parentfe5240732d0a80b8717be77b31d51dc3c4d737fd (diff)
downloadangular.js-120701b9d9ebdd9352c7fca2b8a381597a808362.tar.bz2
fix($browser.setUrl): make browser.setUrl more efficient
- browser should remember the last value retrieved via browser.getUrl - browser should update window.location only if the new value is different from the current window.location value
Diffstat (limited to 'src/Browser.js')
-rw-r--r--src/Browser.js12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/Browser.js b/src/Browser.js
index 3e120e5b..55b65471 100644
--- a/src/Browser.js
+++ b/src/Browser.js
@@ -39,7 +39,8 @@ function Browser(window, document, body, XHR, $log) {
var self = this,
rawDocument = document[0],
location = window.location,
- setTimeout = window.setTimeout;
+ setTimeout = window.setTimeout,
+ lastLocationUrl;
self.isMock = false;
@@ -201,10 +202,13 @@ function Browser(window, document, body, XHR, $log) {
* Sets browser's url
*/
self.setUrl = function(url) {
- var existingURL = location.href;
+
+ var existingURL = lastLocationUrl;
if (!existingURL.match(/#/)) existingURL += '#';
if (!url.match(/#/)) url += '#';
- location.href = url;
+ if (existingURL != url) {
+ location.href = url;
+ }
};
/**
@@ -219,7 +223,7 @@ function Browser(window, document, body, XHR, $log) {
* @returns {string} Browser's url
*/
self.getUrl = function() {
- return location.href;
+ return lastLocationUrl = location.href;
};