1"use strict"; 2 3; 4/* global wppopups_settings,*/ 5 6(function ($) { 7 /** 8 * Copyright 2012, Digital Fusion 9 * Licensed under the MIT license. 10 * http://teamdf.com/jquery-plugins/license/ 11 * 12 * @author Sam Sehnert 13 * @desc A small plugin that checks whether elements are within 14 * the user visible viewport of a web browser. 15 * can accounts for vertical position, horizontal, or both 16 */ 17 var $w = $(window); 18 19 $.fn.visible = function (partial, hidden, direction, container) { 20 if (this.length < 1) return; // Set direction default to 'both'. 21 22 direction = direction || 'both'; 23 var $t = this.length > 1 ? this.eq(0) : this, 24 isContained = typeof container !== 'undefined' && container !== null, 25 $c = isContained ? $(container) : $w, 26 wPosition = isContained ? $c.position() : 0, 27 t = $t.get(0), 28 vpWidth = $c.outerWidth(), 29 vpHeight = $c.outerHeight(), 30 clientSize = hidden === true ? t.offsetWidth * t.offsetHeight : true; 31 32 if (typeof t.getBoundingClientRect === 'function') { 33 // Use this native browser method, if available. 34 var rec = t.getBoundingClientRect(), 35 tViz = isContained ? rec.top - wPosition.top >= 0 && rec.top < vpHeight + wPosition.top : rec.top >= 0 && rec.top < vpHeight, 36 bViz = isContained ? rec.bottom - wPosition.top > 0 && rec.bottom <= vpHeight + wPosition.top : rec.bottom > 0 && rec.bottom <= vpHeight, 37 lViz = isContained ? rec.left - wPosition.left >= 0 && rec.left < vpWidth + wPosition.left : rec.left >= 0 && rec.left < vpWidth, 38 rViz = isContained ? rec.right - wPosition.left > 0 && rec.right < vpWidth + wPosition.left : rec.right > 0 && rec.right <= vpWidth, 39 vVisible = partial ? tViz || bViz : tViz && bViz, 40 hVisible = partial ? lViz || rViz : lViz && rViz, 41 vVisible = rec.top < 0 && rec.bottom > vpHeight ? true : vVisible, 42 hVisible = rec.left < 0 && rec.right > vpWidth ? true : hVisible; 43 if (direction === 'both') return clientSize && vVisible && hVisible;else if (direction === 'vertical') return clientSize && vVisible;else if (direction === 'horizontal') return clientSize && hVisible; 44 } else { 45 var viewTop = isContained ? 0 : wPosition,
46 viewBottom = viewTop + vpHeight, 47 viewLeft = $c.scrollLeft(), 48 viewRight = viewLeft + vpWidth, 49 position = $t.position(), 50 _top = position.top, 51 _bottom = _top + $t.height(), 52 _left = position.left, 53 _right = _left + $t.width(), 54 compareTop = partial === true ? _bottom : _top, 55 compareBottom = partial === true ? _top : _bottom, 56 compareLeft = partial === true ? _right : _left, 57 compareRight = partial === true ? _left : _right; 58 59 if (direction === 'both') return !!clientSize && compareBottom <= viewBottom && compareTop >= viewTop && compareRight <= viewRight && compareLeft >= viewLeft;else if (direction === 'vertical') return !!clientSize && compareBottom <= viewBottom && compareTop >= viewTop;else if (direction === 'horizontal') return !!clientSize && compareRight <= viewRight && compareLeft >= viewLeft; 60 } 61 }; 62})(jQuery); 63 64(function ($) { 65 'use strict'; 66 67 var WPPopupsPro = { 68 popups: {}, 69 last_position: null, 70 delta: 0, 71 timer: null, 72 73 /** 74 * Start the engine. 75 * 76 * @since 2.0.0 77 */ 78 init: function init() { 79 // Document ready 80 $(document).ready(WPPopupsPro.ready); // Page load 81 82 $(window).on('load', WPPopupsPro.load); // Document ready 83 84 $(document).on('wppopupsReady', WPPopupsPro.start); // Before rules in src 85 86 $(document).on('wppopupsBeforeReady', WPPopupsPro.beforeReady); // register events and hooks 87 88 WPPopupsPro.bindEvents(); 89 }, 90 91 /** 92 * Document ready. 93 * 94 * @since 2.0.0 95 */ 96 ready: function ready() {}, 97 98 /** 99 * Page load. 100 * 101 * @since 2.0.0 102 */ 103 load: function load() {}, 104 start: function start() { 105 WPPopupsPro.loopPopups(); // Set user identifier 106 // WPPopupsPro.setUserIndentifier(); not needed for now 107 108 $(document).trigger('wppopupsProStarted'); 109 }, 110 111 /** 112 * Configure each popup 113 */ 114 loopPopups: function loopPopups() { 115 $(".spu-box").each(function () { 116 var $popup = $(this), 117 $id = $popup.data('id'); // check if popups goes after content 118 119 WPPopupsPro.afterContentPopups($popup); // check advanced method 120 121 WPPopupsPro.advancedClosePopups($popup); 122 WPPopupsPro.pushContentPopups($popup); 123 }); 124 }, 125 // --------------------------------------------------------------------// 126 // Binds 127 // --------------------------------------------------------------------// 128 129 /** 130 * Events bindings. 131 * 132 * @since 2.0.0 133 */ 134 bindEvents: function bindEvents() { 135 // Stats 136 if (wppopups_pro_vars.enable_stats && '1' == wppopups_pro_vars.enable_stats) { 137 $(document).on('wppopups.popup_converted', WPPopupsPro.trackConversion); 138 $(document).on('wppopups.popup_opened', WPPopupsPro.trackOpening); 139 } //disable scroll 140 141 142 window.wp.hooks.addAction('wppopups_before_show_popup', 'wppopups', WPPopupsPro.disablePageScroll); 143 window.wp.hooks.addAction('wppopups_hide_popup', 'wppopups', WPPopupsPro.enablePageScroll); // animations 144 145 window.wp.hooks.addAction('wppopups_show_popup', 'wppopups', WPPopupsPro.triggerShowAnimations); 146 window.wp.hooks.addAction('wppopups_show_popup', 'wppopups', WPPopupsPro.triggerAutoClose); // sticky 147 148 window.wp.hooks.addAction('wppopups_show_popup', 'wppopups', WPPopupsPro.stickyPopup); 149 window.wp.hooks.addFilter('wppopups_cancel_hide', 'wppopups', function (default_value, popup) { 150 var settings = window.wppopups.settings(popup, 'position'); 151 152 if (settings.position == 'sticky-left' || settings.position == 'sticky-right') { 153 return true; 154 } 155 156 return default_value; 157 }); 158 $(document).on('click', '.spu-box .spu-sticky-title, .spu-position-sticky-right .spu-close-popup, .spu-position-sticky-left .spu-close-popup', function (e) { 159 $(this).closest('.spu-box').toggleClass('spu-sticky-open'); 160 }); // Triggers 161 162 window.wp.hooks.addAction('wppopups_trigger_popup', 'wppopups', WPPopupsPro.bindTriggers); 163 }, 164 165 /** 166 * Bind popup open trigger 167 * @param func_name 168 * @param trigger_value 169 * @param $popup 170 */ 171 bindTriggers: function bindTriggers(func_name, trigger_value, $popup) { 172 if (typeof WPPopupsPro[func_name] == 'function') { 173 WPPopupsPro[func_name](trigger_value, $popup); 174 } 175 }, 176 177 /** 178 * Trigger exit intent 179 * @param value 180 * @param $popup 181 */ 182 triggerByExit: function triggerByExit(value, $popup) { 183 if (window.wppopups.isMobile()) { 184 $(document).on('scroll', { 185 value: value, 186 popup: $popup 187 }, WPPopupsPro.exitIntentMobile); 188 } else { 189 $(document.body).on('mouseleave', { 190 value: value, 191 popup: $popup 192 }, WPPopupsPro.exitIntent); 193 } 194 }, 195 196 /** 197 * TRigger popup when element of class become visible 198 * @param value 199 * @param $popup 200 */ 201 triggerByVisible: function triggerByVisible(value, $popup) { 202 // if not class provided abort 203 if (value === '') { 204 return; 205 } 206 207 $(window).bind('scroll', { 208 value: value, 209 popup: $popup 210 }, WPPopupsPro.triggerVisible); 211 }, 212 213 /** 214 * @param value 215 * @param $popup 216 */ 217 triggerVisible: function triggerVisible(e) { 218 var triggerClass = WPPopupsPro.cleanClass(e.data.value); // show box when criteria for this box is matched 219 220 if ($(triggerClass).visible(true) && window.wppopups.checkConvertion(e.data.popup)) { 221 // remove listen event if box shouldn't be hidden again
222 $(window).unbind('scroll', WPPopupsPro.triggerVisible); 223 window.wppopups.showPopup(e.data.popup); 224 } 225 }, 226 227 /** 228 * Function that check a classname and add . in front 229 * @param classname 230 */ 231 cleanClass: function cleanClass(classname) { 232 if (classname.indexOf('.') !== 0) { 233 return '.' + classname; 234 } 235 236 return classname; 237 }, 238 239 /** 240 * Callback for exit intent popup 241 * @param e 242 * @param $popup 243 */ 244 exitIntent: function exitIntent(e) { 245 // Only trigger if leaving near the top of the page 246 if (e.clientY > 20 || !window.wppopups.checkConvertion(e.data.popup)) { 247 return; 248 } 249 250 window.wppopups.showPopup(e.data.popup); // we want to show it only once 251 252 $(document.body).unbind('mouseleave', WPPopupsPro.exitIntent); 253 }, 254 255 /** 256 * Callback for exit intent popup for Mobile 257 * @param e 258 * @param $popup 259 */ 260 exitIntentMobile: function exitIntentMobile(e) { 261 if (!window.wppopups.checkConvertion(e.data.popup)) return; 262 WPPopupsPro.scrollSpeed(); 263 if (WPPopupsPro.delta < -200) window.wppopups.showPopup(e.data.popup); 264 }, 265 266 /** 267 * Callback for calculate the speed scroll 268 */ 269 scrollSpeed: function scrollSpeed() { 270 var new_position = window.scrollY; 271 if (WPPopupsPro.last_position != null) WPPopupsPro.delta = new_position - WPPopupsPro.last_position; 272 WPPopupsPro.last_position = new_position; 273 clearTimeout(WPPopupsPro.timer); 274 WPPopupsPro.timer = setTimeout(function () { 275 WPPopupsPro.last_position = null; 276 WPPopupsPro.delta = 0; 277 }, 50); 278 }, 279 280 /** 281 * Set cookie container user UUID. 282 * 283 */ 284 setUserIndentifier: function setUserIndentifier() { 285 if (wppopups_settings.uuid_cookie && !WPPopupsPro.getCookie('_wpfuuid')) { 286 // Generate UUID - http://stackoverflow.com/a/873856/1489528 287 var s = new Array(36), 288 hexDigits = '0123456789abcdef', 289 uuid; 290 291 for (var i = 0; i < 36; i++) { 292 s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1); 293 } 294 295 s[14] = "4"; 296 s[19] = hexDigits.substr(s[19] & 0x3 | 0x8, 1); 297 s[8] = s[13] = s[18] = s[23] = '-'; 298 uuid = s.join(""); 299 WPPopupsPro.createCookie('_wpfuuid', uuid, 3999); 300 } 301 }, 302 303 /** 304 * Track popup opening 305 * @param event 306 * @param id 307 */ 308 trackOpening: function trackOpening(event, id) { 309 var $popup = window.wppopups.getPopup(id), 310 settings = window.wppopups.settings($popup, 'settings'), 311 sampling_active = wppopups_vars.dsampling || false, 312 sampling_rate = wppopups_vars.dsamplingrate; 313 var do_request = true; // don't track admins or test mode 314 315 if (wppopups_vars.is_admin && settings.test_mode == '1') { 316 return; 317 } // only save when sampling is not active or lottery wins 318 319 320 if (sampling_active && sampling_rate > 0) { 321 var num = Math.floor(Math.random() * sampling_rate) + 1; 322 do_request = 1 === num; 323 } 324 325 if (do_request) { 326 // Make the ajax request to track the data. If using Google Analytics, send to GA, otherwise track locally. 327 WPPopupsPro.trackGoogleAnalytics(id, false); 328 var data = { 329 action: 'track_wppopups', 330 popup_id: id, 331 conversion: false, 332 post_id: wppopups_pro_vars.post_id 333 }; 334 var ajax = { 335 url: wppopups_vars.ajax_url, 336 data: data, 337 cache: false, 338 type: 'POST', 339 dataType: 'json', 340 timeout: 30000 341 }; 342 $.ajax(ajax); 343 } 344 }, 345 346 /** 347 * Track in GA 348 * @param popup_id 349 * @param conversion 350 */ 351 trackGoogleAnalytics: function trackGoogleAnalytics(popup_id, conversion) { 352 var $popup = window.wppopups.getPopup(popup_id), 353 settings = window.wppopups.settings($popup, 'settings'), 354 eventCategory = settings.ga_event_category || 'Popup Event', 355 m_id = wppopups_pro_vars.m_id, 356 eventLabel = settings.ga_event_label || 'wppopups-' + popup_id, 357 eventIAction = settings.ga_event_action_impression || 'impression', 358 eventCAction = settings.ga_event_action_conversion || 'conversion', 359 eventAction = conversion ? eventCAction : eventIAction; 360 361 if (!m_id) { 362 return; 363 } 364 /* 365 // Create a custom event tracker and dimensions if it has not been initialized. 366 if ( ! WPPopupsPro.ga_init ) { 367 if (typeof ga == 'function') { 368 // create tracker 369 ga('create', ga_id, 'auto', { 'name' : 'WPPopupsTracker' }); 370 } 371 //yoast analytics 372 if (typeof __gaTracker == 'function') { 373 //create tracker 374 __gaTracker('create', ga_id, 'auto', { 'name' : 'WPPopupsTracker' }); 375 376 } 377 WPPopupsPro.ga_init = true; 378 } 379 380 // monster insights 381 if (typeof __gaTracker == 'function') { 382 // Send the event tracking data to Google Analytics. 383 if( ga_id ) { 384 __gaTracker('WPPopupsTracker.send', 'event', eventCategory, eventAction, eventLabel); 385 } 386 } else { 387 if (typeof ga == 'function') { 388 // Send the event tracking data to Google Analytics. 389 ga('WPPopupsTracker.send', 'event', eventCategory, eventAction, eventLabel ); 390 } 391 }*/ 392 // monster insights 393 394 395 if (typeof __gtagTracker == 'function') { 396 // new method as well
397 if (m_id) { 398 __gtagTracker('event', eventAction, { 399 'send_to': m_id, 400 'event_category': eventCategory, 401 'event_label': eventLabel 402 }); 403 } 404 } else { 405 if (typeof gtag == 'function' && m_id) { 406 // Send the event tracking data to Google Universal Analytics. 407 gtag('event', eventAction, { 408 'send_to': m_id, 409 'event_category': eventCategory, 410 'event_label': eventLabel 411 }); 412 } 413 } 414 }, 415 416 /** 417 * Track popup conversion 418 * @param event 419 * @param id 420 */ 421 trackConversion: function trackConversion(event, id) { 422 var $popup = window.wppopups.getPopup(id), 423 settings = window.wppopups.settings($popup, 'settings'); 424 var do_request = true; // don't track admins or test mode 425 426 if (wppopups_vars.is_admin && settings.test_mode == '1') { 427 return; 428 } // Make the ajax request to track the data. If using Google Analytics, send to GA, otherwise track locally. 429 430 431 WPPopupsPro.trackGoogleAnalytics(id, true); 432 var data = { 433 action: 'track_wppopups', 434 popup_id: id, 435 conversion: true, 436 post_id: wppopups_pro_vars.post_id 437 }; 438 var ajax = { 439 url: wppopups_vars.ajax_url, 440 data: data, 441 cache: false, 442 type: 'POST', 443 dataType: 'json', 444 timeout: 30000 445 }; 446 $.ajax(ajax); 447 }, 448 449 /** 450 * Run before the popup rules are checked 451 */ 452 beforeReady: function beforeReady() { 453 var counter = WPPopupsPro.sessionCounter(); 454 window.wp.hooks.addFilter('wppopups_pre_ready_data', 'wppopups', function (data) { 455 data.visited_n_pages = counter; 456 return data; 457 }); // check if any popups has trigger by conversion 458 459 $(".spu-box").each(function () { 460 var $popup = $(this), 461 $rules = window.wppopups.settings($popup, 'rules'); 462 463 if (Object.keys($rules).length) { 464 for (var group in $rules) { 465 for (var rule in $rules[group]) { 466 if ($rules[group][rule].rule == 'converted') { 467 // add need-convert class 468 $popup.addClass($rules[group][rule].operator == '==' ? 'yes-convert' : 'no-convert'); 469 $popup.data('convert-id', $rules[group][rule].value); 470 } // check if there is no need for ajax and we have a rule for n visited pages 471 472 473 if ($rules[group][rule].rule == 'visited_n_pages' && !$popup.data('need_ajax')) { 474 var operator = $rules[group][rule].operator; 475 var show_popup = false; 476 477 if (operator == "==") { 478 show_popup = counter == $rules[group][rule].value; 479 } else if (operator == "!=") { 480 show_popup = !(counter == $rules[group][rule].value); 481 } 482 483 if (counter < $rules[group][rule].value && operator == "<") { 484 show_popup = true; 485 } 486 487 if (counter > $rules[group][rule].value && operator == ">") { 488 show_popup = true; 489 } 490 491 if (!show_popup) { 492 $popup.remove(); 493 } 494 } 495 } 496 } 497 } 498 }); 499 }, 500 501 /** 502 * Auto close trigger method 503 * @param $popup 504 */ 505 triggerAutoClose: function triggerAutoClose($popup) { 506 var settings = window.wppopups.settings($popup, 'settings'); // Seconds left to close ( autoclose timer ) 507 508 if (settings.autoclose > 0 && typeof $popup.counter === 'undefined') { 509 $popup.autoclose = settings.autoclose; 510 $popup.counter = setInterval(function () { 511 WPPopupsPro.autoClose($popup); 512 }, 1000); 513 } 514 }, 515 516 /** 517 * Auto close function 518 * @param $popup 519 */ 520 autoClose: function autoClose($popup) { 521 var settings = window.wppopups.settings($popup, 'settings'); 522 $popup.autoclose = $popup.autoclose - 1; 523 524 if ($popup.autoclose <= 0) { 525 clearInterval($popup.counter); 526 $popup.counter = 'undefined'; 527 $popup.autoclose = settings.autoclose; 528 window.wppopups.hidePopup($popup, false); 529 return; 530 } 531 532 $("#spu-" + $popup.data('id')).find('.spu-timer').html(wppopups_pro_vars.l18n.wait + " " + $popup.autoclose + " " + wppopups_pro_vars.l18n.seconds); 533 }, 534 535 /** 536 * Move popup after post content 537 * @param $popup 538 */ 539 afterContentPopups: function afterContentPopups($popup) { 540 var settings = window.wppopups.settings($popup, 'position'); 541 542 if (settings.position == 'after-post') { 543 $('#spu-bg-' + $popup.data('id')).remove(); 544 545 if ($('.spu-placeholder').length) { 546 $('.spu-placeholder').append($popup); 547 } else { 548 $popup.remove(); 549 } 550 551 $('.spu-placeholder').show(); // remove advanced close for this popup 552 553 WPPopupsPro.advancedClosePopups($popup, true); 554 } 555 }, 556 557 /** 558 * Disable advanced close method 559 * @param $popup 560 * @param force boolean 561 */ 562 advancedClosePopups: function advancedClosePopups($popup, force) { 563 var settings = window.wppopups.settings($popup, 'settings'); // if popup has disabled advanced close or we are forcing ir (after content 564 565 if (settings.advanced_close == '1' || force) { 566 window.wp.hooks.addFilter('wppopups_allow_togglePopups', 'wppopups', function (default_value, popup) {
567 // if event fired popup id is equal to our popup, cancel it 568 if (popup.data('id') == $popup.data('id')) { 569 return false; 570 } 571 572 return default_value; 573 }); 574 } 575 }, 576 577 /** 578 * Disabel page scroll if needed 579 * @param $popup 580 */ 581 disablePageScroll: function disablePageScroll($popup) { 582 var settings = window.wppopups.settings($popup, 'settings'); 583 584 if (settings.disable_scroll && settings.disable_scroll == '1') { 585 $('body,html').css('overflow', 'hidden'); 586 } 587 }, 588 589 /** 590 * Disabel page scroll if needed 591 * @param $popup 592 */ 593 enablePageScroll: function enablePageScroll($popup) { 594 var settings = window.wppopups.settings($popup, 'settings'); 595 596 if (settings.disable_scroll && settings.disable_scroll == '1') { 597 $('body,html').css('overflow', ''); 598 } 599 }, 600 601 /** 602 * Trigger premium animations on the popup 603 * @param $popup 604 */ 605 triggerShowAnimations: function triggerShowAnimations($popup) { 606 var animation = window.wppopups.settings($popup, 'animation'); 607 var $class_name = ''; 608 609 switch (animation.animation) { 610 case 'fade': 611 break; 612 613 case 'slide': 614 break; 615 616 case 'disable': 617 break; 618 619 default: 620 $class_name = 'spu-animation-' + animation.animation; 621 break; 622 } 623 624 if ($class_name !== '') { 625 $popup.addClass($class_name).addClass('spu-animation-animated'); 626 } 627 }, 628 629 /** 630 * Show a sticky popup 631 * @param $popup 632 */ 633 stickyPopup: function stickyPopup($popup) { 634 var settings = window.wppopups.settings($popup, 'position'); 635 if (settings.position != 'sticky-left' && settings.position != 'sticky-right') return; 636 var sticky_title = $popup.find('.spu-sticky-title'); 637 $('#spu-bg-' + $popup.data('id')).remove(); 638 sticky_title.show(); 639 var popupHeight = $popup.outerHeight(), 640 titleHeight = $popup.find('.spu-sticky-title').outerHeight(); 641 $popup.css({ 642 "bottom": "-" + (popupHeight - titleHeight) + "px" 643 }); 644 }, 645 646 /** 647 * Check if user visited the page before and remove popup if not 648 */ 649 sessionCounter: function sessionCounter() { 650 var counter = sessionStorage.getItem('wppopups_visited_page') || 0; 651 var new_value = parseInt(counter) + 1; // if we have a counter and matches the number of the rule update popup 652 653 sessionStorage.setItem('wppopups_visited_page', new_value); 654 return new_value; 655 }, 656 657 /** 658 * Move popup to top/bottom if needed 659 * @param $popup 660 */ 661 pushContentPopups: function pushContentPopups($popup) { 662 var settings = window.wppopups.settings($popup, 'position'); 663 664 if (settings.position == 'top-bar' && settings.push_content == '1') { 665 $popup.prependTo('body'); 666 } 667 } 668 }; // Initialize. 669 670 WPPopupsPro.init(); // Add to global scope. 671 672 window.wppopups_pro = WPPopupsPro; 673})(jQuery);
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.