mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-20 00:10:26 +00:00
merge
This commit is contained in:
commit
5bd23fde7a
4 changed files with 49 additions and 0 deletions
|
|
@ -411,3 +411,4 @@ function angularInit(config){
|
|||
compile(window.document, config).$init();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -163,6 +163,7 @@ function createScope(parent, Class) {
|
|||
behavior.$root = instance;
|
||||
behavior.$parent = instance;
|
||||
}
|
||||
|
||||
(parent.$onEval || noop)(instance.$eval);
|
||||
Class.apply(instance, slice.call(arguments, 2, arguments.length));
|
||||
|
||||
|
|
|
|||
46
src/UrlWatcher.js
Normal file
46
src/UrlWatcher.js
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
|
||||
// ////////////////////////////
|
||||
// UrlWatcher
|
||||
// ////////////////////////////
|
||||
|
||||
function UrlWatcher(location) {
|
||||
this.location = location;
|
||||
this.delay = 25;
|
||||
this.setTimeout = function(fn, delay) {
|
||||
window.setTimeout(fn, delay);
|
||||
};
|
||||
this.expectedUrl = location.href;
|
||||
this.listeners = [];
|
||||
}
|
||||
|
||||
UrlWatcher.prototype = {
|
||||
watch: function(fn){
|
||||
this.listeners.push(fn);
|
||||
},
|
||||
|
||||
start: function() {
|
||||
var self = this;
|
||||
(function pull () {
|
||||
if (self.expectedUrl !== self.location.href) {
|
||||
foreach(self.listeners, function(listener){
|
||||
listener(self.location.href);
|
||||
});
|
||||
self.expectedUrl = self.location.href;
|
||||
}
|
||||
self.setTimeout(pull, self.delay);
|
||||
})();
|
||||
},
|
||||
|
||||
set: function(url) {
|
||||
var existingURL = this.location.href;
|
||||
if (!existingURL.match(/#/))
|
||||
existingURL += '#';
|
||||
if (existingURL != url)
|
||||
this.location.href = url;
|
||||
this.existingURL = url;
|
||||
},
|
||||
|
||||
get: function() {
|
||||
return this.location.href;
|
||||
}
|
||||
};
|
||||
|
|
@ -45,4 +45,5 @@ describe("services", function(){
|
|||
|
||||
expect(scope.$location()).toEqual('file:///Users/Shared/misko/work/angular.js/scenario/widgets.html');
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue