aboutsummaryrefslogtreecommitdiffstats
path: root/src/Browser.js
diff options
context:
space:
mode:
authorMisko Hevery2010-04-03 17:04:36 -0700
committerMisko Hevery2010-04-03 17:04:36 -0700
commita80a61839a66d244c8bb14bbe2975746e02516c8 (patch)
tree5a7b4d9d3e2a7a15ebf55e068782fbf2aa4ac6bf /src/Browser.js
parent35ca4fcb9c49e505e28669e951e01ddedb01d7db (diff)
downloadangular.js-a80a61839a66d244c8bb14bbe2975746e02516c8.tar.bz2
injection is now working
Diffstat (limited to 'src/Browser.js')
-rw-r--r--src/Browser.js46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/Browser.js b/src/Browser.js
new file mode 100644
index 00000000..bdf57386
--- /dev/null
+++ b/src/Browser.js
@@ -0,0 +1,46 @@
+
+//////////////////////////////
+// Browser
+//////////////////////////////
+
+function Browser(location) {
+ this.location = location;
+ this.delay = 25;
+ this.setTimeout = function(fn, delay) {
+ window.setTimeout(fn, delay);
+ };
+ this.expectedUrl = location.href;
+ this.listeners = [];
+}
+
+Browser.prototype = {
+ watchUrl: function(fn){
+ this.listeners.push(fn);
+ },
+
+ startUrlWatcher: 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);
+ })();
+ },
+
+ setUrl: function(url) {
+ var existingURL = this.location.href;
+ if (!existingURL.match(/#/))
+ existingURL += '#';
+ if (existingURL != url)
+ this.location.href = url;
+ this.existingURL = url;
+ },
+
+ getUrl: function() {
+ return this.location.href;
+ }
+};