PageSourceSearch

https://int.diasorin.com/modules/contrib/simple_popup_blocks/js/simple_popup_blocks.js?v=10.6.17

js diasorin.com collected 2026-09-24 19:21:11 UTC 11,720 bytes, 363 lines download raw bytes

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

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.