diff --git a/themes/bootstrap3/js/common.js b/themes/bootstrap3/js/common.js index 288e40075b7..875f95c92f1 100644 --- a/themes/bootstrap3/js/common.js +++ b/themes/bootstrap3/js/common.js @@ -31,8 +31,14 @@ var VuFind = (function VuFind() { listeners[event] = []; } - listeners[event].push(fn); - return () => unlisten(event, fn); + const listenFn = !once : fn : (...args) => { + fn(...args); + // Automatically remove a listener we only want to run once + unlisten(arguments.callee); + }; + + listeners[event].push(listenFn); + return () => unlisten(event, listenFn); } function emit(event, ...args) { diff --git a/themes/bootstrap3/js/lightbox.js b/themes/bootstrap3/js/lightbox.js index 1c2ac9d0d55..eeb1f964b52 100644 --- a/themes/bootstrap3/js/lightbox.js +++ b/themes/bootstrap3/js/lightbox.js @@ -323,9 +323,8 @@ VuFind.register('lightbox', function Lightbox() { // onclose behavior if ('string' === typeof $(form).data('lightboxOnclose')) { VuFind.listen('lightbox.closed', function lightboxClosed() { - VuFind.unlisten('lightbox.closed', arguments.callee); // only once VuFind.evalCallback($(form).data('lightboxOnclose'), null, form); - }); + }, { once: true }); } // Prevent multiple submission of submit button in lightbox if (submit.closest(_modal).length > 0) {