aboutsummaryrefslogtreecommitdiffstats
path: root/src/Browser.js
diff options
context:
space:
mode:
authorMisko Hevery2010-04-05 11:46:53 -0700
committerMisko Hevery2010-04-05 11:46:53 -0700
commit7a4b48020688060debe9cb0f9c17615d7585cbe7 (patch)
tree48a5b1d8cf92bb272028a106ab9ea3ec16f477a2 /src/Browser.js
parent4bfa4e230d5ebdd582068effe7f4f1b60c43093a (diff)
downloadangular.js-7a4b48020688060debe9cb0f9c17615d7585cbe7.tar.bz2
added ng:switch widget
Diffstat (limited to 'src/Browser.js')
-rw-r--r--src/Browser.js20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/Browser.js b/src/Browser.js
index 893459ae..6036884f 100644
--- a/src/Browser.js
+++ b/src/Browser.js
@@ -3,9 +3,10 @@
// Browser
//////////////////////////////
-function Browser(location) {
+function Browser(location, XHR) {
this.location = location;
this.delay = 25;
+ this.XHR = XHR;
this.setTimeout = function(fn, delay) {
window.setTimeout(fn, delay);
};
@@ -14,6 +15,17 @@ function Browser(location) {
}
Browser.prototype = {
+ xhr: function(method, url, callback){
+ var xhr = new this.XHR();
+ xhr.open(method, url, true);
+ xhr.onreadystatechange = function() {
+ if (xhr.readyState == 4) {
+ callback(xhr.status, xhr.responseText);
+ }
+ };
+ xhr.send('');
+ },
+
watchUrl: function(fn){
this.listeners.push(fn);
},
@@ -23,7 +35,11 @@ Browser.prototype = {
(function pull () {
if (self.expectedUrl !== self.location.href) {
foreach(self.listeners, function(listener){
- listener(self.location.href);
+ try {
+ listener(self.location.href);
+ } catch (e) {
+ error(e);
+ }
});
self.expectedUrl = self.location.href;
}