PageSourceSearch

https://www.lifeinsuranceinternational.com/wp-content/themes/goodl…/assets/js/modules/toggleActiveClass.js

js lifeinsuranceinternational.com collected 2026-09-25 04:05:22 UTC 2,624 bytes, 85 lines download raw bytes

1export default function toggleActiveClass(
2  btnToToggle,
3  containerToToggle,
4  eventTrack = false,
5  targetToTrack,
6  redirect = false,
7  target
8) {
9  btnToToggle.addEventListener("click", (event) => {
10    event.stopPropagation(); // Prevent the click event from propagating to the document
11    event.preventDefault(); // prevent default event
12    // Toggle the 'active' class for the button and container
13
14    if (!event.target.classList.contains(targetToTrack)) {
15      btnToToggle.classList.toggle("active");
16      containerToToggle.classList.toggle("active");
17
18      if (
19        event.target.tagName === "A" &&
20        redirect &&
21        !event.target.classList.contains("copy-link") &&
22        event.target.href
23      ) {
24        if (target === "blank") {
25          window.open(event.target.href, "_blank");
26        } else {
27          window.location = event.target.href;
28        }
29      }
30
31      const copyLinkButton = containerToToggle.querySelector(".copy-link");
32
33      if (
34        !containerToToggle.classList.contains("active") &&
35        copyLinkButton.innerText === "Link copied"
36      ) {
37        copyLinkButton.innerText = "Copy Link";
38        copyLinkButton.classList.remove("active");
39      }
40    }
41
42    if (eventTrack) {
43      // Handle additional functionality when eventTrack is enabled
44      if (
45        targetToTrack === "copy-link" &&
46        event.target.innerText !== "Link copied"
47      ) {
48        if (event.target.href) {
49          navigator.clipboard
50            .writeText(event.target.href)
51            .then(() => {
52              event.target.innerText = "Link copied";
53              event.target.classList.add("active");
54            })
55            .catch((error) => console.error("Error copying link:", error));
56        }
57      }
58    } else {
59      btnToToggle.classList.toggle("active");
60      containerToToggle.classList.toggle("active");
61    }
62  });
63
64  // Add a click event listener to the document to close the container when clicking outside
65  document.addEventListener("click", (docEvent) => {
66    if (
67      eventTrack &&
68      targetToTrack &&
69      docEvent.target !== btnToToggle &&
70      !docEvent.target.classList.contains(targetToTrack)
71    ) {
72      containerToToggle.classList.remove("active");
73      btnToToggle.classList.remove("active");
74      const copyLinkButton = containerToToggle.querySelector(".copy-link");
75
76      if (
77        !containerToToggle.classList.contains("active") &&
78        copyLinkButton.innerText === "Link copied"
79      ) {
80        copyLinkButton.innerText = "Copy Link";
81        copyLinkButton.classList.remove("active");
82      }
83    }
84  });
85}

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.