PageSourceSearch

https://www.justformen.com/sites/g/files/sgirzt191/files/js/optimi…0RdPwwgzYzYMCiIJ-Sh0P3rMD1PfCgcJ0.js?tlee0m

js justformen.com collected 2026-09-26 02:11:39 UTC 8,321 bytes, 148 lines download raw bytes

1/* Source and licensing information for the line(s) below can be found at https://prod.justformen.com/themes/custom/jfm/js/popup.js. */
2(function ($) {
3    Drupal.behaviors.popUp = {
4        attach: function (context, settings) {
5            $(document).ready(function () {
6                /******* Popup Display Handler ********/
7                // Get the path of the current page
8                let path = window.location.pathname;
9                // Generate a unique name for the cookie
10                let popupcookieName = "popupClose_" + path.replace(/\//g, "");
11                let popupCountcookieName = "popupCount_" + path.replace(/\//g, "");
12                // Get intial cookie value can be blank too.
13                let popupcookieValue = document.cookie.replace(new RegExp("(?:(?:^|.*;\\s*)" + popupcookieName + "\\s*\\=\\s*([^;]*).*$)|^.*$"), "$1");
14                let popupcookieCountValue = document.cookie.replace(new RegExp("(?:(?:^|.*;\\s*)" + popupCountcookieName + "\\s*\\=\\s*([^;]*).*$)|^.*$"), "$1");
15                // Show popup only if user have not closed it twice within a cookie period.
16                if (popupcookieValue < 2 &&  popupcookieCountValue < 2 ) {
17                    let delay = ($('.popup-container').data('delay')) * 1000;
18                    setTimeout(function () {
19                        $('.popup-container').show();
20                        $('.popup_overlay').show();
21                        // Set initial cookie value if it was blank.
22                        if (popupcookieValue < 1) {
23                            // Set cookie.
24                            document.cookie = popupcookieName + "=0; expires=Fri, 31 Dec 9999 23:59:59 GMT; path=/";
25                        }
26                        popupcookieCountValue++;
27                        document.cookie = popupCountcookieName + "=" + popupcookieCountValue + "; expires=Fri, 31 Dec 9999 23:59:59 GMT; path=/";
28                    }, delay);
29                    /******* Popup Close Handler
30                     * There are two ways to close popup for now, either click on close button
31                     * or click anywhere outside popup, except menu ********/
32                    $(".popup_overlay").add(".popup-close-btn").on("click", function () {
33                        $('.popup_overlay').hide();
34                        $('.popup-container').hide();
35                        // Get cookie value for increasing it.
36                        popupcookieValue = document.cookie.replace(new RegExp("(?:(?:^|.*;\\s*)" + popupcookieName + "\\s*\\=\\s*([^;]*).*$)|^.*$"), "$1");
37                        // Increasing Cookie Value.
38                        popupcookieValue++;
39                        // Set cookie to Count number of time a popup has been closed.
40                        document.cookie = popupcookieName + "=" + popupcookieValue + "; expires=Fri, 31 Dec 9999 23:59:59 GMT; path=/";
41                    });
42                }
43
44                let $whereToBuyCta = drupalSettings.combe_translations.where_to_buy_cta;
45                let $whereToBuyOnline = drupalSettings.combe_translations.where_to_buy_online;
46                let $whereToInStore = drupalSettings.combe_translations.where_to_in_store;
47
48                if($whereToBuyCta == null) {
49                    jQuery('.where-to-buy .where-to-buy__two-col-row__right-col').css('display','none');
50                } else {
51                    jQuery('.where-to-buy .where-to-buy__two-col-row__right-col').css('display','block');
52                }
53
54                if($whereToBuyOnline == null) {
55                    jQuery('.where-to-buy .quicktabs-wrapper ul li:first-child').attr('aria-selected',false);
56                    jQuery('.where-to-buy .quicktabs-wrapper ul li:last-child').attr('aria-selected',true);
57                    jQuery('.where-to-buy .quicktabs-wrapper ul li:last-child').addClass("active");
58                    jQuery('.where-to-buy #quicktabs-tabpage-where_to_buy_tabs-0').addClass("quicktabs-hide");
59                    jQuery('.where-to-buy #quicktabs-tabpage-where_to_buy_tabs-1').removeClass("quicktabs-hide");
60                    jQuery('.where-to-buy .quicktabs-tabs .buy-online, #quicktabs-tabpage-where_to_buy_tabs-0').hide();
61                } else {
62                    jQuery('.where-to-buy .quicktabs-tabs .buy-online, #quicktabs-tabpage-where_to_buy_tabs-0').show();
63                }
64
65                if($whereToInStore == null) {
66                    jQuery('.where-to-buy .quicktabs-wrapper ul li:last-child').attr('aria-selected',false);
67                    jQuery('.where-to-buy .quicktabs-wrapper ul li:first-child').attr('aria-selected',true);
68                    jQuery('.where-to-buy .quicktabs-wrapper ul li:first-child').addClass("active");
69                    jQuery('.where-to-buy #quicktabs-tabpage-where_to_buy_tabs-1').addClass("quicktabs-hide");
70                    jQuery('.where-to-buy #quicktabs-tabpage-where_to_buy_tabs-0').removeClass("quicktabs-hide");
71                    jQuery('.where-to-buy .quicktabs-tabs .in-store, #quicktabs-tab-where_to_buy_tabs-1').hide();
72                } else {
73                    jQuery('.where-to-buy .quicktabs-tabs .in-store, #quicktabs-tab-where_to_buy_tabs-1').show();
74                }
75
76            })
77
78            /******* Popup with Ping Functionality ********/
79            const LAST_PING_KEY = 'lastPing';
80            const PING_INTERVAL = 2000;
81            const TIMEOUT_THRESHOLD = 3000;
82
83            // Write current timestamp as ping
84            function setPing() {
85                localStorage.setItem(LAST_PING_KEY, Date.now());
86            }
87
88            // Read last ping
89            function getLastPing() {
90                return parseInt(localStorage.getItem(LAST_PING_KEY) || 0);
91            }
92
93            // Run on page load
94            (function () {
95                const now = Date.now();
96                const lastPing = getLastPing();
97
98                const isNewSession = !lastPing || now - lastPing > TIMEOUT_THRESHOLD;
99
100                if (isNewSession) {
101                    // Remove popupShown if it was set earlier
102                    localStorage.removeItem('popupShown');
103                }
104
105                // Set up pinging while this tab is open
106                const pingInterval = setInterval(setPing, PING_INTERVAL);
107
108                window.addEventListener('beforeunload', () => clearInterval(pingInterval));
109
110                if (typeof(Storage) !== "undefined") {
111                    const popupKey = "popupClosedAt";
112                    const now = Date.now();
113                    const lastClosed = localStorage.getItem(popupKey);
114                    var oneDay = 86400000;
115
116                    // If never closed before or 24 hours passed, show popup
117                    if (!lastClosed || (now - parseInt(lastClosed, 10)) >= oneDay) {
118                        let delay = ($('.popup-wrapper').data('delay')) * 1000 || 0;
119
120                        setTimeout(function () {
121                            $('.popup-wrapper').show();
122                            $('.popup_overlay_new').show();
123
124                            // Auto-hide after 10 seconds if not closed
125                            const autoHide = setTimeout(function () {
126                                $('.popup_overlay_new').hide();
127                                $('.popup-wrapper').hide();
128                                // Do not set localStorage, so popup will show again on refresh
129                            }, 10000);
130
131                            // Popup will only close on button click or overlay click
132                            $(".popup-wrapper button, .popup_overlay_new").on("click", function () {
133                                clearTimeout(autoHide);
134                                $('.popup_overlay_new').hide();
135                                $('.popup-wrapper').hide();
136                                // Save current timestamp
137                                localStorage.setItem(popupKey, Date.now().toString());
138                            });
139                        }, delay);
140                    }
141                }
142
143            })();
144        }
145    };
146})(jQuery);
147
148/* Source and licensing information for the above line(s) can be found at https://prod.justformen.com/themes/custom/jfm/js/popup.js. */

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.