mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-18 15:50:22 +00:00
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
This commit is contained in:
parent
fe5240732d
commit
120701b9d9
1 changed files with 8 additions and 4 deletions
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue