Created
January 3, 2012 14:21
-
-
Save amrnt/1555071 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Author: Amr Numan Tamimi <amrnt0@gmail.com> | |
* Extracted from: Foursquare.com | |
* Last Modify: 1/3/2011 | |
*/ | |
(function() { | |
var Api; | |
Api = (function() { | |
function Api(apiServer, apiVersion) { | |
this.iframeManager = iframeManager; | |
this.apiServer = apiServer; | |
this.apiVersion = apiVersion; | |
} | |
Api.prototype.ajax = function(req) { | |
var self; | |
if (this.iframeManager.isLoaded()) { | |
req.xhr = this.iframeManager.xhrCallback; | |
req.crossDomain = !1; | |
req.dataType = "json"; | |
return $.ajax(req); | |
} else { | |
self = this; | |
this.iframeManager.addLoadCallback(function() { | |
return self.ajax(req); | |
}); | |
return this.iframeManager.buildIframe(this.apiServer); | |
} | |
}; | |
Api.prototype.request = function(options) { | |
options.type = options.type || "GET"; | |
options.url = options.url ? "" + this.apiServer + this.apiVersion + options.url : void 0; | |
options.data = options.data || {}; | |
options.headers = options.headers || {}; | |
return this.ajax(options); | |
}; | |
return Api; | |
})(); | |
window.api = new Api("http://API_DOMAIN/", API_VERSION); | |
}).call(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment