Skip to content

Instantly share code, notes, and snippets.

@amrnt
Created January 3, 2012 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amrnt/1555071 to your computer and use it in GitHub Desktop.
Save amrnt/1555071 to your computer and use it in GitHub Desktop.
/*
* 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