| Lines 67-141
          window.onbeforeunload = function () {
      
      
        Link Here | 
        
          | 67 | // Add event handlers to any elements with .expand-textarea classes | 67 | // Add event handlers to any elements with .expand-textarea classes | 
        
          | 68 | // this allows the CodeMirror widget to be displayed | 68 | // this allows the CodeMirror widget to be displayed | 
        
          | 69 | function addExpandHandler() { | 69 | function addExpandHandler() { | 
          
            
              | 70 |     // Don't duplicate click event handlers | 70 |     const textAreas = $('.expand-textarea').map(function() { | 
            
              | 71 |     const ev = $._data($('.expand-textarea'), 'events'); | 71 |         return this | 
            
              | 72 |     if (ev && ev.click) { | 72 |     }).get(); | 
            
              | 73 |         return; | 73 |     textAreas.forEach((expandTextArea) => { | 
            
              | 74 |     } | 74 |         // Don't duplicate click event handlers | 
            
              | 75 |     $(".expand-textarea").on("click", function (e) { | 75 |         const ev = $._data($(expandTextArea).get(0), 'events'); | 
            
              | 76 |         e.preventDefault(); | 76 |         if (ev && ev.click) { | 
            
              | 77 |         $(this).hide(); | 77 |             return; | 
            
              | 78 |         var target = $(this).data("target"); |  |  | 
            
              | 79 |         var syntax = $(this).data("syntax"); | 
            
              | 80 |         $("#collapse_" + target).show(); | 
            
              | 81 |         if (syntax) { | 
            
              | 82 |             var editor = CodeMirror.fromTextArea(document.getElementById("pref_" + target), { | 
            
              | 83 |                 lineNumbers: true, | 
            
              | 84 |                 mode: syntax, | 
            
              | 85 |                 lineWrapping: true, | 
            
              | 86 |                 viewportMargin: Infinity, | 
            
              | 87 |                 gutters: ["CodeMirror-lint-markers"], | 
            
              | 88 |                 lint: true | 
            
              | 89 |             }); | 
            
              | 90 |             editor.on("change", function () { | 
            
              | 91 |                 mark_modified.call($("#pref_" + target)[0]); | 
            
              | 92 |             }); | 
            
              | 93 |             editor.on("blur", function () { | 
            
              | 94 |                 editor.save(); | 
            
              | 95 |             }); | 
            
              | 96 |         } else { | 
            
              | 97 |             $("#pref_" + target).show(); | 
        
          | 98 |         } | 78 |         } | 
          
            
              | 99 |     }); | 79 |         // Add the click event | 
            
              |  |  | 80 |         $(expandTextArea).on("click", function (e) { | 
            
              | 81 |             e.preventDefault(); | 
            
              | 82 |             $(this).hide(); | 
            
              | 83 |             var target = $(this).data("target"); | 
            
              | 84 |             var syntax = $(this).data("syntax"); | 
            
              | 85 |             $("#collapse_" + target).show(); | 
            
              | 86 |             if (syntax) { | 
            
              | 87 |                 var editor = CodeMirror.fromTextArea(document.getElementById("pref_" + target), { | 
            
              | 88 |                     lineNumbers: true, | 
            
              | 89 |                     mode: syntax, | 
            
              | 90 |                     lineWrapping: true, | 
            
              | 91 |                     viewportMargin: Infinity, | 
            
              | 92 |                     gutters: ["CodeMirror-lint-markers"], | 
            
              | 93 |                     lint: true | 
            
              | 94 |                 }); | 
            
              | 95 |                 editor.on("change", function () { | 
            
              | 96 |                     mark_modified.call($("#pref_" + target)[0]); | 
            
              | 97 |                 }); | 
            
              | 98 |                 editor.on("blur", function () { | 
            
              | 99 |                     editor.save(); | 
            
              | 100 |                 }); | 
            
              | 101 |             } else { | 
            
              | 102 |                 $("#pref_" + target).show(); | 
            
              | 103 |             } | 
            
              | 104 |         }); | 
            
              | 105 |     }) | 
        
          | 100 | } | 106 | } | 
        
          | 101 |  | 107 |  | 
        
          | 102 | // Add event handlers to any elements with .collapse-textarea classes | 108 | // Add event handlers to any elements with .collapse-textarea classes | 
        
          | 103 | // this allows the hiding of the CodeMirror widget | 109 | // this allows the hiding of the CodeMirror widget | 
        
          | 104 | function addCollapseHandler() { | 110 | function addCollapseHandler() { | 
          
            
              | 105 |     // Don't duplicate click event handlers | 111 |     const textAreas = $('.collapse-textarea').map(function() { | 
            
              | 106 |     const ev = $._data($('.collapse-textarea'), 'events'); | 112 |         return this | 
            
              | 107 |     if (ev && ev.click) { | 113 |     }).get(); | 
            
              | 108 |         return; | 114 |     textAreas.forEach((collapseTextArea) => { | 
            
              | 109 |     } | 115 |         // Don't duplicate click event handlers | 
            
              | 110 |     $(".collapse-textarea").on("click", function (e) { | 116 |         const ev = $._data($(collapseTextArea).get(0), 'events'); | 
            
              | 111 |         e.preventDefault(); | 117 |         if (ev && ev.click) { | 
            
              | 112 |         $(this).hide(); | 118 |             return; | 
            
              | 113 |         var target = $(this).data("target"); |  |  | 
            
              | 114 |         var syntax = $(this).data("syntax"); | 
            
              | 115 |         $("#expand_" + target).show(); | 
            
              | 116 |         if (syntax) { | 
            
              | 117 |             var editor = $("#pref_" + target).next(".CodeMirror")[0].CodeMirror; | 
            
              | 118 |             editor.toTextArea(); | 
        
          | 119 |         } | 119 |         } | 
          
            
              | 120 |         $("#pref_" + target).hide(); | 120 |         $(collapseTextArea).on("click", function (e) { | 
            
              | 121 |     }); | 121 |             e.preventDefault(); | 
            
              |  |  | 122 |             $(this).hide(); | 
            
              | 123 |             var target = $(this).data("target"); | 
            
              | 124 |             var syntax = $(this).data("syntax"); | 
            
              | 125 |             $("#expand_" + target).show(); | 
            
              | 126 |             if (syntax) { | 
            
              | 127 |                 var editor = $("#pref_" + target).next(".CodeMirror")[0].CodeMirror; | 
            
              | 128 |                 editor.toTextArea(); | 
            
              | 129 |             } | 
            
              | 130 |             $("#pref_" + target).hide(); | 
            
              | 131 |         }); | 
            
              | 132 |     }) | 
        
          | 122 | } | 133 | } | 
        
          | 123 |  | 134 |  | 
        
          | 124 | // Add a handler for any consent delete links | 135 | // Add a handler for any consent delete links | 
        
          | 125 | function addConsentDeleteHandler() { | 136 | function addConsentDeleteHandler() { | 
          
            
              | 126 |     // Don't duplicate click event handlers | 137 |     const deleteButtons = $('.consentDelete').map(function() { | 
            
              | 127 |     const ev = $._data($('.consentDelete'), 'events'); | 138 |         return this | 
            
              | 128 |     if (ev && ev.click) { | 139 |     }).get(); | 
            
              | 129 |         return; | 140 |     deleteButtons.forEach((deleteButton) => { | 
            
              | 130 |     } | 141 |         // Don't duplicate click event handlers | 
            
              | 131 |     $('.consentDelete').on('click', function (e) { | 142 |         const ev = $._data($(deleteButton).get(0), 'events'); | 
            
              | 132 |         e.preventDefault(); | 143 |         if (ev && ev.click) { | 
            
              | 133 |         const target = $(this).data('target'); | 144 |             return; | 
            
              | 134 |         const proceed = confirm(__('Are you sure you want to delete this consent item?')); |  |  | 
            
              | 135 |         if (proceed) { | 
            
              | 136 |             $('#' + target).remove(); | 
        
          | 137 |         } | 145 |         } | 
          
            
              | 138 |     }); | 146 |         $(deleteButton).on('click', function (e) { | 
            
              |  |  | 147 |             e.preventDefault(); | 
            
              | 148 |             const target = $(this).data('target'); | 
            
              | 149 |             const proceed = confirm(__('Are you sure you want to delete this consent item?')); | 
            
              | 150 |             if (proceed) { | 
            
              | 151 |                 $('#' + target).remove(); | 
            
              | 152 |             } | 
            
              | 153 |         }); | 
            
              | 154 |     }) | 
        
          | 139 | } | 155 | } | 
        
          | 140 |  | 156 |  | 
        
          | 141 | $( document ).ready( function () { | 157 | $( document ).ready( function () { | 
  
    | Lines 335-346
          $( document ).ready( function () {
      
      
        Link Here | 
        
          | 335 |             '<input id="' + id + '" type="checkbox" class="' + className + '">'; | 351 |             '<input id="' + id + '" type="checkbox" class="' + className + '">'; | 
        
          | 336 |     } | 352 |     } | 
        
          | 337 |  | 353 |  | 
          
            
              | 338 |     // Create a consentJS item, correctly populated | 354 |     // Create a cookieConsentedJS item, correctly populated | 
            
              | 339 |     function createConsentJSItem(item, idx) { | 355 |     function createCookieConsentedJSItem(item, idx) { | 
            
              | 340 |         const id = 'ConsentJS_' + idx; | 356 |         const id = 'CookieConsentedJS_' + idx; | 
        
          | 341 |         const code = item.code && item.code.length > 0 ? atob(item.code) : ''; | 357 |         const code = item.code && item.code.length > 0 ? atob(item.code) : ''; | 
        
          | 342 |         const itemId = item.id && item.id.length > 0 ? item.id : ''; | 358 |         const itemId = item.id && item.id.length > 0 ? item.id : ''; | 
          
            
              | 343 |         return '<div id="' + id + '" class="consentJSItem" data-id="' + itemId + '">' + | 359 |         return '<div id="' + id + '" class="cookieConsentedJSItem" data-id="' + itemId + '">' + | 
        
          | 344 |                '    <div class="consentRow">' + | 360 |                '    <div class="consentRow">' + | 
        
          | 345 |                '        <div class="consentItem">' + | 361 |                '        <div class="consentItem">' + | 
        
          | 346 |                '            <label class="required" for="name_' + id + '">' + __('Name') + ':</label>' + | 362 |                '            <label class="required" for="name_' + id + '">' + __('Name') + ':</label>' + | 
  
    | Lines 382-397
          $( document ).ready( function () {
      
      
        Link Here | 
        
          | 382 |                '</div > '; | 398 |                '</div > '; | 
        
          | 383 |     } | 399 |     } | 
        
          | 384 |  | 400 |  | 
          
            
              | 385 |     // Return the markup for all consentJS items concatenated | 401 |     // Return the markup for all cookieConsentedJS items concatenated | 
        
          | 386 |     function populateConsentMarkup(items) { | 402 |     function populateConsentMarkup(items) { | 
        
          | 387 |         return items.reduce(function (acc, current, idx) { | 403 |         return items.reduce(function (acc, current, idx) { | 
          
            
              | 388 |             return acc + createConsentJSItem(current, idx); | 404 |             return acc + createCookieConsentedJSItem(current, idx); | 
        
          | 389 |         }, ''); | 405 |         }, ''); | 
        
          | 390 |     } | 406 |     } | 
        
          | 391 |  | 407 |  | 
        
          | 392 |     // Return the markup for a validation warning | 408 |     // Return the markup for a validation warning | 
        
          | 393 |     function populateValidationWarning() { | 409 |     function populateValidationWarning() { | 
          
            
              | 394 |         return '<div id="consentJSWarning" class="error" style="display:none;">' + __('You must complete all fields') + '</div>'; | 410 |         return '<div id="cookieConsentedJSWarning" class="error" style="display:none;">' + __('You must complete all fields') + '</div>'; | 
        
          | 395 |     } | 411 |     } | 
        
          | 396 |  | 412 |  | 
        
          | 397 |     // Return a new, empty consent item | 413 |     // Return a new, empty consent item | 
  
    | Lines 410-435
          $( document ).ready( function () {
      
      
        Link Here | 
        
          | 410 |  | 426 |  | 
        
          | 411 |     // Add the handler for a new empty consent item | 427 |     // Add the handler for a new empty consent item | 
        
          | 412 |     function addNewHandler() { | 428 |     function addNewHandler() { | 
          
            
              | 413 |         $("#consentJSAddNew").on("click", function (e) { | 429 |         $("#cookieConsentedJSAddNew").on("click", function (e) { | 
        
          | 414 |             e.preventDefault(); | 430 |             e.preventDefault(); | 
          
            
              | 415 |             const currentLen = $('.consentJSItem').length; | 431 |             const currentLen = $('.cookieConsentedJSItem').length; | 
        
          | 416 |             const newItem = emptyConsentItem(); | 432 |             const newItem = emptyConsentItem(); | 
          
            
              | 417 |             const markup = createConsentJSItem(newItem, currentLen); | 433 |             const markup = createCookieConsentedJSItem(newItem, currentLen); | 
            
              | 418 |             $('#prefModal .modal-body #consentJSItems').append($(markup)); | 434 |             $('#prefModal .modal-body #cookieConsentedJSItems').append($(markup)); | 
        
          | 419 |             addExpandHandler(); | 435 |             addExpandHandler(); | 
        
          | 420 |             addCollapseHandler(); | 436 |             addCollapseHandler(); | 
        
          | 421 |             addConsentDeleteHandler(); | 437 |             addConsentDeleteHandler(); | 
        
          | 422 |         }); | 438 |         }); | 
        
          | 423 |     } | 439 |     } | 
        
          | 424 |  | 440 |  | 
          
            
              | 425 |     // Populate the consentJS modal, we also initialise any | 441 |     // Populate the cookieConsentedJS modal, we also initialise any | 
        
          | 426 |     // event handlers that are required. This function is added | 442 |     // event handlers that are required. This function is added | 
        
          | 427 |     // to the window object so we can call it if we are passed it's name | 443 |     // to the window object so we can call it if we are passed it's name | 
        
          | 428 |     // as a data-initiator attribute | 444 |     // as a data-initiator attribute | 
        
          | 429 |     // (e.g.) | 445 |     // (e.g.) | 
          
            
              | 430 |     // const f = 'populateConsentJS'; | 446 |     // const f = 'populateCookieConsentedJS'; | 
        
          | 431 |     // window[f](); | 447 |     // window[f](); | 
          
            
              | 432 |     window.populateConsentJS = function(el) { | 448 |     window.populateCookieConsentedJS = function(el) { | 
        
          | 433 |         let items = []; | 449 |         let items = []; | 
        
          | 434 |         let decoded = ''; | 450 |         let decoded = ''; | 
        
          | 435 |         if (el.value && el.value.length > 0) { | 451 |         if (el.value && el.value.length > 0) { | 
  
    | Lines 437-443
          $( document ).ready( function () {
      
      
        Link Here | 
        
          | 437 |                 decoded = atob(el.value); | 453 |                 decoded = atob(el.value); | 
        
          | 438 |             } catch (err) { | 454 |             } catch (err) { | 
        
          | 439 |                 throw (__( | 455 |                 throw (__( | 
          
            
              | 440 |                     'Unable to Base64 decode value stored in ConsentJS syspref: ' + | 456 |                     'Unable to Base64 decode value stored in CookieConsentedJS syspref: ' + | 
        
          | 441 |                     err.message | 457 |                     err.message | 
        
          | 442 |                 )); | 458 |                 )); | 
        
          | 443 |             } | 459 |             } | 
  
    | Lines 445-451
          $( document ).ready( function () {
      
      
        Link Here | 
        
          | 445 |                 items = JSON.parse(decoded); | 461 |                 items = JSON.parse(decoded); | 
        
          | 446 |             } catch (err) { | 462 |             } catch (err) { | 
        
          | 447 |                 throw (__( | 463 |                 throw (__( | 
          
            
              | 448 |                     'Unable to JSON parse decoded value stored in ConsentJS syspref: ' + | 464 |                     'Unable to JSON parse decoded value stored in CookieConsentedJS syspref: ' + | 
        
          | 449 |                     err.message | 465 |                     err.message | 
        
          | 450 |                 )); | 466 |                 )); | 
        
          | 451 |             } | 467 |             } | 
  
    | Lines 455-461
          $( document ).ready( function () {
      
      
        Link Here | 
        
          | 455 |         const pref_name = el.id.replace(/pref_/, ''); | 471 |         const pref_name = el.id.replace(/pref_/, ''); | 
        
          | 456 |         $('#saveModalPrefs').data('target', el.id); | 472 |         $('#saveModalPrefs').data('target', el.id); | 
        
          | 457 |         $('#prefModalLabel').text( pref_name ); | 473 |         $('#prefModalLabel').text( pref_name ); | 
          
            
              | 458 |         $('#prefModal .modal-body').html($('<div id="consentJSItems">' + validationWarning + markup + '</div><div><a href="#" id="consentJSAddNew">' + __('Add new code') + '</a></div>')); | 474 |         $('#prefModal .modal-body').html($('<div id="cookieConsentedJSItems">' + validationWarning + markup + '</div><div><a href="#" id="cookieConsentedJSAddNew">' + __('Add new code') + '</a></div>')); | 
        
          | 459 |         addExpandHandler(); | 475 |         addExpandHandler(); | 
        
          | 460 |         addCollapseHandler(); | 476 |         addCollapseHandler(); | 
        
          | 461 |         addNewHandler(); | 477 |         addNewHandler(); | 
  
    | Lines 467-476
          $( document ).ready( function () {
      
      
        Link Here | 
        
          | 467 |     // to the window object so we can call it if we are passed it's name | 483 |     // to the window object so we can call it if we are passed it's name | 
        
          | 468 |     // as a data-initiator attribute | 484 |     // as a data-initiator attribute | 
        
          | 469 |     // e.g. | 485 |     // e.g. | 
          
            
              | 470 |     // const f = 'prepareConsentJS'; | 486 |     // const f = 'prepareCookieConsentedJS'; | 
        
          | 471 |     // window[f](); | 487 |     // window[f](); | 
          
            
              | 472 |     window.prepareConsentJS = function () { | 488 |     window.prepareCookieConsentedJS = function () { | 
            
              | 473 |         const items = $('.consentJSItem'); | 489 |         const items = $('.cookieConsentedJSItem'); | 
        
          | 474 |         const invalid = []; | 490 |         const invalid = []; | 
        
          | 475 |         const valid = []; | 491 |         const valid = []; | 
        
          | 476 |         items.each(function () { | 492 |         items.each(function () { | 
  
    | Lines 523-532
          $( document ).ready( function () {
      
      
        Link Here | 
        
          | 523 |         }); | 539 |         }); | 
        
          | 524 |         // We failed validation | 540 |         // We failed validation | 
        
          | 525 |         if (invalid.length > 0) { | 541 |         if (invalid.length > 0) { | 
          
            
              | 526 |             $('#consentJSWarning').show(); | 542 |             $('#cookieConsentedJSWarning').show(); | 
        
          | 527 |             return false; | 543 |             return false; | 
        
          | 528 |         } | 544 |         } | 
          
            
              | 529 |         $('#consentJSWarning').hide(); | 545 |         $('#cookieConsentedJSWarning').hide(); | 
        
          | 530 |         if (valid.length === 0) { | 546 |         if (valid.length === 0) { | 
        
          | 531 |             return ''; | 547 |             return ''; | 
        
          | 532 |         } | 548 |         } | 
            
              | 533 | -  |  |  |