From bb285a0c91f9892e4b5d80d8c2bf8bb89a7a6bc3 Mon Sep 17 00:00:00 2001
From: Ere Maijala <ere.maijala@helsinki.fi>
Date: Wed, 16 Mar 2016 15:14:40 +0200
Subject: [PATCH] Use a more specific selector when checking for flash messages
 in lightbox so that other markup using the classes doesn't confuse lightbox.
 Also always use jQuery selectors to find the flash messages to be more
 tolerant of markup changes (e.g. whitespace, class ordering etc.).

---
 .../VuFind/View/Helper/Bootstrap3/Flashmessages.php  |  2 +-
 themes/bootstrap3/js/lightbox.js                     | 12 ++++++------
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/module/VuFind/src/VuFind/View/Helper/Bootstrap3/Flashmessages.php b/module/VuFind/src/VuFind/View/Helper/Bootstrap3/Flashmessages.php
index 2415ad5bab4..1399a8bd60c 100644
--- a/module/VuFind/src/VuFind/View/Helper/Bootstrap3/Flashmessages.php
+++ b/module/VuFind/src/VuFind/View/Helper/Bootstrap3/Flashmessages.php
@@ -50,6 +50,6 @@ class Flashmessages extends \VuFind\View\Helper\Root\Flashmessages
         if ($ns == 'error') {
             $ns = 'danger';
         }
-        return 'alert alert-' . $ns;
+        return 'flash-message alert alert-' . $ns;
     }
 }
diff --git a/themes/bootstrap3/js/lightbox.js b/themes/bootstrap3/js/lightbox.js
index 9c793894ba6..f5565d025dd 100644
--- a/themes/bootstrap3/js/lightbox.js
+++ b/themes/bootstrap3/js/lightbox.js
@@ -68,8 +68,8 @@ VuFind.lightbox = (function() {
       return;
     }
     // Isolate successes
-    var htmlDiv = $('<div>'+html+'</div>');
-    var alerts = htmlDiv.find('.alert-success');
+    var htmlDiv = $('<div/>').html(html);
+    var alerts = htmlDiv.find('.flash-message.alert-success');
     if (alerts.length > 0) {
       showAlert(alerts[0].innerHTML, 'success');
       return;
@@ -127,10 +127,10 @@ VuFind.lightbox = (function() {
           return;
         }
         if ( // Close the lightbox after deliberate login
-          obj.method                                                  // is a form
-          && !html.match(/alert alert-danger/)                        // skip failed logins
-          && ((obj.url.match(/MyResearch/) && !obj.url.match(/Bulk/)) // that matches login/create account
-            || obj.url.match(/catalogLogin/))                         // or catalog login for holds
+          obj.method                                                                // is a form
+          && ((obj.url.match(/MyResearch/) && !obj.url.match(/Bulk/))               // that matches login/create account
+            || obj.url.match(/catalogLogin/))                                       // or catalog login for holds
+          && $('<div/>').html(html).find('.flash-message.alert-danger').length == 0 // skip failed logins
         ) {
           if (_originalUrl.match(/UserLogin/) || obj.url.match(/catalogLogin/)) {
             _refreshPage();
-- 
GitLab