diff --git a/themes/bootstrap3/js/common.js b/themes/bootstrap3/js/common.js index efd7661b15be9e5f78eea051f1fe9a234815d035..8081e8b86f194f41b51f1bed65c38f8b5841d52e 100644 --- a/themes/bootstrap3/js/common.js +++ b/themes/bootstrap3/js/common.js @@ -394,10 +394,18 @@ $(document).ready(function commonDocReady() { // Print var url = window.location.href; - if (url.indexOf('?' + 'print' + '=') !== -1 || url.indexOf('&' + 'print' + '=') !== -1) { + if (url.indexOf('?print=') !== -1 || url.indexOf('&print=') !== -1) { $("link[media='print']").attr("media", "all"); $(document).ajaxStop(function triggerPrint() { - window.print(); + // Print dialogs cause problems during testing, so disable them + // when the "test mode" cookie is set. This should never happen + // under normal usage outside of the Phing startup process. + if (document.cookie.indexOf('VuFindTestSuiteRunning=') === -1) { + window.addEventListener("afterprint", function goBackAfterPrint() { history.back(); }, { once: true }); + window.print(); + } else { + console.log("Printing disabled due to test mode."); // eslint-disable-line no-console + } }); // Make an ajax call to ensure that ajaxStop is triggered $.getJSON(VuFind.path + '/AJAX/JSON', {method: 'keepAlive'});