From 666b4fc143f0f320f5ad808c339386bb47ca5ac2 Mon Sep 17 00:00:00 2001
From: Chris Hallberg <chris.hallberg@hey.com>
Date: Thu, 29 Oct 2020 15:47:54 -0400
Subject: [PATCH] Return to previous page after printing. (#1753)

---
 themes/bootstrap3/js/common.js | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/themes/bootstrap3/js/common.js b/themes/bootstrap3/js/common.js
index efd7661b15b..8081e8b86f1 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'});
-- 
GitLab