1(function ($, Drupal) { 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 $(css_identity + block_id).once(). 114 wrap($('<div class="' + modal_class + '"></div>')) 115 // Hide the popup initially 116 $('.' + modal_class).once().hide() 117 118 // Wrap remaining elements 119 if ($(css_identity + block_id).closest('.spb-popup-main-wrapper').length) { 120 return; 121 } 122 $(css_identity + block_id). 123 wrap($('<div class="spb-popup-main-wrapper"></div>')) 124 $('.' + modal_class). 125 wrap('<div id="' + spb_popup_id + 126 '" class="simple-popup-blocks-global"></div>') 127 $(css_identity + block_id).
128 before($('<div class="spb-controls"></div>')) 129 130 // Skip code for non popup pages. 131 class_exists = $('#' + spb_popup_id). 132 hasClass('simple-popup-blocks-global') 133 if (!class_exists) { 134 return true 135 } 136 // Minimize button wrap 137 if (values.minimize === "1") { 138 $("#"+spb_popup_id + " .spb-controls"). 139 prepend($('<span class="' + modal_minimize_class + 140 ' spb_minimize">-</span>')) 141 $('.' + modal_class). 142 before($('<span class="' + modal_minimized_class + 143 ' spb_minimized"></span>')) 144 } 145 // Close button wrap 146 if (values.close == 1) { 147 $("#"+spb_popup_id + " .spb-controls"). 148 prepend($('<span class="' + modal_close_class + 149 ' spb_close">×</span>')) 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 $('.' + modal_class).delay(delays).fadeIn('slow') 230 if (values.overlay == 1) { 231 setTimeout(stopTheScroll, delays) 232 } 233 } 234 // Automatic trigger without delay 235 else if (values.trigger_method == 0) { 236 $('.' + modal_class).show() 237 $(css_identity + block_id).show() 238 if (values.overlay == 1) { 239 stopTheScroll() 240 } 241 } 242 // Manual trigger 243 else if (values.trigger_method == 1) { 244 $(document).on('click', values.trigger_selector, function (e) { 245 $('.' + modal_class).show() 246 $(css_identity + block_id).show() 247 if (values.overlay == 1) { 248 stopTheScroll() 249 } 250 return false; 251 }) 252 } 253 // Browser close trigger 254 else if (values.trigger_method == 2) { 255 $(_html).mouseleave(function (e) { 256 // Trigger only when mouse leave on top view port 257 if (e.clientY > 20) { return } 258 // Trigger only once per page 259 if (!browser_close_trigger) { return } 260 browser_close_trigger = false 261 $('.' + modal_class).show() 262 $(css_identity + block_id).show()
263 if (values.overlay == 1) { 264 stopTheScroll() 265 } 266 }) 267 } 268 } 269 270 // Trigger for close button click 271 $('.' + modal_close_class).click(function () { 272 $('.' + modal_class).hide() 273 startTheScroll() 274 }) 275 // Trigger for minimize button click 276 $('.' + modal_minimize_class).click(function () { 277 $('.' + modal_class).hide() 278 startTheScroll() 279 $('.' + modal_minimized_class).show() 280 }) 281 // Trigger for minimized button click 282 $('.' + modal_minimized_class).click(function () { 283 $('.' + modal_class).show() 284 $(css_identity + block_id).show() 285 if (values.overlay == 1) { 286 stopTheScroll() 287 } 288 289 // Hide the minimized button. 290 if (show_minimized_button == 0) { 291 $('.' + modal_minimized_class).hide() 292 } 293 294 }) 295 // Trigger for ESC button click 296 if (values.enable_escape == 1) { 297 $(document).keyup(function (e) { 298 if (e.keyCode == 27) { // Escape key maps to keycode `27`. 299 $('.' + modal_class).hide() 300 startTheScroll() 301 $('.' + modal_minimized_class).show() 302 } 303 }) 304 } 305 306 // Hide the minimized button. 307 if (show_minimized_button == 0) { 308 $('.' + modal_minimized_class).hide() 309 } 310 311 }) // Foreach end. 312 } 313 } // document.ready end. 314 315 // Remove the scrolling while overlay active 316 function stopTheScroll () { 317 $('body').css({ 318 'overflow': 'hidden', 319 }); 320 321 $('input:text').focus(); 322 } 323 324 // Enable the scrolling while overlay inactive 325 function startTheScroll () { 326 $('body').css({ 327 'overflow': '', 328 }) 329 } 330 331 // Creating cookie 332 function createCookie (name, value, days) { 333 if (days > 0) { 334 var date = new Date() 335 date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)) 336 var expires = '; expires=' + date.toGMTString() 337 } 338 else { 339 var expires = '' 340 } 341 document.cookie = name + '=' + value + expires + '; path=/' 342 } 343 344 // Reading cookie 345 function readCookie (name) { 346 var nameEQ = name + '=' 347 var ca = document.cookie.split(';') 348 for (var i = 0; i < ca.length; i++) { 349 var c = ca[i] 350 while (c.charAt(0) == ' ') { 351 c = c.substring(1, c.length) 352 } 353 if (c.indexOf(nameEQ) == 0) { 354 return c.substring(nameEQ.length, c.length) 355 } 356 } 357 return null 358 } 359 360})(jQuery, Drupal)
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.