|
Lines 67-124
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 |
|
Lines 335-346
$( document ).ready( function () {
Link Here
|
| 335 |
'<input id="' + id + '" type="checkbox" class="' + className + '">'; |
346 |
'<input id="' + id + '" type="checkbox" class="' + className + '">'; |
| 336 |
} |
347 |
} |
| 337 |
|
348 |
|
| 338 |
// Create a consentJS item, correctly populated |
349 |
// Create a cookieConsentedJS item, correctly populated |
| 339 |
function createConsentJSItem(item, idx) { |
350 |
function createCookieConsentedJSItem(item, idx) { |
| 340 |
const id = 'ConsentJS_' + idx; |
351 |
const id = 'CookieConsentedJS_' + idx; |
| 341 |
const code = item.code && item.code.length > 0 ? atob(item.code) : ''; |
352 |
const code = item.code && item.code.length > 0 ? atob(item.code) : ''; |
| 342 |
const itemId = item.id && item.id.length > 0 ? item.id : ''; |
353 |
const itemId = item.id && item.id.length > 0 ? item.id : ''; |
| 343 |
return '<div id="' + id + '" class="consentJSItem" data-id="' + itemId + '">' + |
354 |
return '<div id="' + id + '" class="cookieConsentedJSItem" data-id="' + itemId + '">' + |
| 344 |
' <div class="consentRow">' + |
355 |
' <div class="consentRow">' + |
| 345 |
' <div class="consentItem">' + |
356 |
' <div class="consentItem">' + |
| 346 |
' <label class="required" for="name_' + id + '">' + __('Name') + ':</label>' + |
357 |
' <label class="required" for="name_' + id + '">' + __('Name') + ':</label>' + |
|
Lines 382-397
$( document ).ready( function () {
Link Here
|
| 382 |
'</div > '; |
393 |
'</div > '; |
| 383 |
} |
394 |
} |
| 384 |
|
395 |
|
| 385 |
// Return the markup for all consentJS items concatenated |
396 |
// Return the markup for all cookieConsentedJS items concatenated |
| 386 |
function populateConsentMarkup(items) { |
397 |
function populateConsentMarkup(items) { |
| 387 |
return items.reduce(function (acc, current, idx) { |
398 |
return items.reduce(function (acc, current, idx) { |
| 388 |
return acc + createConsentJSItem(current, idx); |
399 |
return acc + createCookieConsentedJSItem(current, idx); |
| 389 |
}, ''); |
400 |
}, ''); |
| 390 |
} |
401 |
} |
| 391 |
|
402 |
|
| 392 |
// Return the markup for a validation warning |
403 |
// Return the markup for a validation warning |
| 393 |
function populateValidationWarning() { |
404 |
function populateValidationWarning() { |
| 394 |
return '<div id="consentJSWarning" class="error" style="display:none;">' + __('You must complete all fields') + '</div>'; |
405 |
return '<div id="cookieConsentedJSWarning" class="error" style="display:none;">' + __('You must complete all fields') + '</div>'; |
| 395 |
} |
406 |
} |
| 396 |
|
407 |
|
| 397 |
// Return a new, empty consent item |
408 |
// Return a new, empty consent item |
|
Lines 410-435
$( document ).ready( function () {
Link Here
|
| 410 |
|
421 |
|
| 411 |
// Add the handler for a new empty consent item |
422 |
// Add the handler for a new empty consent item |
| 412 |
function addNewHandler() { |
423 |
function addNewHandler() { |
| 413 |
$("#consentJSAddNew").on("click", function (e) { |
424 |
$("#cookieConsentedJSAddNew").on("click", function (e) { |
| 414 |
e.preventDefault(); |
425 |
e.preventDefault(); |
| 415 |
const currentLen = $('.consentJSItem').length; |
426 |
const currentLen = $('.cookieConsentedJSItem').length; |
| 416 |
const newItem = emptyConsentItem(); |
427 |
const newItem = emptyConsentItem(); |
| 417 |
const markup = createConsentJSItem(newItem, currentLen); |
428 |
const markup = createCookieConsentedJSItem(newItem, currentLen); |
| 418 |
$('#prefModal .modal-body #consentJSItems').append($(markup)); |
429 |
$('#prefModal .modal-body #cookieConsentedJSItems').append($(markup)); |
| 419 |
addExpandHandler(); |
430 |
addExpandHandler(); |
| 420 |
addCollapseHandler(); |
431 |
addCollapseHandler(); |
| 421 |
addConsentDeleteHandler(); |
432 |
addConsentDeleteHandler(); |
| 422 |
}); |
433 |
}); |
| 423 |
} |
434 |
} |
| 424 |
|
435 |
|
| 425 |
// Populate the consentJS modal, we also initialise any |
436 |
// Populate the cookieConsentedJS modal, we also initialise any |
| 426 |
// event handlers that are required. This function is added |
437 |
// 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 |
438 |
// to the window object so we can call it if we are passed it's name |
| 428 |
// as a data-initiator attribute |
439 |
// as a data-initiator attribute |
| 429 |
// (e.g.) |
440 |
// (e.g.) |
| 430 |
// const f = 'populateConsentJS'; |
441 |
// const f = 'populateCookieConsentedJS'; |
| 431 |
// window[f](); |
442 |
// window[f](); |
| 432 |
window.populateConsentJS = function(el) { |
443 |
window.populateCookieConsentedJS = function(el) { |
| 433 |
let items = []; |
444 |
let items = []; |
| 434 |
let decoded = ''; |
445 |
let decoded = ''; |
| 435 |
if (el.value && el.value.length > 0) { |
446 |
if (el.value && el.value.length > 0) { |
|
Lines 437-443
$( document ).ready( function () {
Link Here
|
| 437 |
decoded = atob(el.value); |
448 |
decoded = atob(el.value); |
| 438 |
} catch (err) { |
449 |
} catch (err) { |
| 439 |
throw (__( |
450 |
throw (__( |
| 440 |
'Unable to Base64 decode value stored in ConsentJS syspref: ' + |
451 |
'Unable to Base64 decode value stored in CookieConsentedJS syspref: ' + |
| 441 |
err.message |
452 |
err.message |
| 442 |
)); |
453 |
)); |
| 443 |
} |
454 |
} |
|
Lines 445-451
$( document ).ready( function () {
Link Here
|
| 445 |
items = JSON.parse(decoded); |
456 |
items = JSON.parse(decoded); |
| 446 |
} catch (err) { |
457 |
} catch (err) { |
| 447 |
throw (__( |
458 |
throw (__( |
| 448 |
'Unable to JSON parse decoded value stored in ConsentJS syspref: ' + |
459 |
'Unable to JSON parse decoded value stored in CookieConsentedJS syspref: ' + |
| 449 |
err.message |
460 |
err.message |
| 450 |
)); |
461 |
)); |
| 451 |
} |
462 |
} |
|
Lines 455-461
$( document ).ready( function () {
Link Here
|
| 455 |
const pref_name = el.id.replace(/pref_/, ''); |
466 |
const pref_name = el.id.replace(/pref_/, ''); |
| 456 |
$('#saveModalPrefs').data('target', el.id); |
467 |
$('#saveModalPrefs').data('target', el.id); |
| 457 |
$('#prefModalLabel').text( pref_name ); |
468 |
$('#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>')); |
469 |
$('#prefModal .modal-body').html($('<div id="cookieConsentedJSItems">' + validationWarning + markup + '</div><div><a href="#" id="cookieConsentedJSAddNew">' + __('Add new code') + '</a></div>')); |
| 459 |
addExpandHandler(); |
470 |
addExpandHandler(); |
| 460 |
addCollapseHandler(); |
471 |
addCollapseHandler(); |
| 461 |
addNewHandler(); |
472 |
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 |
478 |
// to the window object so we can call it if we are passed it's name |
| 468 |
// as a data-initiator attribute |
479 |
// as a data-initiator attribute |
| 469 |
// e.g. |
480 |
// e.g. |
| 470 |
// const f = 'prepareConsentJS'; |
481 |
// const f = 'prepareCookieConsentedJS'; |
| 471 |
// window[f](); |
482 |
// window[f](); |
| 472 |
window.prepareConsentJS = function () { |
483 |
window.prepareCookieConsentedJS = function () { |
| 473 |
const items = $('.consentJSItem'); |
484 |
const items = $('.cookieConsentedJSItem'); |
| 474 |
const invalid = []; |
485 |
const invalid = []; |
| 475 |
const valid = []; |
486 |
const valid = []; |
| 476 |
items.each(function () { |
487 |
items.each(function () { |
|
Lines 523-532
$( document ).ready( function () {
Link Here
|
| 523 |
}); |
534 |
}); |
| 524 |
// We failed validation |
535 |
// We failed validation |
| 525 |
if (invalid.length > 0) { |
536 |
if (invalid.length > 0) { |
| 526 |
$('#consentJSWarning').show(); |
537 |
$('#cookieConsentedJSWarning').show(); |
| 527 |
return false; |
538 |
return false; |
| 528 |
} |
539 |
} |
| 529 |
$('#consentJSWarning').hide(); |
540 |
$('#cookieConsentedJSWarning').hide(); |
| 530 |
if (valid.length === 0) { |
541 |
if (valid.length === 0) { |
| 531 |
return ''; |
542 |
return ''; |
| 532 |
} |
543 |
} |
| 533 |
- |
|
|