@@ -, +, @@ from duplicating --- .../prog/js/pages/preferences.js | 174 ++++++++++-------- 1 file changed, 95 insertions(+), 79 deletions(-) --- a/koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js +++ a/koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js @@ -67,75 +67,91 @@ window.onbeforeunload = function () { // Add event handlers to any elements with .expand-textarea classes // this allows the CodeMirror widget to be displayed function addExpandHandler() { - // Don't duplicate click event handlers - const ev = $._data($('.expand-textarea'), 'events'); - if (ev && ev.click) { - return; - } - $(".expand-textarea").on("click", function (e) { - e.preventDefault(); - $(this).hide(); - var target = $(this).data("target"); - var syntax = $(this).data("syntax"); - $("#collapse_" + target).show(); - if (syntax) { - var editor = CodeMirror.fromTextArea(document.getElementById("pref_" + target), { - lineNumbers: true, - mode: syntax, - lineWrapping: true, - viewportMargin: Infinity, - gutters: ["CodeMirror-lint-markers"], - lint: true - }); - editor.on("change", function () { - mark_modified.call($("#pref_" + target)[0]); - }); - editor.on("blur", function () { - editor.save(); - }); - } else { - $("#pref_" + target).show(); + const textAreas = $('.expand-textarea').map(function() { + return this + }).get(); + textAreas.forEach((expandTextArea) => { + // Don't duplicate click event handlers + const ev = $._data($(expandTextArea).get(0), 'events'); + if (ev && ev.click) { + return; } - }); + // Add the click event + $(expandTextArea).on("click", function (e) { + e.preventDefault(); + $(this).hide(); + var target = $(this).data("target"); + var syntax = $(this).data("syntax"); + $("#collapse_" + target).show(); + if (syntax) { + var editor = CodeMirror.fromTextArea(document.getElementById("pref_" + target), { + lineNumbers: true, + mode: syntax, + lineWrapping: true, + viewportMargin: Infinity, + gutters: ["CodeMirror-lint-markers"], + lint: true + }); + editor.on("change", function () { + mark_modified.call($("#pref_" + target)[0]); + }); + editor.on("blur", function () { + editor.save(); + }); + } else { + $("#pref_" + target).show(); + } + }); + }) } // Add event handlers to any elements with .collapse-textarea classes // this allows the hiding of the CodeMirror widget function addCollapseHandler() { - // Don't duplicate click event handlers - const ev = $._data($('.collapse-textarea'), 'events'); - if (ev && ev.click) { - return; - } - $(".collapse-textarea").on("click", function (e) { - e.preventDefault(); - $(this).hide(); - var target = $(this).data("target"); - var syntax = $(this).data("syntax"); - $("#expand_" + target).show(); - if (syntax) { - var editor = $("#pref_" + target).next(".CodeMirror")[0].CodeMirror; - editor.toTextArea(); + const textAreas = $('.collapse-textarea').map(function() { + return this + }).get(); + textAreas.forEach((collapseTextArea) => { + // Don't duplicate click event handlers + const ev = $._data($(collapseTextArea).get(0), 'events'); + if (ev && ev.click) { + return; } - $("#pref_" + target).hide(); - }); + $(collapseTextArea).on("click", function (e) { + e.preventDefault(); + $(this).hide(); + var target = $(this).data("target"); + var syntax = $(this).data("syntax"); + $("#expand_" + target).show(); + if (syntax) { + var editor = $("#pref_" + target).next(".CodeMirror")[0].CodeMirror; + editor.toTextArea(); + } + $("#pref_" + target).hide(); + }); + }) } // Add a handler for any consent delete links function addConsentDeleteHandler() { - // Don't duplicate click event handlers - const ev = $._data($('.consentDelete'), 'events'); - if (ev && ev.click) { - return; - } - $('.consentDelete').on('click', function (e) { - e.preventDefault(); - const target = $(this).data('target'); - const proceed = confirm(__('Are you sure you want to delete this consent item?')); - if (proceed) { - $('#' + target).remove(); + const deleteButtons = $('.consentDelete').map(function() { + return this + }).get(); + deleteButtons.forEach((deleteButton) => { + // Don't duplicate click event handlers + const ev = $._data($(deleteButton).get(0), 'events'); + if (ev && ev.click) { + return; } - }); + $(deleteButton).on('click', function (e) { + e.preventDefault(); + const target = $(this).data('target'); + const proceed = confirm(__('Are you sure you want to delete this consent item?')); + if (proceed) { + $('#' + target).remove(); + } + }); + }) } $( document ).ready( function () { @@ -335,12 +351,12 @@ $( document ).ready( function () { ''; } - // Create a consentJS item, correctly populated - function createConsentJSItem(item, idx) { - const id = 'ConsentJS_' + idx; + // Create a cookieConsentedJS item, correctly populated + function createCookieConsentedJSItem(item, idx) { + const id = 'CookieConsentedJS_' + idx; const code = item.code && item.code.length > 0 ? atob(item.code) : ''; const itemId = item.id && item.id.length > 0 ? item.id : ''; - return '