Skip to content

Commit

Permalink
Modified the attachedTo member to be an integer that is incremented
Browse files Browse the repository at this point in the history
- Essentially just reference counts the connections that are attached to
the loadPreventer
- Also changed the way I create garbage frames.  Moved the variable into
the inner closure

#215
  • Loading branch information
NTaylorMullen committed Mar 23, 2013
1 parent 3f264ce commit 784e28b
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 61 deletions.
Expand Up @@ -1340,7 +1340,7 @@
loadPreventer = (function () {
var iframeTrashIntervalId = null,
trashInterval = 3000,
attachedTo = null,
attachedTo = 0,
ieVersion = (function () {
var version,
matches;
Expand All @@ -1359,27 +1359,31 @@
})();

return {
prevent: function (connection) {
var garbageFrame;

prevent: function () {
// Prevent additional iframe trash procedures from multiple connections and newer browsers
if (ieVersion <= 8 && attachedTo === null) {
attachedTo = connection;
garbageFrame = $("<iframe style='position:absolute;top:0;left:0;width:0;height:0;visibility:hidden;' src=''></iframe>");

// Create and destroy iframe every 3 seconds to prevent loading icon, super hacky
iframeTrashIntervalId = window.setInterval(function () {
$("body").append(garbageFrame);
$(garbageFrame).remove();
}, trashInterval);
if (ieVersion <= 8) {

// We only ever want to set the interval one time, so on the first attachTo
if (attachedTo++ === 0) {
// Create and destroy iframe every 3 seconds to prevent loading icon, super hacky
iframeTrashIntervalId = window.setInterval(function () {
var garbageFrame = $("<iframe style='position:absolute;top:0;left:0;width:0;height:0;visibility:hidden;' src=''></iframe>");

$("body").append(garbageFrame);
$(garbageFrame).remove();
garbageFrame = null;
}, trashInterval);
}
}
},
cancel: function (connection) {
// Only the connection that the loadPreventer is attached to can cancel the loadPreventer
// If a newer version of IE attachedTo will always = null so this will noop
if (attachedTo === connection) {
cancel: function () {
// Only clear the interval if there's only one more object that the loadPreventer is attachedTo
if (attachedTo === 1) {
window.clearInterval(iframeTrashIntervalId);
attachedTo = null;
}

if (attachedTo > 0) {
attachedTo--;
}
}
};
Expand Down Expand Up @@ -1409,7 +1413,7 @@

// Start preventing loading icon
// This will only perform work if the loadPreventer is not attached to another connection.
loadPreventer.prevent(connection);
loadPreventer.prevent();

// Build the url
url = transportLogic.getUrl(connection, this.name);
Expand Down Expand Up @@ -1490,7 +1494,7 @@
var cw = null;

// Stop attempting to prevent loading icon
loadPreventer.cancel(connection);
loadPreventer.cancel();

if (connection.frame) {
if (connection.frame.stop) {
Expand Down

0 comments on commit 784e28b

Please sign in to comment.