Skip to content

Instantly share code, notes, and snippets.

@amrnt
Created January 3, 2012 14:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amrnt/1555068 to your computer and use it in GitHub Desktop.
Save amrnt/1555068 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 iframeManager;
iframeManager = {
xhrCallback: null,
iframeLoading: !1,
loadQueue: [],
addLoadCallback: function(a) {
if (iframeManager.isLoaded()) {
return a();
} else {
return iframeManager.loadQueue.push(a);
}
},
runLoadCallbacks: function() {
var a, _i, _len, _ref, _results;
_ref = iframeManager.loadQueue;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
a = _ref[_i];
_results.push(a());
}
return _results;
},
isLoaded: function() {
return null !== iframeManager.xhrCallback;
},
buildIframe: function(apiServer) {
var a, b, c;
if (!iframeManager.iframeLoading) {
iframeManager.iframeLoading = !0;
a = document.createElement("div");
b = "" + apiServer + "receiver.html?parent=" + (encodeURIComponent(window.location.href));
a.innerHTML = "<iframe onload=\"window._tempIframeCallback()\" id=\"receiver_iframe\" tabindex=\"-1\" role=\"presentation\" style=\"position:absolute;top:-9999px;\" src=\"" + b + "\"></iframe>";
c = a.firstChild;
window._tempIframeCallback = function() {
delete api._tempIframeCallback;
iframeManager.xhrCallback = window.XMLHttpRequest && ("file:" !== window.location.protocol || !window.ActiveXObject) ? function() {
return new c.contentWindow.XMLHttpRequest;
} : function() {
try {
return new c.contentWindow.ActiveXObject("Microsoft.XMLHTTP");
} catch (_error) {}
};
return iframeManager.runLoadCallbacks();
};
return document.body.appendChild(c);
}
}
};
window.iframeManager = iframeManager;
}).call(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment