aboutsummaryrefslogtreecommitdiffstats
path: root/src/Browser.js
diff options
context:
space:
mode:
authorMisko Hevery2010-07-22 11:18:32 -0700
committerMisko Hevery2010-07-22 11:18:32 -0700
commit849a05b5a578f19ddc3d24dc9fbd304e0e07612a (patch)
tree3e32e2ab7b8c1ed3f53e5b568990070b5edab4fa /src/Browser.js
parentb5bbfaeb80c3f89c65d14c72cff6f0e1c8aa497a (diff)
downloadangular.js-849a05b5a578f19ddc3d24dc9fbd304e0e07612a.tar.bz2
added jsonp to resources
Diffstat (limited to 'src/Browser.js')
-rw-r--r--src/Browser.js48
1 files changed, 31 insertions, 17 deletions
diff --git a/src/Browser.js b/src/Browser.js
index 0552b3ae..3299540c 100644
--- a/src/Browser.js
+++ b/src/Browser.js
@@ -2,7 +2,7 @@
// Browser
//////////////////////////////
-function Browser(location, document) {
+function Browser(location, document, head) {
this.delay = 50;
this.expectedUrl = location.href;
this.urlListeners = [];
@@ -21,8 +21,9 @@ function Browser(location, document) {
};
this.location = location;
- this.document = jqLite(document);
- this.body = jqLite(document.body);
+ this.document = document;
+ this.head = head;
+ this.idCounter = 0;
}
Browser.prototype = {
@@ -58,21 +59,34 @@ Browser.prototype = {
callback = post;
post = null;
}
- var xhr = new this.XHR(),
- self = this;
- xhr.open(method, url, true);
- this.outstandingRequests.count ++;
- xhr.onreadystatechange = function() {
- if (xhr.readyState == 4) {
- try {
- callback(xhr.status || 200, xhr.responseText);
- } finally {
- self.outstandingRequests.count--;
- self.processRequestCallbacks();
+ if (lowercase(method) == 'json') {
+ var callbackId = "angular_" + Math.random() + '_' + (this.idCounter++);
+ callbackId = callbackId.replace(/\d\./, '');
+ var script = this.document[0].createElement('script');
+ script.type = 'text/javascript';
+ script.src = url.replace('JSON_CALLBACK', callbackId);
+ this.head.append(script);
+ window[callbackId] = function(data){
+ delete window[callbackId];
+ callback(200, data);
+ };
+ } else {
+ var xhr = new this.XHR(),
+ self = this;
+ xhr.open(method, url, true);
+ this.outstandingRequests.count ++;
+ xhr.onreadystatechange = function() {
+ if (xhr.readyState == 4) {
+ try {
+ callback(xhr.status || 200, xhr.responseText);
+ } finally {
+ self.outstandingRequests.count--;
+ self.processRequestCallbacks();
+ }
}
- }
- };
- xhr.send(post || '');
+ };
+ xhr.send(post || '');
+ }
},
processRequestCallbacks: function(){