1/* global Drupal */ 2(function ($) { // Avoid leaking variables 3 4 /** 5 * Add CSRF token to link 6 * 7 * @param {HTMLAnchorElement} button Link 8 * @param {string} token Token 9 */ 10 const addCSRFToken = function (button, token) { 11 const form = document.createElement('form'); 12 form.action = button.href; 13 form.method = 'POST'; 14 form.classList.add('h5p-hidden-form'); 15 16 const inputToken = document.createElement('input'); 17 inputToken.name = '_token'; 18 inputToken.type = 'hidden'; 19 inputToken.value = token; 20 form.appendChild(inputToken); 21 22 button.parentNode.appendChild(form); 23 24 button.href = '#' + button.href.match(/([^\/])+$/i)[0]; 25 button.addEventListener('click', function (e) { 26 form.submit(); 27 e.preventDefault(); 28 }); 29 } 30 31 Drupal.behaviors.h5pContentHub = { 32 attach: function (context, settings) { 33 if (typeof context.getElementsByClassName === "function") { 34 const buttons = context.getElementsByClassName('h5p-content-hub-button'); 35 for (let i = 0; i < buttons.length; i++) { 36 if (buttons[i].classList.contains('processed')) { 37 continue; // Skip 38 } 39 buttons[i].classList.add('processed'); 40 addCSRFToken(buttons[i], settings.h5pContentHub.token); 41 } 42 } 43 } 44 }; 45 46})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.