PageSourceSearch

https://www.iisd.org/modules/contrib/simple_popup_blocks/js/simple_popup_blocks.js?v=11.4.7

js iisd.org collected 2026-09-24 08:27:54 UTC 11,965 bytes, 361 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 !== undefined && values.cookie_expiry !== null) ? 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, cookie_days)
55          }
56          else {
57            createCookie('spb_' + block_id, cookie_val, cookie_days)
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, cookie_days)
90            }
91          }
92          else {
93            createCookie('spb_time' + block_id, next_popup, cookie_days)
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($('<button type="button" aria-label="Dismiss modal" class="' + modal_minimize_class + ' spb_minimize">&minus;</button>'))
143          $('.' + modal_class).
144            before($('<button type="button" aria-label="Open modal" class="' + modal_minimized_class + ' spb_minimized">&plus;</button>'))
145        }
146        // Close button wrap
147        if (values.close == 1) {
148          $("#"+spb_popup_id + " .spb-controls").
149            prepend($('<button type="button" aria-label="Close modal" class="' + modal_close_class + ' spb_close">&times;</button>'))
150        }
151        // Overlay
152        if (values.overlay == 1) {
153          $('.' + modal_class).addClass('spb_overlay')
154        }
155        // Inject layout class.
156        switch (values.layout) {
157          // Top left.
158          case 0:
159            $(layout_class).addClass('spb_top_left')
160            $(layout_class).css({
161              'width': values.width,
162            })
163            break
164          // Top right.
165          case '1':
166            $(layout_class).addClass('spb_top_right')
167            $(layout_class).css({
168              'width': values.width,
169            })
170            break
171          // Bottom left.
172          case '2':
173            $(layout_class).addClass('spb_bottom_left')
174            $(layout_class).css({
175              'width': values.width,
176            })
177            break
178          // Bottom right.
179          case '3':
180            $(layout_class).addClass('spb_bottom_right')
181            $(layout_class).css({
182              'width': values.width,
183            })
184            break
185          // Center.
186          case '4':
187            $(layout_class).addClass('spb_center')
188            $(layout_class).css({
189              'width': values.width,
190			  'margin-left': -values.width / 2
191            })
192            break
193          // Top Center.
194          case '5':
195            $(layout_class).addClass('spb_top_center')
196			  $(layout_class).css({
197			  'width': values.width,
198			  })
199            break
200          // Top bar.
201          case '6':
202            $(layout_class).addClass('spb_top_bar')
203            $(layout_class).css({})
204            break
205          // Right bar.
206          case '7':
207            $(layout_class).addClass('spb_bottom_bar')
208            $(layout_class).css({})
209            break
210          // Bottom bar.
211          case '8':
212            $(layout_class).addClass('spb_left_bar')
213            $(layout_class).css({
214              'width': values.width,
215            })
216            break
217          // Right bar.
218          case '9':
219            $(layout_class).addClass('spb_right_bar')
220            $(layout_class).css({
221              'width': values.width,
222            })
223            break
224        }
225      if (show_model === true) {
226        // Automatic trigger with delay
227        if (values.trigger_method == 0 && values.delay > 0) {
228          delays = values.delay * 1000
229          $(css_identity + block_id).show()
230          $('.' + modal_class).delay(delays).fadeIn('slow')
231            if (values.overlay == 1) {
232              setTimeout(stopTheScroll, delays)
233            }
234        }
235        // Automatic trigger without delay
236        else if (values.trigger_method == 0) {
237            $('.' + modal_class).show()
238            $(css_identity + block_id).show()
239            if (values.overlay == 1) {
240              stopTheScroll()
241            }
242        }
243        // Manual trigger
244        else if (values.trigger_method == 1) {
245          $(document).on('click', values.trigger_selector, function (e) {
246            $('.' + modal_class).show()
247            $(css_identity + block_id).show()
248            if (values.overlay == 1) {
249              stopTheScroll()
250            }
251            return false;
252          })
253        }
254        // Browser close trigger
255        else if (values.trigger_method == 2) {
256          $(_html).mouseleave(function (e) {
257            // Trigger only when mouse leave on top view port
258            if (e.clientY > 20) { return }
259            // Trigger only once per page
260            if (!browser_close_trigger) { return }
261            browser_close_trigger = false
262            $('.' + modal_class).show()
263            $(css_identity + block_id).show()
264            if (values.overlay == 1) {
265              stopTheScroll()
266            }
267          })
268        }
269        }
270
271        // Trigger for close button click
272        $('.' + modal_close_class).click(function () {
273          $('.' + modal_class).hide()
274          startTheScroll()
275        })
276        // Trigger for minimize button click
277        $('.' + modal_minimize_class).click(function () {
278          $('.' + modal_class).hide()
279          startTheScroll()
280          $('.' + modal_minimized_class).show()
281        })
282        // Trigger for minimized button click
283        $('.' + modal_minimized_class).click(function () {
284          $('.' + modal_class).show()
285          $(css_identity + block_id).show()
286          if (values.overlay == 1) {
287            stopTheScroll()
288          }
289
290        // Hide the minimized button.
291        if (show_minimized_button == 0) {
292          $('.' + modal_minimized_class).hide()
293        }
294
295        })
296        // Trigger for ESC button click
297        if (values.enable_escape == 1) {
298          $(document).keyup(function (e) {
299            if (e.keyCode == 27) { // Escape key maps to keycode `27`.
300              $('.' + modal_class).hide()
301              startTheScroll()
302              $('.' + modal_minimized_class).show()
303            }
304          })
305        }
306
307      // Hide the minimized button.
308      if (show_minimized_button == 0) {
309        $('.' + modal_minimized_class).hide()
310      }
311
312      }) // Foreach end.
313    }
314  } // document.ready end.
315
316  // Remove the scrolling while overlay active
317  function stopTheScroll () {
318    $('body').css({
319      'overflow': 'hidden',
320    });
321
322    $('.simple-popup-blocks-global input:text').focus();
323  }
324
325  // Enable the scrolling while overlay inactive
326  function startTheScroll () {
327    $('body').css({
328      'overflow': '',
329    })
330  }
331
332  // Creating cookie
333  function createCookie (name, value, days) {
334    if (days > 0) {
335      var date = new Date()
336      date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000))
337      var expires = '; expires=' + date.toGMTString()
338    }
339    else {
340      var expires = ''
341    }
342    document.cookie = name + '=' + value + expires + '; path=/'
343  }
344
345  // Reading cookie
346  function readCookie (name) {
347    var nameEQ = name + '='
348    var ca = document.cookie.split(';')
349    for (var i = 0; i < ca.length; i++) {
350      var c = ca[i]
351      while (c.charAt(0) == ' ') {
352        c = c.substring(1, c.length)
353      }
354      if (c.indexOf(nameEQ) == 0) {
355        return c.substring(nameEQ.length, c.length)
356      }
357    }
358    return null
359  }
360
361})(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.