PageSourceSearch

https://various-shop.com/wp-content/plugins/garanlabs-eu-guarantee…/assets/js/eggl-frontend.js?ver=1790748697

js various-shop.com collected 2026-10-04 12:20:35 UTC 3,883 bytes, 105 lines download raw bytes

1// EU Guarantee Notice & GARAN Labels
2// Front-end enhancement: opens the tabbed modal with the official graphics.
3// Everything renders server-side; this only toggles visibility. Loaded via
4// wp_enqueue_script (no inline scripts).
5(function () {
6  var lastTrigger = null;
7
8  function openModal(modal, tab) {
9    if (!modal) return;
10    modal.removeAttribute('hidden');
11    document.body.classList.add('eggl-modal-open');
12    if (tab) switchTab(modal, tab);
13    var closeBtn = modal.querySelector('.eggl-modal__close');
14    if (closeBtn) closeBtn.focus();
15  }
16
17  function closeModal(modal) {
18    if (!modal) return;
19    modal.setAttribute('hidden', '');
20    document.body.classList.remove('eggl-modal-open');
21    if (lastTrigger) { lastTrigger.focus(); lastTrigger = null; }
22  }
23
24  function switchTab(modal, tab) {
25    var buttons = modal.querySelectorAll('[data-eggl-tab-btn]');
26    var panels = modal.querySelectorAll('[data-eggl-panel]');
27    buttons.forEach(function (btn) {
28      var active = btn.getAttribute('data-eggl-tab-btn') === tab;
29      btn.classList.toggle('is-active', active);
30      btn.setAttribute('aria-selected', active ? 'true' : 'false');
31    });
32    panels.forEach(function (panel) {
33      if (panel.getAttribute('data-eggl-panel') === tab) panel.removeAttribute('hidden');
34      else panel.setAttribute('hidden', '');
35    });
36  }
37
38  function toggleNested(trigger) {
39    var panel = document.getElementById(trigger.getAttribute('data-eggl-toggle'));
40    if (!panel) return;
41    var expanded = panel.hasAttribute('hidden');
42    if (expanded) panel.removeAttribute('hidden');
43    else panel.setAttribute('hidden', '');
44    trigger.setAttribute('aria-expanded', expanded ? 'true' : 'false');
45  }
46
47  document.addEventListener('click', function (e) {
48    var toggle = e.target.closest && e.target.closest('[data-eggl-toggle]');
49    if (toggle) {
50      toggleNested(toggle);
51      return;
52    }
53
54    var opener = e.target.closest && e.target.closest('[data-eggl-open]');
55    if (opener) {
56      var modal = document.getElementById(opener.getAttribute('data-eggl-open'));
57      lastTrigger = opener;
58      openModal(modal, opener.getAttribute('data-eggl-tab'));
59      return;
60    }
61
62    var closer = e.target.closest && e.target.closest('[data-eggl-close]');
63    if (closer) {
64      closeModal(closer.closest('[data-eggl-modal]'));
65      return;
66    }
67
68    var tabBtn = e.target.closest && e.target.closest('[data-eggl-tab-btn]');
69    if (tabBtn) {
70      var wrap = tabBtn.closest('[data-eggl-modal]');
71      if (wrap) switchTab(wrap, tabBtn.getAttribute('data-eggl-tab-btn'));
72    }
73  });
74
75  // Variable products: swap the GARAN label to the chosen variation's (see
76  // EGGL_Frontend::render_garan()). WooCommerce fires these as jQuery events.
77  function showGaran(form, variationId) {
78    var scope = (form.closest && form.closest('.product')) || document;
79    var wrap = scope.querySelector('[data-eggl-garan-variations]') || document.querySelector('[data-eggl-garan-variations]');
80    if (!wrap) return;
81    var current = wrap.querySelector('[data-eggl-garan-current]');
82    var tpl = variationId
83      ? wrap.querySelector('template[data-eggl-garan-variation="' + variationId + '"]')
84      : null;
85    if (!tpl) tpl = wrap.querySelector('template[data-eggl-garan-default]');
86    if (!current || !tpl) return;
87    current.innerHTML = tpl.innerHTML;
88  }
89
90  if (window.jQuery) {
91    window.jQuery(document)
92      .on('found_variation', '.variations_form', function (e, variation) {
93        showGaran(this, variation && variation.variation_id);
94      })
95      .on('reset_data', '.variations_form', function () {
96        showGaran(this, 0);
97      });
98  }
99
100  document.addEventListener('keydown', function (e) {
101    if (e.key !== 'Escape') return;
102    var open = document.querySelector('[data-eggl-modal]:not([hidden])');
103    if (open) closeModal(open);
104  });
105})();

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.