diff --git a/wagtail/wagtailadmin/static/wagtailadmin/js/page-editor.js b/wagtail/wagtailadmin/static/wagtailadmin/js/page-editor.js index 03adb7aca..96eed6bf6 100644 --- a/wagtail/wagtailadmin/static/wagtailadmin/js/page-editor.js +++ b/wagtail/wagtailadmin/static/wagtailadmin/js/page-editor.js @@ -331,36 +331,65 @@ $(function() { /* Set up behaviour of preview button */ $('.action-preview').click(function(e) { e.preventDefault(); + $this = $(this); - var previewWindow = window.open($(this).data('placeholder'), $(this).data('windowname')); - - $.ajax({ - type: "POST", - url: $(this).data('action'), - data: $('#page-edit-form').serialize(), - success: function(data, textStatus, request) { - if (request.getResponseHeader('X-Wagtail-Preview') == 'ok') { - previewWindow.document.open(); - previewWindow.document.write(data); - previewWindow.document.close(); - } else { - previewWindow.close(); - document.open(); - document.write(data); - document.close(); - } - }, - error: function(xhr, textStatus, errorThrown) { - /* If an error occurs, display it in the preview window so that - we aren't just showing the spinner forever. We preserve the original - error output rather than giving a 'friendly' error message so that - developers can debug template errors. (On a production site, we'd - typically be serving a friendly custom 500 page anyhow.) */ - - previewWindow.document.open(); - previewWindow.document.write(xhr.responseText); - previewWindow.document.close(); + var previewWindow = window.open($this.data('placeholder'), $this.data('windowname')); + + if(/MSIE/.test(navigator.userAgent)){ + submitPreview.call($this, false); + } else { + previewWindow.onload = function(){ + submitPreview.call($this, true); } - }); + } + + function submitPreview(enhanced){ + $.ajax({ + type: "POST", + url: $(this).data('action'), + data: $('#page-edit-form').serialize(), + success: function(data, textStatus, request) { + if (request.getResponseHeader('X-Wagtail-Preview') == 'ok') { + var pdoc = previewWindow.document; + + if(enhanced){ + var frame = pdoc.getElementById('preview-frame'); + + frame = frame.contentWindow || frame.contentDocument.document || frame.contentDocument; + frame.document.open(); + frame.document.write(data); + frame.document.close(); + + var hideTimeout = setTimeout(function(){ + pdoc.getElementById('loading-spinner-wrapper').className += 'remove'; + clearTimeout(hideTimeout); + }) // just enough to give effect without adding discernible slowness + } else { + pdoc.open(); + pdoc.write(data); + pdoc.close() + } + } else { + previewWindow.close(); + document.open(); + document.write(data); + document.close(); + } + }, + error: function(xhr, textStatus, errorThrown) { + /* If an error occurs, display it in the preview window so that + we aren't just showing the spinner forever. We preserve the original + error output rather than giving a 'friendly' error message so that + developers can debug template errors. (On a production site, we'd + typically be serving a friendly custom 500 page anyhow.) */ + + previewWindow.document.open(); + previewWindow.document.write(xhr.responseText); + previewWindow.document.close(); + } + }); + + } + }); }); diff --git a/wagtail/wagtailadmin/templates/wagtailadmin/pages/preview.html b/wagtail/wagtailadmin/templates/wagtailadmin/pages/preview.html index 46a4d2867..d5c4b7a51 100644 --- a/wagtail/wagtailadmin/templates/wagtailadmin/pages/preview.html +++ b/wagtail/wagtailadmin/templates/wagtailadmin/pages/preview.html @@ -11,5 +11,6 @@