From bf8004c545104d3f3b0ee960b4433926e854a798 Mon Sep 17 00:00:00 2001 From: Chris Hallberg <crhallberg@gmail.com> Date: Tue, 16 Dec 2014 15:04:33 -0500 Subject: [PATCH] Add ability to specify error type in checkForError/displayError --- themes/bootstrap3/js/lightbox.js | 35 ++++++++++++++++---------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/themes/bootstrap3/js/lightbox.js b/themes/bootstrap3/js/lightbox.js index 2fffedc84ef..ddc3687dd1b 100644 --- a/themes/bootstrap3/js/lightbox.js +++ b/themes/bootstrap3/js/lightbox.js @@ -160,11 +160,15 @@ var Lightbox = { * * If one is not found, return html to a success callback function */ - checkForError: function(html, success) { - var fi = html.indexOf('<div class="alert alert-danger">'); + checkForError: function(html, success, type) { + if(typeof type === "undefined") { + type = "danger"; + } + var divPattern = '<div class="alert alert-'+type+'">'; + var fi = html.indexOf(divPattern); if(fi > -1) { - var li = html.indexOf('</div>', fi+31); - Lightbox.displayError(html.substring(fi+31, li).replace(/^[\s<>]+|[\s<>]+$/g, '')); + var li = html.indexOf('</div>', fi+divPattern.length); + Lightbox.displayError(html.substring(fi+divPattern.length, li).replace(/^[\s<>]+|[\s<>]+$/g, ''), type); } else { success(html); } @@ -172,22 +176,19 @@ var Lightbox = { /** * Insert an error alert element at the top of the lightbox */ - displayError: function(message) { - var alert = $('#modal .modal-body .alert'); + displayError: function(message, type) { + if(typeof type === "undefined") { + type = "danger"; + } + $('#modal .modal-body .alert').remove(); var html = $.parseHTML($('#modal .modal-body').html()); - // Page with dismissable alert already present - if(alert.find('.message').length > 0 && html.length > 1) { - $(alert).find('.message').html(message); - // Page with alert already present - } else if(alert.length > 0 && html.length > 1) { - $(alert).html(message); - // Empty or alert only, change to message with button - } else if($('#modal .modal-body').html() == vufindString.loading+"..." - || (html.length == 1 && $(html).hasClass('alert-danger'))) { - Lightbox.changeContent('<div class="alert alert-danger" role="alert">'+message+'</div><button class="btn btn-default" onClick="Lightbox.close()">'+vufindString['close']+'</button>'); + // Empty or alert only, change to message with button + if($('#modal .modal-body').html() == vufindString.loading+"..." + || (html.length == 1 && $(html).hasClass('alert-'+type))) { + Lightbox.changeContent('<div class="alert alert-'+type+'" role="alert">'+message+'</div><button class="btn btn-default" onClick="Lightbox.close()">'+vufindString['close']+'</button>'); // Page without alert } else { - $('#modal .modal-body').prepend('<div class="alert alert-danger alert-dismissible" role="alert"><button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button><p class="message">'+message+'</p></div>'); + $('#modal .modal-body').prepend('<div class="alert alert-'+type+' alert-dismissible" role="alert"><button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button><p class="message">'+message+'</p></div>'); } $('.fa-spinner').remove(); if (typeof Recaptcha !== "undefined" && Recaptcha.widget) { -- GitLab