This commit is contained in:
Misko Hevery 2010-04-02 11:16:49 -07:00
commit 5bd23fde7a
4 changed files with 49 additions and 0 deletions

View file

@ -411,3 +411,4 @@ function angularInit(config){
compile(window.document, config).$init();
}
}

View file

@ -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
View 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;
}
};

View file

@ -45,4 +45,5 @@ describe("services", function(){
expect(scope.$location()).toEqual('file:///Users/Shared/misko/work/angular.js/scenario/widgets.html');
});
});