From b1c6063b4118c7ed3ec4ec07f553253e8d11bf87 Mon Sep 17 00:00:00 2001 From: Matt Westcott Date: Fri, 13 May 2016 13:16:01 +0100 Subject: [PATCH] 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. --- .../static_src/wagtailadmin/js/page-editor.js | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/wagtail/wagtailadmin/static_src/wagtailadmin/js/page-editor.js b/wagtail/wagtailadmin/static_src/wagtailadmin/js/page-editor.js index f12a17dd62..c6e3235bb0 100644 --- a/wagtail/wagtailadmin/static_src/wagtailadmin/js/page-editor.js +++ b/wagtail/wagtailadmin/static_src/wagtailadmin/js/page-editor.js @@ -452,13 +452,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) { @@ -481,13 +486,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 {