PageSourceSearch

https://www.dhcare.co.uk/modules/custom/inv_views/js/visualizer.js?v=1.x.1

js dhcare.co.uk collected 2026-10-09 17:41:05 UTC 3,806 bytes, 110 lines download raw bytes

1/**
2 * @file
3 * Handles PIM visualizer iFrames, comparison bars, and menu accessibility.
4 */
5
6(function ($, Drupal, once) {
7  'use strict';
8
9  Drupal.behaviors.invViewsVisualizer = {
10    attach: function (context) {
11      // ✅ D10 FIX: once() cannot use 'document'. Use 'html' if context is document.
12      const el = (context === document || !context) ? document.documentElement : context;
13
14      // 1. Visualizer iFrame Logic.
15      const visualizerTriggers = once('visualizer-trigger', '.showVisualzer', el);
16      if (visualizerTriggers.length > 0) {
17        $(visualizerTriggers).on('click', function (e) {
18          e.preventDefault();
19          const $trigger = $(this);
20          const getURL = $trigger.attr('data');
21          
22          $('.visualizer-detail').addClass("hidden");
23
24          const screenheight = $(window).height() - 50; 
25          const $holder = $('#iframeHolder');
26
27          if (!$('#iframe').length) {
28            $holder.html(`<iframe id="iframe" src="${getURL}" width="100%" height="${screenheight}" frameborder="0"></iframe>`);
29          } else {
30            $('#iframe').attr('src', getURL);
31          }
32          
33          $('#visualizer').focus();
34        });
35      }
36
37      // 2. Product Comparison Bar Toggle.
38      const prodSelect = once('compare-toggle', '#prod-select', el);
39      if (prodSelect.length > 0) {
40        $(prodSelect).on('click', function () {
41          const $check = $('.icon-check_comparador');
42          const $footer = $('.footer-compare');
43          const $error = $('.errors-message');
44
45          if ($check.hasClass('open')) {
46            $footer.add($error).removeClass('open').addClass('close');
47          } else {
48            $footer.add($error).addClass('open').removeClass('close');
49          }
50        });
51      }
52
53      // 3. Initial state for Comparison Bar.
54      const compareBars = once('compare-init-state', '.footer-compare, .errors-message', el);
55      if (compareBars.length > 0) {
56        $(compareBars)
57          .removeClass('open')
58          .addClass('close');
59      }
60
61      // 4. Menu Accessibility (Title Attributes).
62      const menuItems = once('menu-title-fix', '.menu-item, .menus .products-categories .content li', el);
63      if (menuItems.length > 0) {
64        $(menuItems).each(function () {
65          const $link = $(this).find('a').first();
66          if ($link.length) {
67            const linkText = $link.text().trim();
68            $link.attr('title', linkText);
69          }
70        });
71      }
72    }
73  };
74})(jQuery, Drupal, once);
75
76/**
77 * Newsletter reCAPTCHA / Validation Callback.
78 */
79function onSubmit(token) {
80  const newsletters = document.querySelectorAll('.webform-submission-newsletter-add-form');
81  
82  newsletters.forEach(newsletter => {
83    const emailWrapper = newsletter.querySelector('.form-item-email');
84    if (!emailWrapper) return;
85
86    const emailInput = emailWrapper.querySelector('input');
87    const submitBtn = newsletter.querySelector('.webform-button--submit');
88    const value = emailInput.value.trim();
89
90    if (value !== '') {
91      if (validateEmail(value)) {
92        emailInput.style.border = "1px solid #d1d1d4";
93        emailWrapper.classList.replace('invalid-email', 'valid-email');
94        submitBtn.click();
95      } else {
96        emailInput.style.border = "1px solid #E20D0D";
97        emailWrapper.classList.replace('valid-email', 'invalid-email');
98      }
99    } else {
100      emailInput.style.border = "1px solid #d1d1d4";
101      emailWrapper.classList.remove('invalid-email', 'valid-email');
102    }
103  });
104  return false;
105}
106
107function validateEmail(email) {
108  const re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
109  return re.test(String(email).toLowerCase());
110}

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.