1Drupal.behaviors.toybox_control = { 2 // eslint-disable-next-line no-unused-vars 3 attach: function (context, settings) { 4 this.initSelects(context); 5 this.initExpirationTags(context); 6 this.initHiders(context); 7 }, 8 // Finding items that has an expiration date, and set a helper class if 9 // they are expired. 10 // We do this in JS, to avoid any cache issues. 11 // Setting the target date to tomorrow, as that is the logic in the view. 12 initExpirationTags: function (context) { 13 const targetDate = new Date(); 14 targetDate.setDate(targetDate.getDate() - 1); 15 targetDate.setHours(23, 59); 16 const targetDateTimestamp = Math.floor(targetDate.getTime() / 1000); 17 context.querySelectorAll("[data-expiration-date]").forEach(item => { 18 const expirationDate = parseInt(item.getAttribute("data-expiration-date"), 10); 19 if (expirationDate < targetDateTimestamp) { 20 item.classList.add("is-expired"); 21 } 22 }); 23 }, 24 // Looping through .js-control-hide elements and toggleHide() on click. 25 initHiders: function (context) { 26 const that = this; 27 context.querySelectorAll(".js-control-hide:not(.is-initialized)").forEach(element => { 28 element.classList.add("is-initialized"); 29 element.addEventListener("click", event => { 30 event.preventDefault(); 31 that.toggleHide(element); 32 }); 33 }); 34 }, 35 toggleHide: function (element) { 36 const hideSelector = element.getAttribute("data-hide-selector"); 37 if (!hideSelector) { 38 return; 39 } 40 41 // Looping through our items and toggling their hidden state. 42 document.querySelectorAll(hideSelector).forEach(item => { 43 item.classList.toggle("is-hidden"); 44 }); 45 }, 46 // Looping through .js-control-select elements and chooseSelect() on click. 47 initSelects: function (context) { 48 const that = this; 49 context.querySelectorAll(".js-control-select:not(.is-initialized)").forEach(item => { 50 item.classList.add("is-initialized"); 51 const select = item.querySelector("select"); 52 const label = item.querySelector("span"); 53 select.addEventListener("change", () => { 54 that.chooseSelect(select, label); 55 }); 56 }); 57 }, 58 chooseSelect: function (select, label) { 59 const selectedOption = select.options[select.selectedIndex]; 60 let labelText = "- Vælg -"; 61 if (selectedOption) { 62 labelText = "text" in selectedOption ? selectedOption.text : labelText; 63 if ("value" in selectedOption) { 64 label.classList.remove("is-placeholder"); 65 } else { 66 label.classList.add("is-placeholder"); 67 } 68 } 69 label.innerHTML = labelText; 70 } 71}; 72//# sourceMappingURL=toybox.control.js.map
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.