PageSourceSearch

https://www.sanctuary.co.uk/themes/custom/sanctuary/assets/js/module_override/simple_popup_blocks.js?v=10.6.12

js sanctuary.co.uk collected 2026-09-28 08:49:40 UTC 12,493 bytes, 399 lines download raw bytes

1
2/*
3 * sanctuary_theme
4 * Sanctuary main theme.
5 * @version v1.0.0
6 */
7"use strict";
8
9(function ($, Drupal, once) {
10  'use strict';
11
12  Drupal.behaviors.simplePopupBlocks = {
13    attach: function attach(context, settings) {
14      // Global variables
15      var popup_settings = drupalSettings.simple_popup_blocks.settings,
16          _html = document.documentElement,
17          windowWidth = $(window).width();
18      $.each(popup_settings, function (index, values) {
19        // No popup when the window width is less than the trigger width.
20        if (windowWidth < values.trigger_width) {
21          return null;
22        }
23
24        ; // Declaring variable inside foreach - so it will not global.
25
26        var modal_class = '',
27            block_id = values.identifier,
28            visit_counts_arr = values.visit_counts.split(','),
29            allow_cookie = true,
30            read_cookie = '',
31            cookie_val = 1,
32            cookie_days = values.cookie_expiry || 100,
33            match = 0,
34            css_identity = '',
35            spb_popup_id = '',
36            modal_close_class = '',
37            modal_minimize_class = '',
38            modal_minimized_class = '',
39            layout_class = '',
40            class_exists = false,
41            delays = '',
42            browser_close_trigger = true,
43            use_time_frequency = values.use_time_frequency,
44            time_frequency = values.time_frequency,
45            time_frequency_cookie = 0,
46            next_popup = 0,
47            current_timestamp = 0,
48            show_minimized_button = values.show_minimized_button,
49            show_model = true; // Always show popup, so prevent from creating cookie
50
51        if (visit_counts_arr.length == 1 && visit_counts_arr[0] == 0 && use_time_frequency == 0) {
52          allow_cookie = false;
53        } // Check to see if the block exists in the current page.
54
55
56        var element = document.getElementById(block_id);
57
58        if (typeof element != 'undefined' && element != null) {
59          // Creating cookie
60          if (allow_cookie == true) {
61            if (use_time_frequency == 0) {
62              read_cookie = readCookie('spb_' + block_id);
63
64              if (read_cookie) {
65                cookie_val = +read_cookie + 1;
66                createCookie('spb_' + block_id, cookie_val, 100);
67              } else {
68                createCookie('spb_' + block_id, cookie_val, 100);
69              } // Match cookie
70
71
72              cookie_val = cookie_val.toString();
73              match = $.inArray(cookie_val, visit_counts_arr);
74
75              if (match === -1) {
76                show_model = false;
77              }
78            } else {
79              time_frequency_cookie = readCookie('spb_time' + block_id);
80              current_timestamp = Math.floor(Date.now() / 1000);
81              next_popup = current_timestamp + parseInt(time_frequency, 10);
82
83              if (time_frequency_cookie) {
84                // If current_timestamp is greater than cookie time show the popup.
85                if (current_timestamp >= time_frequency_cookie) {
86                  match = 1;
87                } // This should allow the time frequency to be adjusted down after
88                // the cookie has been set.
89                else if (next_popup <= time_frequency_cookie) {
90                  match = 1;
91                } else {
92                  match = -1;
93                  show_model = false;
94                } // Create new cookie for popup.
95
96
97                if (match === 1) {
98                  createCookie('spb_time' + block_id, next_popup, 100);
99                }
100              } else {
101                createCookie('spb_time' + block_id, next_popup, 100);
102              }
103            }
104          }
105        } // Set css selector
106
107
108        css_identity = '.';
109
110        if (values.css_selector == 1) {
111          css_identity = '#';
112        } // Assign dynamic css classes
113
114
115        spb_popup_id = 'spb-' + block_id;
116        modal_class = block_id + '-modal';
117        modal_close_class = block_id + '-modal-close';
118        modal_minimize_class = block_id + '-modal-minimize';
119        modal_minimized_class = block_id + '-modal-minimized';
120        layout_class = '.' + modal_class + ' .spb-popup-main-wrapper'; // Wrap arround elements
121
122        once('wrap-arround', css_identity + block_id).forEach(function (elem) {
123          $(elem).wrap($('<div class="' + modal_class + '"></div>'));
124        }); // Hide the popup initially
125
126        once('hide-popup', '.' + modal_class).forEach(function (elem) {
127          $(elem).hide();
128        }); // Wrap remaining elements
129
130        if ($(css_identity + block_id).closest('.spb-popup-main-wrapper').length) {
131          return;
132        }
133
134        $(css_identity + block_id).wrap($('<div class="spb-popup-main-wrapper"></div>'));
135        $('.' + modal_class).wrap('<div id="' + spb_popup_id + '" class="simple-popup-blocks-global"></div>');
136        $(css_identity + block_id).after($('<div class="spb-controls"></div>')); // Skip code for non popup pages.
137
138        class_exists = $('#' + spb_popup_id).hasClass('simple-popup-blocks-global');
139
140        if (!class_exists) {
141          return true;
142        } // Minimize button wrap
143
144
145        if (values.minimize === "1") {
146          $("#" + spb_popup_id + " .spb-controls").prepend($('<button type="button" aria-label="Dismiss modal" class="' + modal_minimize_class + ' spb_minimize">&minus;</button>'));
147          $('.' + modal_class).before($('<button type="button" aria-label="Open modal" class="' + modal_minimized_class + ' spb_minimized">&plus;</button>'));
148        } // Close button wrap
149
150
151        if (values.close == 1) {
152          $("#" + spb_popup_id + " .spb-controls").prepend($('<button type="button" aria-label="Close modal" class="' + modal_close_class + ' spb_close">&times;</button>'));
153        } // Overlay
154
155
156        if (values.overlay == 1) {
157          $('.' + modal_class).addClass('spb_overlay');
158        } // Inject layout class.
159
160
161        switch (values.layout) {
162          // Top left.
163          case '0':
164            $(layout_class).addClass('spb_top_left');
165            $(layout_class).css({
166              'width': values.width
167            });
168            break;
169          // Top right.
170
171          case '1':
172            $(layout_class).addClass('spb_top_right');
173            $(layout_class).css({
174              'width': values.width
175            });
176            break;
177          // Bottom left.
178
179          case '2':
180            $(layout_class).addClass('spb_bottom_left');
181            $(layout_class).css({
182              'width': values.width
183            });
184            break;
185          // Bottom right.
186
187          case '3':
188            $(layout_class).addClass('spb_bottom_right');
189            $(layout_class).css({
190              'width': values.width
191            });
192            break;
193          // Center.
194
195          case '4':
196            $(layout_class).addClass('spb_center');
197            $(layout_class).css({
198              'width': values.width,
199              'margin-left': -values.width / 2
200            });
201            break;
202          // Top Center.
203
204          case '5':
205            $(layout_class).addClass('spb_top_center');
206            $(layout_class).css({
207              'width': values.width
208            });
209            break;
210          // Top bar.
211
212          case '6':
213            $(layout_class).addClass('spb_top_bar');
214            $(layout_class).css({});
215            break;
216          // Right bar.
217
218          case '7':
219            $(layout_class).addClass('spb_bottom_bar');
220            $(layout_class).css({});
221            break;
222          // Bottom bar.
223
224          case '8':
225            $(layout_class).addClass('spb_left_bar');
226            $(layout_class).css({
227              'width': values.width
228            });
229            break;
230          // Right bar.
231
232          case '9':
233            $(layout_class).addClass('spb_right_bar');
234            $(layout_class).css({
235              'width': values.width
236            });
237            break;
238        }
239
240        if (show_model === true) {
241          // Automatic trigger with delay
242          if (values.trigger_method == 0 && values.delay > 0) {
243            delays = values.delay * 1000;
244            $('.' + modal_class).delay(delays).fadeIn('slow');
245
246            if (values.overlay == 1) {
247              setTimeout(stopTheScroll, delays);
248            }
249          } // Automatic trigger without delay
250          else if (values.trigger_method == 0) {
251            $('.' + modal_class).show();
252            $(css_identity + block_id).show();
253
254            if (values.overlay == 1) {
255              stopTheScroll();
256            }
257          } // Manual trigger
258          else if (values.trigger_method == 1) {
259            $(document).on('click', values.trigger_selector, function (e) {
260              $('.' + modal_class).show();
261              $(css_identity + block_id).show();
262
263              if (values.overlay == 1) {
264                stopTheScroll();
265              }
266
267              return false;
268            });
269          } // Browser close trigger
270          else if (values.trigger_method == 2) {
271            $(_html).mouseleave(function (e) {
272              // Trigger only when mouse leave on top view port
273              if (e.clientY > 20) {
274                return;
275              } // Trigger only once per page
276
277
278              if (!browser_close_trigger) {
279                return;
280              }
281
282              browser_close_trigger = false;
283              $('.' + modal_class).show();
284              $(css_identity + block_id).show();
285
286              if (values.overlay == 1) {
287                stopTheScroll();
288              }
289            });
290          }
291        } // Trigger for close button click
292
293
294        $('.' + modal_close_class).click(function () {
295          $('.' + modal_class).hide();
296          startTheScroll();
297        }); // Custom: trigger focus trap
298
299        $('.' + modal_close_class).on('keydown', function (e) {
300          var keyCode = e.keyCode || e.which;
301
302          if (keyCode === 9 && !e.shiftKey) {
303            e.preventDefault();
304            $('#edit-keywords').focus();
305          }
306        }); // Trigger for minimize button click
307
308        $('.' + modal_minimize_class).click(function () {
309          $('.' + modal_class).hide();
310          startTheScroll();
311          $('.' + modal_minimized_class).show();
312        }); // Trigger for minimized button click
313
314        $('.' + modal_minimized_class).click(function () {
315          $('.' + modal_class).show();
316          $(css_identity + block_id).show();
317
318          if (values.overlay == 1) {
319            stopTheScroll();
320          } // Hide the minimized button.
321
322
323          if (show_minimized_button == 0) {
324            $('.' + modal_minimized_class).hide();
325          }
326        }); // Trigger for ESC button click
327
328        if (values.enable_escape == 1) {
329          $(document).keyup(function (e) {
330            if (e.keyCode == 27) {
331              // Escape key maps to keycode `27`.
332              $('.' + modal_class).hide();
333              startTheScroll();
334              $('.' + modal_minimized_class).show();
335            }
336          });
337        } // Hide the minimized button.
338
339
340        if (show_minimized_button == 0) {
341          $('.' + modal_minimized_class).hide();
342        }
343      }); // Foreach end.
344    }
345  }; // document.ready end.
346  // Remove the scrolling while overlay active
347
348  function stopTheScroll() {
349    $('body').css({
350      'overflow': 'hidden'
351    });
352    $('.simple-popup-blocks-global input:text').focus();
353  } // Enable the scrolling while overlay inactive
354
355
356  function startTheScroll() {
357    $('body').css({
358      'overflow': ''
359    });
360  } // Creating cookie
361
362
363  function createCookie(name, value, days) {
364    if (days > 0) {
365      var date = new Date();
366      date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
367      var expires = '; expires=' + date.toGMTString();
368    } else {
369      var expires = '';
370    }
371
372    document.cookie = name + '=' + value + expires + '; path=/';
373  } // Reading cookie
374
375
376  function readCookie(name) {
377    var nameEQ = name + '=';
378    var ca = document.cookie.split(';');
379
380    for (var i = 0; i < ca.length; i++) {
381      var c = ca[i];
382
383      while (c.charAt(0) == ' ') {
384        c = c.substring(1, c.length);
385      }
386
387      if (c.indexOf(nameEQ) == 0) {
388        return c.substring(nameEQ.length, c.length);
389      }
390    }
391
392    return null;
393  }
394})(jQuery, Drupal, once);
395/*
396 * Last updated: 09/09/2026 @ 14:22
397 */
398
399//# sourceMappingURL=simple_popup_blocks.js.map

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.