Make preview window work on IE11

IE doesn't provide standard onload event listeners on opened windows, so this code did user-agent sniffing
on the string 'MSIE' to bypass the onload animation. This failed on IE11, which drops 'MSIE' from the
user agent string. The code now checks for the presence of addEventListener instead.

As a bonus, it now falls back on IE's (non-standard?) attachEvent method, so the animation now works on IE
after all.
This commit is contained in:
Matt Westcott 2016-05-13 13:16:01 +01:00
parent 6081ab5480
commit 4ee93914ce

View file

@ -416,13 +416,18 @@ $(function() {
previewWindow = window.open($this.data('placeholder'), $this.data('windowname'));
if (/MSIE/.test(navigator.userAgent)) {
// If IE, load contents immediately without fancy effects
submitPreview.call($this, false);
} else {
previewWindow.onload = function() {
if (previewWindow.addEventListener) {
previewWindow.addEventListener('load', function() {
submitPreview.call($this, true);
}
}, false);
} else if (previewWindow.attachEvent) {
// for IE
previewWindow.attachEvent('onload', function() {
submitPreview.call($this, true);
}, false);
} else {
// Can't trap onload event, so load contents immediately without fancy effects
submitPreview.call($this, false);
}
function submitPreview(enhanced) {
@ -445,13 +450,13 @@ $(function() {
var hideTimeout = setTimeout(function() {
previewDoc.getElementById('loading-spinner-wrapper').className += ' remove';
clearTimeout(hideTimeout);
})
});
// just enough to give effect without adding discernible slowness
} else {
previewDoc.open();
previewDoc.write(data);
previewDoc.close()
previewDoc.close();
}
} else {