PageSourceSearch

https://www.pingdom.com/wp-content/themes/pingdom-2018/blocks/modal/modal.js?ver=1782376030

js pingdom.com collected 2026-09-24 06:23:44 UTC 3,093 bytes, 126 lines download raw bytes

1(function () {
2  const COOKIE_PREFIX = "modal_dont_show";
3
4  function setCookie(name, value, hours) {
5    let expires = "";
6
7    if (typeof hours === "number" && hours > 0) {
8      const date = new Date();
9      date.setTime(date.getTime() + hours * 60 * 60 * 1000);
10      expires = "; expires=" + date.toUTCString();
11    } else if (hours < 0) {
12      expires = "; expires=Thu, 01 Jan 1970 00:00:00 UTC";
13    }
14
15    document.cookie = name + "=" + (value || "") + expires + "; path=/";
16  }
17
18  function getCookie(name) {
19    const nameEQ = name + "=";
20    const cookies = document.cookie.split(";");
21
22    for (let i = 0; i < cookies.length; i++) {
23      const cookie = cookies[i].trim();
24      if (cookie.indexOf(nameEQ) === 0) {
25        return cookie.substring(nameEQ.length);
26      }
27    }
28
29    return null;
30  }
31
32  function cookieNameFor(selector) {
33    return COOKIE_PREFIX + "_" + selector.replace(/[^a-z0-9]/gi, "_");
34  }
35
36  function hideModal(modal) {
37    modal.style.display = "none";
38    modal.setAttribute("aria-hidden", "true");
39  }
40
41  function getModalElement() {
42    return document.querySelector(".modal");
43  }
44
45  function getCloseButtonElement(modal) {
46    return modal.querySelector(".modal-close, .global-modal__close");
47  }
48
49  function getBackdropElement(modal) {
50    return modal.querySelector(".modal-backdrop, .global-modal__backdrop");
51  }
52
53  function getCheckboxElement(modal) {
54    return modal.querySelector('input[name="global-modal-no-show"]');
55  }
56
57  function getDelay(modal) {
58    return Number(modal.getAttribute("data-delay")) || 0;
59  }
60
61  function handleClose(modal, cookieName) {
62    const checkbox = getCheckboxElement(modal);
63
64    if (checkbox && checkbox.checked) {
65      setCookie(cookieName, "1", 24);
66    }
67
68    hideModal(modal);
69  }
70
71  function initializeModal() {
72
73    const modal = getModalElement();
74
75    if (!modal) return;
76
77    const selector =
78      modal.getAttribute("data-selector") || "#global-modal";
79
80    const delay = getDelay(modal);
81
82    if (delay <= 0) return;
83
84    const cookieName = cookieNameFor(selector);
85
86    if (getCookie(cookieName)) return;
87
88    setTimeout(function () {
89      modal.style.display = "flex";
90      modal.setAttribute("aria-hidden", "false");
91    }, delay * 1000);
92
93    const closeButton = getCloseButtonElement(modal);
94    const backdrop = getBackdropElement(modal);
95    const checkbox = getCheckboxElement(modal);
96
97    if (closeButton) {
98      closeButton.addEventListener("click", function (event) {
99        event.preventDefault();
100        handleClose(modal, cookieName);
101      });
102    }
103
104    if (backdrop) {
105      backdrop.addEventListener("click", function () {
106        handleClose(modal, cookieName);
107      });
108    }
109
110    if (checkbox) {
111      checkbox.addEventListener("change", function () {
112        if (checkbox.checked) {
113          setCookie(cookieName, "1", 24);
114        } else {
115          setCookie(cookieName, "", -1);
116        }
117      });
118    }
119  }
120
121  if (document.readyState === "loading") {
122    document.addEventListener("DOMContentLoaded", initializeModal);
123  } else {
124    initializeModal();
125  }
126})();

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.