1function sgAddEvent(element, eventName, fn) 2{ 3 if (element.addEventListener) 4 element.addEventListener(eventName, fn, false); 5 else if (element.attachEvent) 6 element.attachEvent('on' + eventName, fn); 7} 8/*Popup order count*/ 9window.SGPB_ORDER = 0; 10 11function SGPBPopup() 12{ 13 this.id = null; 14 this.eventName = ''; 15 this.popupData = null; 16 this.popupConfig = {}; 17 this.popupObj = null; 18 this.onceListener(); 19 this.initialsListeners(); 20 this.countPopupOpen = true; 21} 22 23SGPBPopup.prototype.setCountPopupOpen = function(countPopupOpen) 24{ 25 this.countPopupOpen = countPopupOpen; 26} 27 28SGPBPopup.prototype.getCountPopupOpen = function() 29{ 30 return this.countPopupOpen; 31} 32 33SGPBPopup.prototype.initialsListeners = function() 34{ 35 window.SGPB_SOUND = []; 36 sgAddEvent(window, 'sgpbDidOpen', function(e) { 37 var args = e.detail; 38 var popupId = parseInt(args.popupId); 39 var options = SGPBPopup.getPopupOptionsById(popupId); 40 var soundUrl = options['sgpb-sound-url']; 41 var soundStatus = options['sgpb-open-sound']; 42 43 if (soundStatus && soundUrl && !window.SGPB_SOUND[popupId]) { 44 var audio = new Audio(soundUrl); 45 audio.play(); 46 window.SGPB_SOUND[popupId] = audio; 47 } 48 }); 49 50 sgAddEvent(window, 'sgpbDidClose', function(e) { 51 var args = e.detail; 52 var popupId = parseInt(args.popupId); 53 54 if (typeof window.SGPB_SOUND[popupId] && window.SGPB_SOUND[popupId]) { 55 window.SGPB_SOUND[popupId].pause(); 56 delete window.SGPB_SOUND[popupId]; 57 } 58 }); 59}; 60 61SGPBPopup.prototype.onceListener = function() 62{ 63 var that = this; 64 65 sgAddEvent(window, 'sgpbDidOpen', function(e) { 66 jQuery('.sg-popup-close').click(function(){ 67 var currentPopup = that.getPopupIdForNextEsc(); 68 if (!currentPopup) { 69 return false; 70 } 71 72 SGPBPopup.closePopupById(currentPopup.popupId); 73 }); 74 document.onkeydown = function(e) { 75 e = e || window.event; 76 77 if (e.keyCode == 27) { /*esc pressed*/ 78 var currentPopup = that.getPopupIdForNextEsc(); 79 if (!currentPopup) { 80 return false; 81 } 82 var lastPopupId = parseInt(currentPopup['popupId']); 83 SGPBPopup.closePopupById(lastPopupId); 84 } 85 }; 86 }); 87 88 sgAddEvent(window, 'sgpbDidClose', function(e) { 89 if (window.sgPopupBuilder.length != 0) { 90 var popups = [].concat(window.sgPopupBuilder).reverse(); 91 for (var i in popups) { 92 var nextIndex = ++i; 93 var nextObj = popups[nextIndex]; 94 95 if (typeof nextObj == 'undefined') { 96 jQuery('html, body').removeClass('sgpb-overflow-hidden'); 97 break; 98 } 99 100 if (nextObj.isOpen == false) { 101 continue; 102 } 103 var options = SGPBPopup.getPopupOptionsById(nextObj.popupId); 104 if (typeof options['sgpb-disable-page-scrolling'] == 'undefined') { 105 jQuery('html, body').removeClass('sgpb-overflow-hidden'); 106 } 107 else { 108 jQuery('html, body').addClass('sgpb-overflow-hidden'); 109 } 110 break; 111 } 112 } 113 else { 114 jQuery('html, body').addClass('sgpb-overflow-hidden'); 115 } 116 }); 117}; 118 119SGPBPopup.prototype.getPopupIdForNextEsc = function() 120{ 121 var popups = window.sgPopupBuilder; 122 var popup = false; 123 124 if (!popups.length) { 125 return popup; 126 } 127 128 var searchPopups = [].concat(popups).reverse(); 129 130 for (var i in searchPopups) { 131 var popupData = searchPopups[i]; 132 133 if (popupData.isOpen) { 134 var popupId = parseInt(popupData['popupId']); 135 var popupOptions = SGPBPopup.getPopupOptionsById(popupId); 136 137 if (!popupOptions['sgpb-disable-popup-closing'] && popupOptions['sgpb-esc-key']) { 138 popup = popupData; 139 break; 140 } 141 } 142 } 143 144 return popup; 145}; 146 147SGPBPopup.prototype.setPopupId = function(popupId) 148{ 149 this.id = parseInt(popupId); 150}; 151 152SGPBPopup.prototype.getPopupId = function() 153{ 154 return this.id; 155}; 156 157SGPBPopup.prototype.setPopupObj = function(popupObj) 158{ 159 this.popupObj = popupObj; 160}; 161 162SGPBPopup.prototype.getPopupObj = function() 163{ 164 return this.popupObj; 165}; 166 167SGPBPopup.prototype.setPopupData = function(popupData) 168{ 169 if (typeof popupData == 'string') { 170 var popupData = SGPBPopup.unserialize(popupData); 171 } 172 173 this.popupData = popupData; 174}; 175 176SGPBPopup.prototype.getPopupData = function() 177{ 178 return this.popupData; 179}; 180 181SGPBPopup.prototype.setPopupConfig = function(config) 182{ 183 this.popupConfig = config; 184}; 185 186SGPBPopup.prototype.getPopupConfig = function() 187{ 188 return this.popupConfig; 189}; 190 191SGPBPopup.prototype.setUpPopupConfig = function() 192{ 193 var popupConfig = new PopupConfig(); 194 this.setPopupConfig(popupConfig); 195}; 196 197SGPBPopup.createPopupObjById = function(popupId) 198{ 199 var options = SGPBPopup.getPopupOptionsById(popupId); 200 201 if (!options) { 202 return false;
203 } 204 var popupObj = new SGPBPopup(); 205 popupObj.setPopupId(popupId); 206 popupObj.setPopupData(options); 207 208 return popupObj; 209}; 210 211 212SGPBPopup.getPopupOptionsById = function(popupId) 213{ 214 var popupDataDiv = jQuery('#sg-popup-content-wrapper-'+popupId); 215 216 if (!popupDataDiv.length) { 217 return false; 218 } 219 var options = popupDataDiv.attr('data-options'); 220 221 return SGPBPopup.unserialize(options); 222}; 223 224SGPBPopup.prototype.getCompatibleZiIndex = function(popupZIndex) 225{ 226 /*2147483647 it's maximal z index value*/ 227 if (popupZIndex > 2147483647) { 228 return 2147483627; 229 } 230 231 return popupZIndex; 232}; 233 234SGPBPopup.prototype.prepareOpen = function() 235{ 236 var popupId = this.getPopupId(); 237 var popupData = this.getPopupData(); 238 var popupZIndex = this.getCompatibleZiIndex(popupData['sgpb-popup-z-index']); 239 var popupType = this.popupData['sgpb-type']; 240 this.setUpPopupConfig(); 241 var that = this; 242 243 var popupConfig = this.getPopupConfig(); 244 this.setPopupDimensions(); 245 246 if (popupData['sgpb-disable-popup-closing'] == 'on') { 247 popupData['sgpb-enable-close-button'] = ''; 248 popupData['sgpb-esc-key'] = ''; 249 popupData['sgpb-overlay-click'] = ''; 250 } 251 /*used in the analytics*/ 252 popupData['eventName'] = this.eventName; 253 254 if (SGPBPopup.varToBool(popupData['sgpb-enable-close-button'])) { 255 popupConfig.magicCall('setCloseButtonDelay', parseInt(popupData['sgpb-close-button-delay'])); 256 } 257 258 popupConfig.magicCall('setShowButton', SGPBPopup.varToBool(popupData['sgpb-enable-close-button'])); 259 /* Convert seconds to micro seconds */ 260 var openAnimationSpeed = parseFloat(popupData['sgpb-open-animation-speed'])*1000; 261 var closeAnimationSpeed = parseFloat(popupData['sgpb-close-animation-speed'])*1000; 262 popupConfig.magicCall('setOpenAnimationEffect', popupData['sgpb-open-animation-effect']); 263 popupConfig.magicCall('setCloseAnimationEffect', popupData['sgpb-close-animation-effect']); 264 popupConfig.magicCall('setOpenAnimationSpeed', openAnimationSpeed); 265 popupConfig.magicCall('setCloseAnimationSpeed', closeAnimationSpeed); 266 popupConfig.magicCall('setOpenAnimationStatus', popupData['sgpb-open-animation']); 267 popupConfig.magicCall('setCloseAnimationStatus', popupData['sgpb-close-animation']); 268 popupConfig.magicCall('setContentPadding', popupData['sgpb-content-padding']); 269 if (typeof SgpbRecentSalesPopupType != 'undefined') { 270 if (popupType == SgpbRecentSalesPopupType) { 271 /* set max z index for recent sales popup */ 272 popupZIndex = 2147483647; 273 popupConfig.magicCall('setCloseAnimationEffect', 'fade'); 274 popupConfig.magicCall('setCloseAnimationSpeed', 1000); 275 popupConfig.magicCall('setCloseAnimationStatus', 'on'); 276 } 277 } 278 279 popupConfig.magicCall('setZIndex', popupZIndex); 280 popupConfig.magicCall('setCloseButtonWidth', popupData['sgpb-button-image-width']); 281 popupConfig.magicCall('setCloseButtonHeight', popupData['sgpb-button-image-height']); 282 popupConfig.magicCall('setPopupId', popupId); 283 popupConfig.magicCall('setPopupData', popupData); 284 popupConfig.magicCall('setAllowed', !SGPBPopup.varToBool(popupData['sgpb-disable-popup-closing'])); 285 if (popupData['sgpb-type'] == SGPB_POPUP_PARAMS.popupTypeAgeRestriction) { 286 popupConfig.magicCall('setAllowed', false); 287 } 288 popupConfig.magicCall('setEscShouldClose', SGPBPopup.varToBool(popupData['sgpb-esc-key'])); 289 popupConfig.magicCall('setOverlayShouldClose', SGPBPopup.varToBool(popupData['sgpb-overlay-click'])); 290 291 popupConfig.magicCall('setScrollingEnabled', SGPBPopup.varToBool(popupData['sgpb-enable-content-scrolling'])); 292 293 if (SGPBPopup.varToBool(popupData['sgpb-content-click'])) { 294 this.contentCloseBehavior(); 295 } 296 if (SGPBPopup.varToBool(popupData['sgpb-popup-fixed'])) { 297 this.addFixedPosition(); 298 } 299 /*ThemeCreator*/ 300 this.themeCreator(); 301 this.themeCustomizations(); 302 303 popupConfig.magicCall('setContents', document.getElementById('sg-popup-content-wrapper-'+popupId)); 304 popupConfig.magicCall('setPopupType', popupType); 305 this.setPopupConfig(popupConfig); 306 this.popupTriggeringListeners(); 307 308 /* check popup type, then check if popup can be opened by popup type */ 309 var allowToOpen = this.checkCurrentPopupType(); 310 if (allowToOpen) { 311 this.open(); 312 } 313}; 314 315SGPBPopup.prototype.checkCurrentPopupType = function() 316{ 317 var allowToOpen = true; 318 var popupConfig = new PopupConfig(); 319 320 var isPreview = parseInt(this.popupData['sgpb-is-preview']); 321 if (!isNaN(isPreview) && isPreview == 1) { 322 return allowToOpen; 323 } 324 325 var popupHasLimit = this.popupLimitation(this.popupData); 326 if (!popupHasLimit) { 327 return false;
328 } 329 330 var dontShowPopupCookieName = 'sgDontShowPopup' + this.popupData['sgpb-post-id']; 331 var dontShowPopup = SGPopup.getCookie(dontShowPopupCookieName); 332 if (dontShowPopup != '') { 333 return false; 334 } 335 336 var className = this.popupData['sgpb-type']; 337 if (typeof className == 'undefined' || className == 'undefined') { 338 return false; 339 } 340 341 if (typeof SGPB_POPUP_PARAMS.conditionalJsClasses != 'undefined' && SGPB_POPUP_PARAMS.conditionalJsClasses.length) { 342 var isAllowConditions = this.isAllowJsConditions(); 343 344 if (!isAllowConditions) { 345 return false; 346 } 347 } 348 349 if (typeof this.allowAfterXPages != 'undefined') { 350 var allowAfterXPages = this.allowAfterXPages(); 351 if (!allowAfterXPages) { 352 return false; 353 } 354 } 355 /* make the first letter of a string uppercase, then concat prefix (uppercase all prefix string) */ 356 className = popupConfig.prefix.toUpperCase() + className.firstToUpperCase(); 357 /* hasOwnProperty returns boolean value */ 358 if (window.hasOwnProperty(className)) { 359 className = eval(className); 360 /* create current popup type object */ 361 var obj = new className; 362 /* call allowToOpen function if exists */ 363 if (typeof obj.allowToOpen === 'function') { 364 allowToOpen = obj.allowToOpen(this.id); 365 } 366 } 367 368 return allowToOpen; 369}; 370 371SGPBPopup.prototype.isAllowJsConditions = function() { 372 var conditions = SGPB_POPUP_PARAMS.conditionalJsClasses; 373 var isAllow = true; 374 375 for (var i in conditions) { 376 if (!conditions.hasOwnProperty(i)) { 377 break; 378 } 379 380 try { 381 var className = eval(conditions[i]); 382 } 383 catch (e) { 384 continue; 385 } 386 var obj = new className; 387 /* call allowToOpen function if exists */ 388 if (typeof obj.allowToOpen === 'function') { 389 var allowToOpen = obj.allowToOpen(this.id); 390 if (!allowToOpen) { 391 isAllow = allowToOpen; 392 break; 393 } 394 } 395 } 396 397 return isAllow; 398}; 399 400SGPBPopup.prototype.popupLimitation = function(popupData) 401{ 402 var currentUrl = window.location.href; 403 var currentPopupId = popupData['sgpb-post-id']; 404 var popupLimitationCookieHomePageLevelName = 'SGPBShowingLimitationHomePage' + currentPopupId; 405 var popupLimitationCookiePageLevelName = 'SGPBShowingLimitationPage' + currentPopupId; 406 var popupLimitationCookieDomainName = 'SGPBShowingLimitationDomain' + currentPopupId; 407 var popupLimitation = popupData['sgpb-show-popup-same-user']; 408 if (typeof popupLimitation != 'undefined' && popupLimitation) { 409 var popupShowingLimit = popupData['sgpb-show-popup-same-user-count']; 410 var popupShowingLimitExpiry = popupData['sgpb-show-popup-same-user-expiry']; 411 var pageLevelCookie = popupData['sgpb-show-popup-same-user-page-level']; 412 if (typeof pageLevelCookie == 'undefined') { 413 pageLevelCookie = ''; 414 } 415 if (currentUrl == SGPB_POPUP_PARAMS.homePageUrl) { 416 popupLimitationCookiePageLevelName = popupLimitationCookieHomePageLevelName; 417 } 418 var popupLimitationPageLevelCookie = SGPopup.getCookie(popupLimitationCookiePageLevelName); 419 var popupLimitationDomainCookie = SGPopup.getCookie(popupLimitationCookieDomainName); 420 /* page level cookie saving selected */ 421 if (pageLevelCookie) { 422 /* if has already another saving level cookie */ 423 if (popupLimitationPageLevelCookie == '') { 424 var cookieObject = { 425 openingCount : 1, 426 pageLevelCookie : pageLevelCookie, 427 openingPage : currentUrl 428 }; 429 SGPBPopup.setCookie(popupLimitationCookiePageLevelName, JSON.stringify(cookieObject), popupShowingLimitExpiry, currentUrl); 430 } 431 else { 432 var popupLimitationPageLevelCookie = jQuery.parseJSON(popupLimitationPageLevelCookie); 433 if (popupShowingLimit <= popupLimitationPageLevelCookie.openingCount) { 434 return false; 435 } 436 var updatedCount = parseInt(popupLimitationPageLevelCookie.openingCount + 1); 437 popupLimitationPageLevelCookie.openingCount = updatedCount; 438 SGPBPopup.setCookie(popupLimitationCookiePageLevelName, JSON.stringify(popupLimitationPageLevelCookie), popupShowingLimitExpiry, currentUrl); 439 } 440 SGPBPopup.deleteCookie(popupLimitationCookieDomainName); 441 } 442 /* domain level cookie saving selected */ 443 else { 444 if (typeof popupLimitationPageLevelCookie == 'undefined') { 445 popupLimitationPageLevelCookie = ''; 446 } 447 if (popupLimitationPageLevelCookie != '') { 448 var popupLimitationPageLevelCookie = jQuery.parseJSON(popupLimitationPageLevelCookie); 449 } 450 /* if has already another saving level cookie */ 451 if (popupLimitationPageLevelCookie) { 452 SGPBPopup.deleteCookie(popupLimitationCookiePageLevelName, popupLimitationPageLevelCookie.openingPage); 453 } 454 455 if (popupLimitationDomainCookie == '') { 456 var cookieObject = { 457 openingCount : 1, 458 pageLevelCookie : pageLevelCookie 459 }; 460 SGPBPopup.setCookie(popupLimitationCookieDomainName, JSON.stringify(cookieObject), popupShowingLimitExpiry, pageLevelCookie); 461 } 462 else { 463 var popupLimitationDomainCookie = jQuery.parseJSON(popupLimitationDomainCookie); 464 if (popupShowingLimit <= popupLimitationDomainCookie.openingCount) { 465 return false;
466 } 467 var updatedCount = parseInt(popupLimitationDomainCookie.openingCount + 1); 468 popupLimitationDomainCookie.openingCount = updatedCount; 469 SGPBPopup.setCookie(popupLimitationCookieDomainName, JSON.stringify(popupLimitationDomainCookie), popupShowingLimitExpiry, pageLevelCookie); 470 } 471 } 472 } 473 474 return true; 475}; 476 477SGPBPopup.prototype.themeCreator = function() 478{ 479 var noPositionSelected = false; 480 var popupData = this.getPopupData(); 481 var popupId = this.getPopupId(); 482 var popupConfig = this.getPopupConfig(); 483 var forceRtlClass = ''; 484 var forceRtl = SGPBPopup.varToBool(popupData['sgpb-force-rtl']); 485 var popupTheme = popupData['sgpb-popup-themes']; 486 var popupType = popupData['sgpb-type']; 487 var closeButtonWidth = popupData['sgpb-button-image-width']; 488 var closeButtonHeight = popupData['sgpb-button-image-height']; 489 var contentPadding = parseInt(popupData['sgpb-content-padding']); 490 var contentClass = popupData['sgpb-content-custom-class']; 491 var closeButtonImage = popupConfig.closeButtonImage; 492 var themeNumber = 1; 493 if (forceRtl) { 494 forceRtlClass = ' sgpb-popup-content-direction-right'; 495 } 496 if (popupData['sgpb-type'] == 'countdown') { 497 popupConfig.magicCall('setMinWidth', 300); 498 } 499 popupConfig.magicCall('setContentPadding', contentPadding); 500 popupConfig.magicCall('setOverlayAddClass', popupTheme+'-overlay sgpb-popup-overlay-' + popupId); 501 popupConfig.magicCall('setContentAddClass', 'sgpb-content sgpb-content-'+popupId+' ' + popupTheme+'-content ' + contentClass + forceRtlClass); 502 503 if (typeof popupData['sgpb-close-button-position'] == 'undefined' || popupData['sgpb-close-button-position'] == '') { 504 /* 505 * in the old version we don't have close button position option 506 * and if noPositionSelected is true, the popup was not edited 507 */ 508 var noPositionSelected = true; 509 } 510 else { 511 var closeButtonPosition = popupData['sgpb-close-button-position']; 512 popupConfig.magicCall('setButtonPosition', closeButtonPosition); 513 } 514 515 var backgroundColor = 'black'; 516 var recentSalesPopup = false; 517 if (typeof SgpbRecentSalesPopupType != 'undefined') { 518 if (popupType == SgpbRecentSalesPopupType) { 519 recentSalesPopup = true; 520 popupTheme = 'sgpb-theme-2'; 521 closeButtonPosition = 'topRight'; 522 backgroundColor = 'white'; 523 popupConfig.magicCall('setShadowSpread', 3); 524 popupConfig.magicCall('setContentShadowBlur', 5); 525 } 526 } 527 528 if (popupTheme == 'sgpb-theme-1') { 529 themeNumber = 1; 530 popupConfig.magicCall('setShadowSpread', 14); 531 /* 9px theme default close button position for all cases */ 532 if (noPositionSelected || closeButtonPosition == 'bottomRight') { 533 popupConfig.magicCall('setCloseButtonPositionRight', '9px'); 534 popupConfig.magicCall('setCloseButtonPositionBottom', '9px'); 535 } 536 else { 537 popupConfig.magicCall('setCloseButtonPositionLeft', '9px'); 538 popupConfig.magicCall('setCloseButtonPositionBottom', '9px'); 539 } 540 } 541 else if (popupTheme == 'sgpb-theme-2') { 542 themeNumber = 2; 543 popupConfig.magicCall('setButtonInside', false); 544 popupConfig.magicCall('setContentBorderWidth', 1); 545 popupConfig.magicCall('setContentBackgroundColor', backgroundColor); 546 popupConfig.magicCall('setContentBorderColor', 'inherit'); 547 popupConfig.magicCall('setOverlayColor', 'white'); 548 var rightPosition = '0'; 549 var topPosition = '-' + closeButtonHeight + 'px'; 550 if (recentSalesPopup) { 551 rightPosition = '-' + (closeButtonWidth / 2) + 'px'; 552 topPosition = '-' + (closeButtonHeight / 2) + 'px'; 553 themeNumber = 6; 554 } 555 if (noPositionSelected || closeButtonPosition == 'topRight') { 556 /* this theme has 1px border */ 557 popupConfig.magicCall('setCloseButtonPositionRight', rightPosition); 558 popupConfig.magicCall('setCloseButtonPositionTop', topPosition); 559 } 560 else { 561 if (closeButtonPosition == 'topLeft') { 562 popupConfig.magicCall('setCloseButtonPositionLeft', '0'); 563 popupConfig.magicCall('setCloseButtonPositionTop', '-' + closeButtonHeight + 'px'); 564 } 565 else if (closeButtonPosition == 'bottomRight') { 566 popupConfig.magicCall('setCloseButtonPositionRight', '0'); 567 popupConfig.magicCall('setCloseButtonPositionBottom', '-' + closeButtonHeight + 'px'); 568 } 569 else if (closeButtonPosition == 'bottomLeft') { 570 popupConfig.magicCall('setCloseButtonPositionLeft', '0'); 571 popupConfig.magicCall('setCloseButtonPositionBottom', '-' + closeButtonHeight + 'px'); 572 } 573 } 574 } 575 else if (popupTheme == 'sgpb-theme-3') { 576 themeNumber = 3; 577 popupConfig.magicCall('setContentBorderWidth', 5); 578 popupConfig.magicCall('setContentBorderRadius', popupData['sgpb-border-radius']); 579 popupConfig.magicCall('setContentBorderRadiusType', popupData['sgpb-border-radius-type']); 580 popupConfig.magicCall('setContentBorderColor', popupData['sgpb-border-color']); 581 if (noPositionSelected) { 582 popupConfig.magicCall('setCloseButtonWidth', 38); 583 popupConfig.magicCall('setCloseButtonHeight', 19); 584 popupConfig.magicCall('setCloseButtonPositionRight', '4px'); 585 popupConfig.magicCall('setCloseButtonPositionTop', '4px'); 586 } 587 else { 588 if (closeButtonPosition == 'topRight') { 589 popupConfig.magicCall('setCloseButtonPositionRight', '4px'); 590 popupConfig.magicCall('setCloseButtonPositionTop', '4px'); 591 } 592 else if (closeButtonPosition == 'topLeft') { 593 popupConfig.magicCall('setCloseButtonPositionLeft', '4px'); 594 popupConfig.magicCall('setCloseButtonPositionTop', '4px'); 595 } 596 else if (closeButtonPosition == 'bottomRight') { 597 popupConfig.magicCall('setCloseButtonPositionLeft', '4px'); 598 popupConfig.magicCall('setCloseButtonPositionBottom', '4px'); 599 } 600 else if (closeButtonPosition == 'bottomLeft') { 601 popupConfig.magicCall('setCloseButtonPositionLeft', '4px'); 602 popupConfig.magicCall('setCloseButtonPositionBottom', '4px'); 603 } 604 } 605 } 606 else if (popupTheme == 'sgpb-theme-4') { 607 /* in theme-4 close button type is button,not image, 608 * then set type to button, default is image and 609 * set text 610 */ 611 themeNumber = 4;
612 popupConfig.magicCall('setButtonImage', popupData['sgpb-button-text']); 613 popupConfig.magicCall('setCloseButtonType', 'button'); 614 popupConfig.magicCall('setCloseButtonText', popupData['sgpb-button-text']); 615 popupConfig.magicCall('setContentBorderWidth', 0); 616 popupConfig.magicCall('setContentBackgroundColor', 'white'); 617 popupConfig.magicCall('setContentBorderColor', 'white'); 618 popupConfig.magicCall('setOverlayColor', 'white'); 619 popupConfig.magicCall('setShadowSpread', 4); 620 popupConfig.magicCall('setContentShadowBlur', 8); 621 /* 8px/12px theme default close button position for all cases */ 622 if (noPositionSelected || closeButtonPosition == 'bottomRight') { 623 popupConfig.magicCall('setCloseButtonPositionRight', '12px'); 624 popupConfig.magicCall('setCloseButtonPositionBottom', '9px'); 625 } 626 else { 627 popupConfig.magicCall('setCloseButtonPositionLeft', '12px'); 628 popupConfig.magicCall('setCloseButtonPositionBottom', '9px'); 629 } 630 } 631 else if (popupTheme == 'sgpb-theme-5') { 632 themeNumber = 5; 633 popupConfig.magicCall('setBoxBorderWidth', 10); 634 popupConfig.magicCall('setContentBorderColor', '#4B4B4B'); 635 if (noPositionSelected || closeButtonPosition == 'bottomRight') { 636 popupConfig.magicCall('setCloseButtonPositionRight', '8px'); 637 popupConfig.magicCall('setCloseButtonPositionBottom', '8px'); 638 } 639 else { 640 popupConfig.magicCall('setCloseButtonPositionLeft', '8px'); 641 popupConfig.magicCall('setCloseButtonPositionBottom', '8px'); 642 } 643 } 644 else if (popupTheme == 'sgpb-theme-6') { 645 themeNumber = 6; 646 popupConfig.magicCall('setButtonInside', false); 647 popupConfig.magicCall('setContentBorderRadius', 7); 648 popupConfig.magicCall('setContentBorderRadiusType', 'px'); 649 if (noPositionSelected) { 650 popupConfig.magicCall('setCloseButtonWidth', 37); 651 popupConfig.magicCall('setCloseButtonHeight', 37); 652 popupConfig.magicCall('setCloseButtonPositionRight', '-18.5px'); 653 popupConfig.magicCall('setCloseButtonPositionTop', '-18.5px'); 654 } 655 else { 656 if (closeButtonPosition == 'topRight') { 657 popupConfig.magicCall('setCloseButtonPositionRight', '-' + (closeButtonWidth / 2) + 'px'); 658 popupConfig.magicCall('setCloseButtonPositionTop', '-' + (closeButtonHeight / 2) + 'px'); 659 } 660 else if (closeButtonPosition == 'topLeft') { 661 popupConfig.magicCall('setCloseButtonPositionLeft', '-' + (closeButtonWidth / 2) + 'px'); 662 popupConfig.magicCall('setCloseButtonPositionTop', '-' + (closeButtonHeight / 2) + 'px'); 663 } 664 else if (closeButtonPosition == 'bottomRight') { 665 popupConfig.magicCall('setCloseButtonPositionRight', '-' + (closeButtonWidth / 2) + 'px'); 666 popupConfig.magicCall('setCloseButtonPositionBottom', '-' + (closeButtonHeight / 2) + 'px'); 667 } 668 else if (closeButtonPosition == 'bottomLeft') { 669 popupConfig.magicCall('setCloseButtonPositionLeft', '-' + (closeButtonWidth / 2) + 'px'); 670 popupConfig.magicCall('setCloseButtonPositionBottom', '-' + (closeButtonHeight / 2) + 'px'); 671 } 672 } 673 } 674 675 popupConfig.magicCall('setPopupTheme', themeNumber); 676 677 if (!popupData['sgpb-button-image']) { 678 closeButtonImage = SGPB_POPUP_PARAMS.defaultThemeImages[themeNumber]; 679 if (typeof closeButtonImage != 'undefined') { 680 popupConfig.magicCall('setButtonImage', 'data:image/png;base64,'+closeButtonImage); 681 } 682 } 683 else { 684 popupConfig.magicCall('setButtonImage', 'data:image/png;base64,'+popupData['sgpb-button-image-data']); 685 } 686 687}; 688 689SGPBPopup.prototype.themeCustomizations = function() 690{ 691 var popupId = this.getPopupId(); 692 var popupData = this.getPopupData(); 693 var popupConfig = this.getPopupConfig(); 694 695 var contentOpacity = popupData['sgpb-content-opacity']; 696 var contentBgColor = popupData['sgpb-background-color']; 697 if (popupData['sgpb-background-image-data']) { 698 var contentBgImage = 'data:image/png;base64,'+popupData['sgpb-background-image-data']; 699 } 700 else { 701 var contentBgImage = popupData['sgpb-background-image']; 702 } 703 var showContentBackground = popupData['sgpb-show-background']; 704 var contentBgImageMode = popupData['sgpb-background-image-mode']; 705 var overlayColor = popupData['sgpb-overlay-color']; 706 var popupTheme = popupData['sgpb-popup-themes']; 707 var popupType = popupData['sgpb-type']; 708
709 if (typeof showContentBackground == 'undefined') { 710 contentBgColor = ''; 711 contentBgImage = ''; 712 contentBgImageMode = ''; 713 } 714 if (typeof SgpbRecentSalesPopupType != 'undefined') { 715 if (popupType == SgpbRecentSalesPopupType) { 716 showContentBackground = 'on'; 717 contentBgColor = popupData['sgpb-background-color']; 718 contentOpacity = popupData['sgpb-content-opacity']; 719 } 720 } 721 722 if (contentOpacity) { 723 popupConfig.magicCall('setContentBackgroundOpacity', contentOpacity); 724 } 725 if (contentBgImageMode) { 726 popupConfig.magicCall('setContentBackgroundMode', contentBgImageMode); 727 } 728 if (contentBgImage) { 729 popupConfig.magicCall('setContentBackgroundImage', contentBgImage); 730 } 731 if (contentBgColor) { 732 contentBgColor = SGPBPopup.hexToRgba(contentBgColor, contentOpacity); 733 popupConfig.magicCall('setContentBackgroundColor', contentBgColor); 734 } 735 if (overlayColor) { 736 popupConfig.magicCall('setOverlayColor', overlayColor); 737 } 738 739 var overlayClasses = popupTheme+'-overlay sgpb-popup-overlay-'+popupId; 740 if (SGPBPopup.varToBool(popupData['sgpb-enable-popup-overlay']) || SGPB_JS_PACKAGES.packages['current'] == SGPB_JS_PACKAGES.packages['free']) { 741 if (SGPB_JS_PACKAGES.packages['current'] != SGPB_JS_PACKAGES.packages['free']) { 742 popupConfig.magicCall('setOverlayVisible', SGPBPopup.varToBool(popupData['sgpb-enable-popup-overlay'])); 743 } 744 popupConfig.magicCall('setOverlayAddClass', overlayClasses + ' ' + popupData['sgpb-overlay-custom-class']); 745 popupConfig.magicCall('setOverlayOpacity', popupData['sgpb-overlay-opacity'] * 100); 746 } 747 else { 748 if (SGPB_JS_PACKAGES.packages['current'] == SGPB_JS_PACKAGES.packages['free']) { 749 popupData['sgpb-enable-popup-overlay'] = true; 750 } 751 popupConfig.magicCall('setOverlayVisible', SGPBPopup.varToBool(popupData['sgpb-enable-popup-overlay'])); 752 } 753}; 754 755SGPBPopup.prototype.formSubmissionDetection = function(args) 756{ 757 if (args.length) { 758 return false; 759 } 760 var popupId = args.popupId; 761 var options = SGPBPopup.getPopupOptionsById(popupId); 762 763 if (!options['sgpb-reopen-after-form-submission']) { 764 return false; 765 } 766 767 jQuery('.sgpb-popup-builder-content-' + popupId + ' form').submit(function() { 768 SGPBPopup.setCookie('SGPBSubmissionReloadPopup', popupId); 769 }); 770}; 771 772SGPBPopup.prototype.htmlIframeFilterForOpen = function(popupId, popupEventName) 773{ 774 var popupContent = jQuery('.sgpb-content-' + popupId); 775 776 if (!popupContent.length) { 777 return false; 778 } 779 780 popupContent.find('iframe').each(function() { 781 782 if (popupEventName != 'open') { 783 /* for do not affect facebook type buttons iframe only */ 784 if (jQuery(this).closest('.fb_iframe_widget').length) { 785 return true; 786 } 787 788 jQuery(this).attr('data-attr-src', src); 789 jQuery(this).attr('src', ''); 790 return true; 791 } 792 else { 793 var src = jQuery(this).attr('data-attr-src'); 794 jQuery(this).attr('src', src); 795 } 796 }); 797}; 798 799SGPBPopup.prototype.getSearchDataFromContent = function(content) 800{ 801 var pattern = /\[(\[?)(pbvariable)(?![\w-])([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]\*+(?:\[(?!\/\2\])[^\[]\*+)\*+)\[\/\2\])?)(\]?)/gi; 802 var match; 803 var collectedData = []; 804 805 while (match = pattern.exec(content)) { 806 var currentSearchData = []; 807 var attributes; 808 var attributesKeyValue = []; 809 var parseAttributes = /\s(\w+?)="(.+?)"/g; 810 currentSearchData['replaceString'] = this.htmlDecode(match[0]); 811 812 while (attributes = parseAttributes.exec(match[3])) { 813 attributesKeyValue[attributes[1]] = this.htmlDecode(attributes[2]); 814 } 815 816 currentSearchData['searchData'] = attributesKeyValue; 817 collectedData.push(currentSearchData); 818 } 819 820 return collectedData; 821}; 822 823SGPBPopup.prototype.replaceWithCustomShortcode = function(popupId) 824{ 825 var currentHtmlContent = jQuery('.sgpb-content-'+popupId).html(); 826 var searchData = this.getSearchDataFromContent(currentHtmlContent); 827 828 var that = this; 829 830 if (!searchData.length) { 831 return false; 832 } 833 834 for (var index in searchData) { 835 var currentSearchData = searchData[index]; 836 var searchAttributes = currentSearchData['searchData']; 837 838 if (typeof searchAttributes['selector'] == 'undefined' || typeof searchAttributes['attribute'] == 'undefined') { 839 that.replaceShortCode(currentSearchData['replaceString'], ''); 840 continue; 841 } 842 843 try { 844 if (!jQuery(searchAttributes['selector']).length) { 845 that.replaceShortCode(currentSearchData['replaceString'], ''); 846 continue; 847 } 848 } 849 catch (e) { 850 that.replaceShortCode(currentSearchData['replaceString'], ''); 851 continue; 852 } 853 854 var replaceName = jQuery(searchAttributes['selector']).attr(searchAttributes['attribute']); 855 856 if (typeof replaceName == 'undefined') { 857 that.replaceShortCode(currentSearchData['replaceString'], ''); 858 continue; 859 } 860 861 that.replaceShortCode(currentSearchData['replaceString'], replaceName, popupId); 862 } 863}; 864 865SGPBPopup.prototype.replaceShortCode = function(shortCode, replaceText, popupId) 866{ 867 var popupId = parseInt(popupId); 868 869 if (!popupId) { 870 return false;
871 } 872 873 var popupContentWrapper = jQuery('.sgpb-content-' + popupId); 874 875 if (!popupContentWrapper.length) { 876 return false; 877 } 878 879 popupContentWrapper.find('div').each(function() { 880 var currentHtmlContent = jQuery(this).contents(); 881 882 if (!currentHtmlContent.length) { 883 return false; 884 } 885 886 for (var index in currentHtmlContent) { 887 var currentChild = currentHtmlContent[index]; 888 var currentChildNodeValue = currentChild.nodeValue; 889 var currentChildNodeType = currentChild.nodeType; 890 891 if (currentChildNodeType != Node.TEXT_NODE) { 892 continue; 893 } 894 895 if (currentChildNodeValue.indexOf(shortCode) != -1) { 896 currentChild.nodeValue = currentChildNodeValue.replace(shortCode, replaceText); 897 } 898 } 899 }); 900 901 return true; 902}; 903 904SGPBPopup.prototype.popupTriggeringListeners = function() 905{ 906 var that = this; 907 var popupData = this.getPopupData(); 908 var popupConfig = this.getPopupConfig(); 909 910 sgAddEvent(window, 'sgpbDidOpen', function(e) { 911 var args = e.detail; 912 that.formSubmissionDetection(args); 913 var popupOptions = args.popupData; 914 /* if no analytics extension */ 915 if (typeof SGPB_ANALYTICS_PARAMS == 'undefined') { 916 if (that.getCountPopupOpen()) { 917 that.addToCounter(popupOptions); 918 } 919 } 920 921 var closeButtonDelay = parseInt(popupOptions['sgpb-close-button-delay']); 922 if (closeButtonDelay) { 923 that.closeButtonDisplay(popupOptions['sgpb-post-id'], 'show', closeButtonDelay); 924 } 925 var disablePageScrolling = popupOptions['sgpb-disable-page-scrolling']; 926 if (popupOptions['sgpb-overlay-color']) { 927 jQuery('.sgpb-theme-1-overlay').css({'background-image': 'none'}); 928 } 929 if (SGPBPopup.varToBool(disablePageScrolling)) { 930 jQuery('html, body').addClass('sgpb-overflow-hidden'); 931 } 932 }); 933 934 sgAddEvent(window, 'sgpbWillOpen', function(e) { 935 var args = e.detail; 936 var popupId = parseInt(args['popupId']); 937 that.htmlIframeFilterForOpen(args.popupId, 'open'); 938 that.replaceWithCustomShortcode(popupId); 939 that.sgpbDontShowPopup(popupId); 940 var autoCloseStatus = SGPBPopup.varToBool(popupData['sgpb-auto-close']); 941 var closeButtonDelay = parseInt(popupData['sgpb-close-button-delay']); 942 if (closeButtonDelay) { 943 that.closeButtonDisplay(popupData['sgpb-post-id'], 'hide'); 944 } 945 if (autoCloseStatus) { 946 var autoCloseTime = parseInt(popupData['sgpb-auto-close-time'])*1000; 947 setTimeout(function() { 948 SGPBPopup.closePopupById(that.getPopupId()); 949 }, autoCloseTime); 950 } 951 }); 952 953 sgAddEvent(window, 'sgpbShouldClose', function(e) { 954 955 }); 956 957 sgAddEvent(window, 'sgpbWillClose', function(e) { 958 var args = e.detail; 959 that.htmlIframeFilterForOpen(args.popupId, 'close'); 960 SGPBPopup.offPopup(e.detail.currentObj); 961 }); 962}; 963 964SGPBPopup.prototype.sgpbDontShowPopup = function(popupId) 965{ 966 var dontShowPopup = jQuery('.sgpb-content-' + popupId).parent().find('[class*="sg-popup-dont-show"]'); 967 if (!dontShowPopup.length) { 968 return false; 969 } 970 971 dontShowPopup.each(function() { 972 jQuery(this).bind('click', function(e) { 973 e.preventDefault(); 974 var expireTime = SGPB_POPUP_PARAMS.dontShowPopupExpireTime; 975 var cookieName = 'sgDontShowPopup' + popupId; 976 var classNameSearch = jQuery(this).attr('class').match(/sg-popup-dont-show/); 977 var className = classNameSearch['input']; 978 var customExpireTime = className.match(/sg-popup-dont-show-(\d+$)/); 979 980 if (customExpireTime) { 981 expireTime = parseInt(customExpireTime[1]); 982 } 983 984 SGPBPopup.setCookie(cookieName, expireTime, expireTime); 985 SGPBPopup.closePopupById(popupId); 986 }); 987 }); 988} 989 990SGPBPopup.prototype.addToCounter = function(popupOptions) 991{ 992 if (SGPB_POPUP_PARAMS.isPreview != '') { 993 return false; 994 } 995 var params = {}; 996 var popupId = parseInt(popupOptions['sgpb-post-id']); 997 params.popupId = popupId; 998 999 var data = { 1000 action: 'sgpb_send_to_open_counter', 1001 nonce: SGPB_JS_PARAMS.nonce, 1002 params: params 1003 }; 1004 1005 jQuery.post(SGPB_JS_PARAMS.ajaxUrl, data, function(res) { 1006 1007 }); 1008}; 1009 1010/* 1011 * closeButtonDisplay() 1012 * close or hide close button 1013 * @param popupId 1014 * @param display 1015 * @param delay 1016 */ 1017 1018SGPBPopup.prototype.closeButtonDisplay = function(popupId, display, delay) 1019{ 1020 if (display == 'show') { 1021 setTimeout(function() { 1022 jQuery('.sgpb-content-' + popupId).prev().show(); 1023 }, 1024 delay * 1000 /* received values covert to milliseconds */ 1025 ); 1026 } 1027 else if (display == 'hide') { 1028 jQuery('.sgpb-content-' + popupId).prev().hide(); 1029 } 1030}; 1031 1032SGPBPopup.prototype.open = function(args) 1033{ 1034 var config = this.getPopupConfig(); 1035 var popupId = this.getPopupId(); 1036 var eventName = this.eventName; 1037 1038 if (typeof window.sgPopupBuilder == 'undefined') { 1039 window.sgPopupBuilder = []; 1040 } 1041 var popupData = SGPBPopup.getPopupWindowDataById(popupId); 1042 1043 if (!popupData) { 1044 window.SGPB_ORDER += 1; 1045 var currentObj = { 1046 'eventName': eventName, 1047 'popupId': popupId, 1048 'order': window.SGPB_ORDER, 1049 'isOpen': true 1050 }; 1051 config.currentObj = currentObj; 1052 var popupConfig = config.combineConfigObj(); 1053 var popup = new SGPopup(popupConfig); 1054 currentObj.popup = popup; 1055 window.sgPopupBuilder.push(currentObj); 1056 } 1057 else { 1058 popup = popupData['popup']; 1059 popupData['isOpen'] = true; 1060 } 1061 1062 if (typeof args != 'undefined' && !args['countPopupOpen']) { 1063 /* don't allow to count popup opening */ 1064 this.setCountPopupOpen(false); 1065 } 1066 popup.open(); 1067 this.setPopupObj(popup); 1068 1069 /* contact form 7 form submission 1070 * TODO: this must be moved to a better place in the future 1071 * I'm leaving it here for now, since sgpbDidOpen() gets called way too much! 1072 */ 1073 var options = SGPBPopup.getPopupOptionsById(popupId); 1074 if (typeof options['sgpb-behavior-after-special-events'] != 'undefined') { 1075 if (options['sgpb-behavior-after-special-events'].length) { 1076 options = options['sgpb-behavior-after-special-events'][0][0]; 1077 if (options['param'] == 'contact-form-7') { 1078 SgpbEventListener.processCF7MailSent(popupId, options); 1079 } 1080 } 1081 } 1082}; 1083 1084SGPBPopup.varToBool = function(optionName) 1085{ 1086 var returnValue = optionName ? true : false;
1087 1088 return returnValue; 1089}; 1090 1091SGPBPopup.hexToRgba = function(hex, opacity) 1092{ 1093 var c; 1094 if (/^#([A-Fa-f0-9]{3}){1,2}$/.test(hex)){ 1095 c = hex.substring(1).split(''); 1096 1097 if (c.length == 3){ 1098 c= [c[0], c[0], c[1], c[1], c[2], c[2]]; 1099 } 1100 c = '0x'+c.join(''); 1101 return 'rgba('+[(c>>16)&255, (c>>8)&255, c&255].join(',')+','+opacity+')'; 1102 } 1103 throw new Error('Bad Hex'); 1104}; 1105 1106SGPBPopup.prototype.contentCopyToClick = function() 1107{ 1108 var popupData = this.getPopupData(); 1109 var popupId = this.getPopupId(); 1110 var textAreaId = 'content-copy-to-click-'+popupId; 1111 1112 var value = this.htmlDecode(popupData['sgpb-copy-to-clipboard-text']); 1113 var textArea = jQuery('<textarea>', { 1114 id: textAreaId, 1115 value: value, 1116 style: 'position: absolute; right: -10000px' 1117 }); 1118 1119 if (!jQuery('#'+textAreaId).length) { 1120 jQuery('body').append(textArea); 1121 } 1122 jQuery('#'+textAreaId).select(); 1123 document.execCommand('copy'); 1124 jQuery('#'+textAreaId).remove(); 1125}; 1126 1127SGPBPopup.prototype.htmlDecode = function(value) 1128{ 1129 return jQuery('<textarea/>').html(value).text(); 1130}; 1131 1132SGPBPopup.prototype.findTargetInsideExceptionsList = function(targetName, exceptionList) 1133{ 1134 var status = false; 1135 var popupContentMainDiv = document.getElementById('sgpb-popup-dialog-main-div'); 1136 1137 while (targetName.parentNode) { 1138 targetName = targetName.parentNode; 1139 if (typeof targetName.tagName == 'undefined') { 1140 continue; 1141 } 1142 var tagName = targetName.tagName.toLowerCase(); 1143 if (targetName === popupContentMainDiv) { 1144 break; 1145 } 1146 if (exceptionList.indexOf(tagName) != -1) { 1147 status = true; 1148 break; 1149 } 1150 } 1151 1152 return status; 1153}; 1154 1155SGPBPopup.prototype.contentCloseBehavior = function() 1156{ 1157 var that = this; 1158 var popupData = this.getPopupData(); 1159 var popupId = this.getPopupId(); 1160 var redirectUrl = popupData['sgpb-click-redirect-to-url']; 1161 var contentClickBehavior = popupData['sgpb-content-click-behavior']; 1162 var redirectToNewTab = SGPBPopup.varToBool(popupData['sgpb-redirect-to-new-tab']); 1163 var closePopupAfterCopy = SGPBPopup.varToBool(popupData['sgpb-copy-to-clipboard-close-popup']); 1164 var clipboardAlert = SGPBPopup.varToBool(popupData['sgpb-copy-to-clipboard-alert']); 1165 1166 sgAddEvent(window, 'sgpbDidOpen', function(e) { 1167 1168 }); 1169 1170 sgAddEvent(window, 'sgpbWillOpen', function(e) { 1171 if (popupId != e.detail.popupId || e.detail.popupData['sgpb-content-click'] == 'undefined') { 1172 return false; 1173 } 1174 jQuery('.sgpb-content-'+e.detail.popupId).on('click', function(event) { 1175 if (contentClickBehavior == 'redirect') { 1176 if (redirectToNewTab) { 1177 window.open(redirectUrl); 1178 SGPBPopup.closePopupById(that.getPopupId()); 1179 return; 1180 } 1181 window.location = redirectUrl; 1182 SGPBPopup.closePopupById(that.getPopupId()); 1183 } 1184 else if (contentClickBehavior == 'copy') { 1185 var exceptionList = ['input', 'textarea', 'select', 'button', 'a']; 1186 var targetName = event.target.tagName.toLowerCase(); 1187 var parentTagName = event.target.parentNode.tagName.toLowerCase(); 1188 var parentsIsInExceptionsList = that.findTargetInsideExceptionsList(event.target, exceptionList); 1189 1190 /*for do not copy when user click to any input element*/ 1191 if (exceptionList.indexOf(targetName) == -1 && !parentsIsInExceptionsList) { 1192 that.contentCopyToClick(); 1193 1194 if (closePopupAfterCopy) { 1195 SGPBPopup.closePopupById(that.getPopupId()); 1196 } 1197 if (clipboardAlert) { 1198 alert(popupData['sgpb-copy-to-clipboard-message']) 1199 } 1200 } 1201 } 1202 else if (popupData['sgpb-disable-popup-closing'] != 'on') { 1203 SGPBPopup.closePopupById(that.getPopupId()); 1204 } 1205 }); 1206 }); 1207 1208 sgAddEvent(window, 'sgpbDidClose', function(e) { 1209 1210 }); 1211}; 1212 1213SGPBPopup.prototype.addFixedPosition = function() 1214{ 1215 var popupData = this.getPopupData(); 1216 var popupId = this.getPopupId(); 1217 var popupConfig = this.getPopupConfig(); 1218 1219 var fixedPosition = popupData['sgpb-popup-fixed-position']; 1220 var positionRight = ''; 1221 var positionTop = ''; 1222 var positionBottom = ''; 1223 var positionLeft = ''; 1224 1225 if (fixedPosition == 1) { 1226 positionTop = 40; 1227 positionLeft = 20; 1228 } 1229 else if (fixedPosition == 2) { 1230 positionLeft = 'center'; 1231 positionTop = 40; 1232 } 1233 else if (fixedPosition == 3) { 1234 positionTop = 40; 1235 positionRight = 20; 1236 } 1237 else if (fixedPosition == 4) { 1238 positionTop = 'center'; 1239 positionLeft = 20; 1240 } 1241 else if (fixedPosition == 6) { 1242 positionTop = 'center'; 1243 positionRight = 20; 1244 } 1245 else if (fixedPosition == 7) { 1246 positionLeft = 20; 1247 positionBottom = 2; 1248 } 1249 else if (fixedPosition == 8) { 1250 positionLeft = 'center'; 1251 positionBottom = 2; 1252 } 1253 else if (fixedPosition == 9) { 1254 positionRight = 20; 1255 positionBottom = 2; 1256 } 1257 1258 if (typeof SgpbRecentSalesPopupType != 'undefined') { 1259 if (popupData['sgpb-type'] == SgpbRecentSalesPopupType) { 1260 if (positionTop != '') { 1261 positionTop = parseInt(positionTop+10); 1262 } 1263 else if (positionBottom != '') { 1264 positionBottom = parseInt(positionBottom+10); 1265 } 1266 } 1267 } 1268 popupConfig.magicCall('setPositionTop', positionTop); 1269 popupConfig.magicCall('setPositionRight', positionRight); 1270 popupConfig.magicCall('setPositionBottom', positionBottom); 1271 popupConfig.magicCall('setPositionLeft', positionLeft); 1272}; 1273 1274SGPBPopup.prototype.setPopupDimensions = function() 1275{ 1276 var popupData = this.getPopupData(); 1277 var popupConfig = this.getPopupConfig(); 1278 var popupId = this.getPopupId(); 1279 var dimensionData = popupData['sgpb-popup-dimension-mode']; 1280 var maxWidth = popupData['sgpb-max-width']; 1281 var maxHeight = popupData['sgpb-max-height']; 1282 var minWidth = popupData['sgpb-min-width']; 1283 var minHeight = popupData['sgpb-min-height']; 1284 var contentPadding = popupData['sgpb-content-padding']; 1285 var popupType = popupData['sgpb-type']; 1286 1287 popupConfig.magicCall('setMaxWidth', maxWidth); 1288 popupConfig.magicCall('setMaxHeight', maxHeight); 1289 popupConfig.magicCall('setMinWidth', minWidth); 1290 popupConfig.magicCall('setMinHeight', minHeight); 1291 1292 if (popupType == 'image') { 1293 if (popupData['sgpb-image-data']) {
1294 popupConfig.magicCall('setContentBackgroundImage', 'data:image/png;base64,'+popupData['sgpb-image-data']); 1295 } 1296 else { 1297 popupConfig.magicCall('setContentBackgroundImage', popupData['sgpb-image-url']); 1298 } 1299 popupConfig.magicCall('setContentBackgroundMode', 'contain'); 1300 } 1301 if (dimensionData == 'responsiveMode') { 1302 /* for image popup type and responsive mode, set background image to fit */ 1303 if (popupType == 'image') { 1304 popupConfig.magicCall('setContentBackgroundMode', 'fit'); 1305 } 1306 1307 var dimensionMeasure = popupData['sgpb-responsive-dimension-measure']; 1308 var popupConfig = this.getPopupConfig(); 1309 1310 if (dimensionMeasure != 'auto') { 1311 popupConfig.magicCall('setWidth', dimensionMeasure+'%'); 1312 } 1313 else { 1314 popupConfig.magicCall('setWidth', jQuery('.sgpb-popup-builder-content-'+popupId).width() + (contentPadding*2) + 'px'); 1315 } 1316 1317 return popupConfig; 1318 } 1319 1320 var popupWidth = popupData['sgpb-width']; 1321 var popupHeight = popupData['sgpb-height']; 1322 1323 popupConfig.magicCall('setWidth', popupWidth); 1324 popupConfig.magicCall('setHeight', popupHeight); 1325 1326 return popupConfig; 1327}; 1328 1329SGPBPopup.b64DecodeUnicode = function(str) 1330{ 1331 var Base64 = { 1332 1333 /* private property */ 1334 _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", 1335 1336 /* public method for decoding */ 1337 decode : function (input) { 1338 var output = ""; 1339 var chr1, chr2, chr3; 1340 var enc1, enc2, enc3, enc4; 1341 var i = 0; 1342 1343 input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); 1344 1345 while (i < input.length) { 1346 enc1 = this._keyStr.indexOf(input.charAt(i++)); 1347 enc2 = this._keyStr.indexOf(input.charAt(i++)); 1348 enc3 = this._keyStr.indexOf(input.charAt(i++)); 1349 enc4 = this._keyStr.indexOf(input.charAt(i++)); 1350 1351 chr1 = (enc1 << 2) | (enc2 >> 4); 1352 chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); 1353 chr3 = ((enc3 & 3) << 6) | enc4; 1354 1355 output = output + String.fromCharCode(chr1); 1356 1357 if (enc3 != 64) { 1358 output = output + String.fromCharCode(chr2); 1359 } 1360 if (enc4 != 64) { 1361 output = output + String.fromCharCode(chr3); 1362 } 1363 1364 } 1365 1366 output = Base64._utf8_decode(output); 1367 1368 return output; 1369 1370 }, 1371 1372 /* private method for UTF-8 decoding */ 1373 _utf8_decode : function (utftext) { 1374 var string = ""; 1375 var i = 0; 1376 var c = c1 = c2 = 0; 1377 1378 while (i < utftext.length) { 1379 1380 c = utftext.charCodeAt(i); 1381 1382 if (c < 128) { 1383 string += String.fromCharCode(c); 1384 i++; 1385 } 1386 else if ((c > 191) && (c < 224)) { 1387 c2 = utftext.charCodeAt(i+1); 1388 string += String.fromCharCode(((c & 31) << 6) | (c2 & 63)); 1389 i += 2; 1390 } 1391 else { 1392 c2 = utftext.charCodeAt(i+1); 1393 c3 = utftext.charCodeAt(i+2); 1394 string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); 1395 i += 3; 1396 } 1397 } 1398 1399 return string; 1400 } 1401 }; 1402 1403 return Base64.decode(str); 1404}; 1405 1406SGPBPopup.unserialize = function(data) 1407{ 1408 data = SGPBPopup.b64DecodeUnicode(data); 1409 1410 var $global = (typeof window !== 'undefined' ? window : global); 1411 1412 var utf8Overhead = function(str) { 1413 var s = str.length; 1414 for (var i = str.length - 1; i >= 0; i--) { 1415 var code = str.charCodeAt(i) 1416 if (code > 0x7f && code <= 0x7ff) { 1417 s++; 1418 } 1419 else if (code > 0x7ff && code <= 0xffff) { 1420 s += 2; 1421 } 1422 /* trail surrogate */ 1423 if (code >= 0xDC00 && code <= 0xDFFF) { 1424 i--; 1425 } 1426 } 1427 return s - 1; 1428 } 1429 1430 var error = function(type, msg, filename, line) { 1431 throw new $global[type](msg, filename, line); 1432 } 1433 var readUntil = function(data, offset, stopchr) { 1434 var i = 2; 1435 var buf = []; 1436 var chr = data.slice(offset, offset + 1); 1437 1438 while (chr !== stopchr) { 1439 if ((i + offset) > data.length) { 1440 error('Error', 'Invalid'); 1441 } 1442 buf.push(chr); 1443 chr = data.slice(offset + (i - 1), offset + i); 1444 i += 1; 1445 } 1446 return [buf.length, buf.join('')]; 1447 } 1448 var readChrs = function(data, offset, length) { 1449 var i, chr, buf 1450 1451 buf = [] 1452 for (i = 0; i < length; i++) { 1453 chr = data.slice(offset + (i - 1), offset + i); 1454 buf.push(chr); 1455 length -= utf8Overhead(chr); 1456 } 1457 return [buf.length, buf.join('')]; 1458 } 1459 function _unserialize(data, offset) { 1460 var dtype 1461 var dataoffset 1462 var keyandchrs 1463 var keys 1464 var contig 1465 var length 1466 var array 1467 var readdata 1468 var readData 1469 var ccount 1470 var stringlength 1471 var i 1472 var key 1473 var kprops 1474 var kchrs 1475 var vprops 1476 var vchrs 1477 var value 1478 var chrs = 0 1479 var typeconvert = function(x) { 1480 return x 1481 } 1482 1483 if (!offset) { 1484 offset = 0 1485 } 1486 dtype = (data.slice(offset, offset + 1)).toLowerCase() 1487 1488 dataoffset = offset + 2 1489 1490 switch (dtype) { 1491 case 'i': 1492 typeconvert = function(x) { 1493 return parseInt(x, 10); 1494 } 1495 readData = readUntil(data, dataoffset, ';'); 1496 chrs = readData[0]; 1497 readdata = readData[1]; 1498 dataoffset += chrs + 1; 1499 break; 1500 case 'b': 1501 typeconvert = function(x) { 1502 return parseInt(x, 10) !== 0; 1503 } 1504 readData = readUntil(data, dataoffset, ';'); 1505 chrs = readData[0]; 1506 readdata = readData[1]; 1507 dataoffset += chrs + 1; 1508 break; 1509 case 'd': 1510 typeconvert = function(x) { 1511 return parseFloat(x); 1512 } 1513 readData = readUntil(data, dataoffset, ';'); 1514 chrs = readData[0]; 1515 readdata = readData[1]; 1516 dataoffset += chrs + 1; 1517 break; 1518 case 'n': 1519 readdata = null 1520 break 1521 case 's': 1522 ccount = readUntil(data, dataoffset, ':') 1523 chrs = ccount[0] 1524 stringlength = ccount[1] 1525 dataoffset += chrs + 2 1526 1527 readData = readChrs(data, dataoffset + 1, parseInt(stringlength, 10)) 1528 chrs = readData[0] 1529 readdata = readData[1] 1530 dataoffset += chrs + 2 1531 if (chrs !== parseInt(stringlength, 10) && chrs !== readdata.length) { 1532 error('SyntaxError', 'String length mismatch') 1533 } 1534 break; 1535 case 'a': 1536 readdata = {}; 1537 1538 keyandchrs = readUntil(data, dataoffset, ':'); 1539 chrs = keyandchrs[0]; 1540 keys = keyandchrs[1]; 1541 dataoffset += chrs + 2; 1542 1543 length = parseInt(keys, 10); 1544 contig = true; 1545 1546 for (i = 0; i < length; i++) { 1547 kprops = _unserialize(data, dataoffset); 1548 kchrs = kprops[1]; 1549 key = kprops[2]; 1550 dataoffset += kchrs; 1551 1552 vprops = _unserialize(data, dataoffset); 1553 vchrs = vprops[1]; 1554 value = vprops[2]; 1555 dataoffset += vchrs; 1556 1557 if (key !== i) { 1558 contig = false;
1559 } 1560 1561 readdata[key] = value; 1562 } 1563 1564 if (contig) { 1565 array = new Array(length) 1566 for (i = 0; i < length; i++) { 1567 array[i] = readdata[i]; 1568 } 1569 readdata = array; 1570 } 1571 1572 dataoffset += 1; 1573 break; 1574 default: 1575 error('SyntaxError', 'Unknown / Unhandled data type(s): ' + dtype); 1576 break; 1577 } 1578 1579 return [dtype, dataoffset - offset, typeconvert(readdata)] 1580 } 1581 1582 return _unserialize((data + ''), 0)[2]; 1583}; 1584 1585SGPBPopup.closePopup = function() 1586{ 1587 var popupObjs = window.sgPopupBuilder; 1588 var lastPopupObj = this.getLastPopup(); 1589 1590 if (typeof lastPopupObj == 'undefined') { 1591 return false; 1592 } 1593 1594 var popupId = lastPopupObj.popupId; 1595 1596 SGPBPopup.closePopupById(popupId); 1597}; 1598 1599SGPBPopup.closePopupById = function(popupId) 1600{ 1601 var popupObjs = window.sgPopupBuilder; 1602 if (!popupObjs.length) { 1603 return; 1604 } 1605 1606 for (var i in popupObjs) { 1607 1608 var currentObj = popupObjs[i]; 1609 1610 if (currentObj.popupId == popupId) { 1611 var popupObj = popupObjs[i]['popup']; 1612 if (popupObj) { 1613 /*Send true argument to don’t count disable popup option*/ 1614 popupObj.close(true); 1615 } 1616 } 1617 } 1618}; 1619 1620SGPBPopup.getPopupWindowDataById = function(popupId) 1621{ 1622 var popups = window.sgPopupBuilder; 1623 var popup = false; 1624 1625 if (typeof popups == 'undefined' || !popups.length) { 1626 return popup; 1627 } 1628 1629 for (var i in popups) { 1630 var popupData = popups[i]; 1631 1632 if (popupData.popupId == popupId) { 1633 popup = popupData; 1634 break; 1635 } 1636 } 1637 1638 return popup; 1639}; 1640 1641SGPBPopup.findPopupObjById = function(popupId) 1642{ 1643 var popup = false; 1644 var popupData = SGPBPopup.getPopupWindowDataById(popupId); 1645 1646 if (popupData) { 1647 popup = popupData['popup']; 1648 } 1649 1650 return popup; 1651}; 1652 1653SGPBPopup.getLastPopup = function() 1654{ 1655 var popups = window.sgPopupBuilder; 1656 var popup = false; 1657 1658 if (!popups.length) { 1659 return popup; 1660 } 1661 1662 var searchPopups = [].concat(popups); 1663 1664 for (var i in searchPopups) { 1665 var popupData = searchPopups[i]; 1666 1667 if (popupData.isOpen) { 1668 popup = popupData; 1669 break; 1670 } 1671 } 1672 1673 return popup; 1674}; 1675 1676SGPBPopup.offPopup = function(currentPopup) 1677{ 1678 var popups = window.sgPopupBuilder; 1679 1680 if (!popups.length) { 1681 return false; 1682 } 1683 1684 for (var i in popups) { 1685 var popupData = popups[i]; 1686 1687 if (popupData.order == currentPopup.order && popupData.eventName == currentPopup.eventName) { 1688 popups[i]['isOpen'] = false; 1689 break; 1690 } 1691 } 1692 1693 return true; 1694}; 1695 1696SGPBPopup.capitalizeFirstLetter = function(string) 1697{ 1698 return string.charAt(0).toUpperCase() + string.slice(1); 1699}; 1700 1701SGPBPopup.getParamFromUrl = function(param) 1702{ 1703 var url = window.location.href; 1704 param = param.replace(/[\[\]]/g, "\\$&"); 1705 var regex = new RegExp("[?&]" + param + "(=([^&#]*)|&|#|$)"), 1706 results = regex.exec(url); 1707 if (!results) { 1708 return null; 1709 } 1710 if (!results[2]) { 1711 return ''; 1712 } 1713 return decodeURIComponent(results[2].replace(/\+/g, " ")); 1714}; 1715 1716/* 1717 * 1718 * SGPBPopup Cookies' settings 1719 * 1720 */ 1721 1722SGPBPopup.setCookie = function(cName, cValue, exDays, cPageLevel) 1723{ 1724 var isPreview = SGPBPopup.getParamFromUrl('preview'); 1725 if (isPreview) { 1726 return false; 1727 } 1728 var expirationDate = new Date(); 1729 var cookiePageLevel = 'path=/;'; 1730 var cookieExpirationData = 1; 1731 if (!exDays || isNaN(exDays)) { 1732 exDays = 365*50; 1733 } 1734 if (typeof cPageLevel == 'undefined') { 1735 cPageLevel = false; 1736 } 1737 1738 expirationDate.setDate(parseInt(expirationDate.getDate() + parseInt(exDays))); 1739 cookieExpirationData = expirationDate.toString(); 1740 var expires = 'expires='+cookieExpirationData; 1741 1742 if (exDays == -1) { 1743 expires = ''; 1744 } 1745 1746 if (cPageLevel) { 1747 cookiePageLevel = 'path=' + cPageLevel + ';'; 1748 } 1749 1750 var value = cValue+((exDays == null) ? ';' : '; '+expires+';'+cookiePageLevel); 1751 document.cookie = cName + '=' + value; 1752}; 1753 1754SGPBPopup.getCookie = function(cName) 1755{ 1756 var name = cName + '='; 1757 var ca = document.cookie.split(';'); 1758 for (var i = 0; i < ca.length; i++) { 1759 var c = ca[i]; 1760 while (c.charAt(0) == ' ') { 1761 c = c.substring(1); 1762 } 1763 if (c.indexOf(name) == 0) { 1764 return c.substring(name.length, c.length); 1765 } 1766 } 1767 1768 return ''; 1769}; 1770 1771/* 1772 * 1773 * Delete the cookie by expiring it 1774 * 1775 */ 1776 1777SGPBPopup.deleteCookie = function(cName, cPath) 1778{ 1779 if (!cPath) { 1780 cPath = 'path=/;'; 1781 } 1782 1783 document.cookie = cName + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;' + cPath; 1784}; 1785 1786/** 1787 * 1788 * @SgpbEventListener listen Events and call corresponding events 1789 * 1790 * 1791 * 1792 * 1793 * 1794 * 1795 * 1796 * 1797 * 1798 */ 1799 1800function SgpbEventListener() 1801{
1802 this.evenets = null; 1803 this.popupObj = {}; 1804} 1805 1806SgpbEventListener.inactivityIdicator = 0; 1807 1808SgpbEventListener.prototype.setEvents = function(events) 1809{ 1810 this.evenets = events; 1811}; 1812 1813SgpbEventListener.prototype.getEvents = function() 1814{ 1815 return this.evenets; 1816}; 1817 1818SgpbEventListener.prototype.setPopupObj = function(popupObj) 1819{ 1820 this.popupObj = popupObj; 1821}; 1822 1823SgpbEventListener.prototype.getPopupObj = function() 1824{ 1825 return this.popupObj; 1826}; 1827 1828SgpbEventListener.init = function() 1829{ 1830 var popupsData = jQuery('.sg-popup-builder-content'); 1831 1832 if (!popupsData) { 1833 return ''; 1834 } 1835 1836 var that = this; 1837 1838 popupsData.each(function() { 1839 that.popupObjCreator(jQuery(this)); 1840 }); 1841 1842}; 1843 1844SgpbEventListener.popupObjCreator = function(currentData) 1845{ 1846 var popupId = currentData.data('id'); 1847 var popupData = currentData.data('options'); 1848 1849 var events = currentData.attr('data-events'); 1850 events = jQuery.parseJSON(events); 1851 1852 SgpbEventListener.reopenAfterFormSubmission(popupData); 1853 1854 var popupObj = new SGPBPopup(); 1855 popupObj.setPopupId(popupId); 1856 popupObj.setPopupData(popupData); 1857 1858 for (var i in events) { 1859 var obj = new this; 1860 obj.setPopupObj(popupObj); 1861 obj.eventListener(events[i]); 1862 } 1863 1864}; 1865 1866SgpbEventListener.prototype.eventListener = function(eventData) 1867{ 1868 if (eventData == null) { 1869 return ''; 1870 } 1871 var event = ''; 1872 if (typeof eventData == 'string') { 1873 event = eventData; 1874 } 1875 else if (typeof eventData.param != 'undefined') { 1876 event = eventData.param; 1877 } 1878 1879 if (!event) { 1880 return false; 1881 } 1882 1883 var popupObj = this.getPopupObj(); 1884 var popupData = popupObj.getPopupData(); 1885 1886 if (eventData.value == '') { 1887 eventData.value = popupData['sgpb-popup-delay']; 1888 } 1889 1890 var eventName = SGPBPopup.capitalizeFirstLetter(event); 1891 1892 eventName = 'sgpb'+eventName; 1893 popupObj.eventName = eventName; 1894 1895 try { 1896 eval('this.'+eventName)(this, eventData); 1897 } 1898 catch (err) { 1899 console.log(err) 1900 } 1901 1902}; 1903 1904SgpbEventListener.reopenAfterFormSubmission = function(eventData) 1905{ 1906 var popupId = SGPBPopup.getCookie('SGPBSubmissionReloadPopup'); 1907 popupId = parseInt(popupId); 1908 1909 if (!popupId) { 1910 return false; 1911 } 1912 var popupObj = SGPBPopup.createPopupObjById(popupId); 1913 if (!popupObj) { 1914 return false; 1915 } 1916 var options = popupObj.getPopupData(); 1917 1918 if (!options['sgpb-reopen-after-form-submission']) { 1919 return false; 1920 } 1921 1922 popupObj.prepareOpen(); 1923 SGPBPopup.deleteCookie('SGPBSubmissionReloadPopup'); 1924}; 1925 1926SgpbEventListener.prototype.sgpbLoad = function(listenerObj, eventData) 1927{ 1928 var timeout = parseInt(eventData.value); 1929 var popupObj = listenerObj.getPopupObj(); 1930 timeout = timeout*1000; 1931 var timerId, 1932 repetitiveTimeout = null; 1933 1934 sgAddEvent(window, 'load', function() { 1935 clearInterval(timerId); 1936 timerId = setTimeout(function() { 1937 popupObj.prepareOpen(); 1938 }, timeout); 1939 }); 1940 sgAddEvent(window, 'sgpbDidOpen', function(e) { 1941 var args = e.detail; 1942 clearInterval(repetitiveTimeout); 1943 }); 1944 1945 sgAddEvent(window, 'sgpbDidClose', function(e) { 1946 var args = e.detail; 1947 var options = popupObj.getPopupData(); 1948 1949 if (SGPBPopup.varToBool(eventData['repetitive'])) { 1950 var intervalTime = parseInt(eventData['value'])*1000; 1951 repetitiveTimeout = setInterval(function() { 1952 popupObj.prepareOpen(); 1953 }, intervalTime); 1954 } 1955 }); 1956}; 1957 1958SgpbEventListener.prototype.timerIncrement = function(listenerObj , idleInterval) 1959{ 1960 var lastActivity = SgpbEventListener.inactivityIdicator; 1961 1962 if (lastActivity == 0) { 1963 clearInterval(idleInterval); 1964 listenerObj.getPopupObj().prepareOpen(); 1965 } 1966 SgpbEventListener.inactivityIdicator = 0; 1967}; 1968 1969SgpbEventListener.prototype.sgpbOnScroll = function(listenerObj, eventData) 1970{ 1971 var that = this; 1972 var percent = parseInt(eventData.value); 1973 var scrollStatus = false; 1974 1975 jQuery(window).on('scroll', function() { 1976 1977 var scrollTop = jQuery(window).scrollTop(); 1978 var docHeight = jQuery(document).height(); 1979 var winHeight = jQuery(window).height(); 1980 var scrollPercent = (scrollTop) / (docHeight - winHeight); 1981 var scrollPercentRounded = Math.round(scrollPercent*100); 1982 if (percent < scrollPercentRounded) { 1983 if (scrollStatus == false) { 1984 listenerObj.getPopupObj().prepareOpen(); 1985 scrollStatus = true; 1986 } 1987 } 1988 }); 1989}; 1990 1991SgpbEventListener.prototype.sgpbInsideclick = function(listenerObj, eventData) 1992{ 1993 sgAddEvent(window, 'sgpbDidOpen', function(e) { 1994 var args = e.detail; 1995 var that = listenerObj; 1996 var popupObj = that.getPopupObj(); 1997 var popupId = parseInt(popupObj.id); 1998 var targetClick = jQuery('.sgpb-content .sgpb-popup-id-'+popupId); 1999 2000 if (!targetClick.length) { 2001 return false;
2002 } 2003 2004 targetClick.each(function() { 2005 jQuery(this).unbind('click').bind('click', function() { 2006 SGPBPopup.closePopup(); 2007 popupObj.prepareOpen(); 2008 }); 2009 }); 2010 }); 2011}; 2012 2013SgpbEventListener.prototype.sgpbClick = function(listenerObj, eventData) 2014{ 2015 var that = listenerObj; 2016 var popupIds = []; 2017 var popupObj = that.getPopupObj(); 2018 var popupOptions = popupObj.getPopupData(); 2019 var popupId = parseInt(popupObj.id); 2020 popupIds.push(popupId); 2021 var mapId = listenerObj.filterPopupId(popupId); 2022 popupIds.push(mapId); 2023 2024 for(var key in popupIds) { 2025 var popupId = popupIds[key]; 2026 if (!popupIds.hasOwnProperty(key)) { 2027 return false; 2028 } 2029 var targetClick = jQuery('a[href*="#sg-popup-id-' + popupId + '"], .sg-popup-id-' + popupId + ', .sgpb-popup-id-' + popupId); 2030 2031 if (typeof eventData.operator != 'undefined' && eventData.operator == 'clickActionCustomClass') { 2032 targetClick = jQuery('a[href*="#sg-popup-id-' + popupId + '"], .sg-popup-id-' + popupId + ', .sgpb-popup-id-' + popupId+', .'+eventData.value); 2033 } 2034 if (!targetClick.length) { 2035 continue; 2036 } 2037 var delay = parseInt(popupOptions['sgpb-popup-delay']) * 1000; 2038 var clickCount = 1; 2039 targetClick.each(function() { 2040 jQuery(this).bind('click', function(e) { 2041 e.preventDefault(); 2042 if (clickCount > 1) { 2043 return false; 2044 } 2045 ++clickCount; 2046 jQuery(window).trigger('sgpbClickEvent', popupOptions); 2047 setTimeout(function() { 2048 popupObj.prepareOpen(); 2049 clickCount = 1; 2050 }, delay); 2051 }); 2052 }); 2053 } 2054}; 2055 2056SgpbEventListener.prototype.sgpbHover = function(listenerObj, eventData) 2057{ 2058 var that = listenerObj; 2059 var popupObj = that.getPopupObj(); 2060 2061 if (!popupObj) { 2062 return false; 2063 } 2064 var popupIds = []; 2065 var popupOptions = popupObj.getPopupData(); 2066 var popupId = parseInt(popupObj.id); 2067 popupIds.push(popupId); 2068 var mapId = listenerObj.filterPopupId(popupId); 2069 popupIds.push(mapId); 2070 2071 for(var key in popupIds) { 2072 var popupId = popupIds[key]; 2073 if (!popupIds.hasOwnProperty(key)) { 2074 return false; 2075 } 2076 2077 var hoverSelector = jQuery('.sg-popup-hover-' + popupId + ', .sgpb-popup-id-' + popupId + '[data-popup-event="hover"]'); 2078 2079 if (typeof eventData.operator != 'undefined' && eventData.operator == 'hoverActionCustomClass') { 2080 hoverSelector = jQuery('.sg-popup-hover-' + popupId + ', .sgpb-popup-id-' + popupId + '[data-popup-event="hover"]'+', .'+eventData.value); 2081 } 2082 2083 if (!hoverSelector) { 2084 return false; 2085 } 2086 var hoverCount = 1; 2087 var delay = parseInt(popupOptions['sgpb-popup-delay']) * 1000; 2088 hoverSelector.bind('hover', function() { 2089 if (hoverCount > 1) { 2090 return false; 2091 } 2092 ++hoverCount; 2093 jQuery(window).trigger('sgpbHoverEvent', popupOptions); 2094 setTimeout(function() { 2095 popupObj.prepareOpen(); 2096 hoverCount = 1; 2097 }, delay); 2098 }); 2099 } 2100}; 2101 2102SgpbEventListener.prototype.sgpbConfirm = function(listenerObj, eventData) 2103{ 2104 var that = listenerObj; 2105 var popupObj = that.getPopupObj(); 2106 2107 if (!popupObj) { 2108 return false; 2109 } 2110 var popupIds = []; 2111 var popupOptions = popupObj.getPopupData(); 2112 var popupId = parseInt(popupObj.id); 2113 popupIds.push(popupId); 2114 var mapId = listenerObj.filterPopupId(popupId); 2115 popupIds.push(mapId); 2116 2117 for(var key in popupIds) { 2118 var popupId = popupIds[key]; 2119 if (!popupIds.hasOwnProperty(key)) { 2120 return false; 2121 } 2122 2123 var confirmSelector = jQuery('.sg-confirm-popup-' + popupId); 2124 2125 if (!confirmSelector) { 2126 return false; 2127 } 2128 var confirmCount = 1; 2129 2130 confirmSelector.bind('click', function(e) { 2131 e.preventDefault(); 2132 2133 if (confirmCount > 1) { 2134 return false; 2135 } 2136 ++confirmCount; 2137 jQuery(window).trigger('sgpbConfirmEvent', popupOptions); 2138 var target = jQuery(this).attr('target'); 2139 2140 if (typeof target == 'undefined') { 2141 target = 'self'; 2142 } 2143 var href = jQuery(this).attr('href'); 2144 var delay = parseInt(popupOptions['sgpb-popup-delay']) * 1000; 2145 setTimeout(function() { 2146 if (typeof href != 'undefined') { 2147 popupOptions['sgpb-confirm-' + popupId] = {'target' : target, 'href' : href}; 2148 popupObj.setPopupData(popupOptions); 2149 } 2150 popupObj.prepareOpen(); 2151 confirmCount = 1; 2152 }, delay); 2153 2154 }); 2155 2156 sgAddEvent(window, 'sgpbDidClose', function(e) { 2157 var args = e.detail; 2158 var popupId = parseInt(args.popupId); 2159 var popupOptions = args.popupData; 2160 2161 if (typeof popupOptions['sgpb-confirm-' + popupId] != 'undefined') { 2162 var confirmAgrs = popupOptions['sgpb-confirm-' + popupId]; 2163 2164 if (confirmAgrs['target'] == '_blank') { 2165 window.open(confirmAgrs['href']); 2166 } 2167 else { 2168 window.location.href = confirmAgrs['href']; 2169 } 2170 2171 delete popupOptions['sgpb-confirm-' + popupId]; 2172 popupObj.setPopupData(popupOptions); 2173 } 2174 }); 2175 } 2176}; 2177 2178SgpbEventListener.prototype.sgpbIframe = function(listenerObj, eventData) 2179{ 2180 var that = listenerObj; 2181 var popupObj = that.getPopupObj(); 2182 var popupId = parseInt(popupObj.id); 2183 popupId = listenerObj.filterPopupId(popupId); 2184 var popupOptions = popupObj.getPopupData();
2185 var iframeCount = 1; 2186 var delay = parseInt(popupOptions['sgpb-popup-delay']) * 1000; 2187 2188 jQuery('.sg-iframe-popup-' + popupId).each(function() { 2189 jQuery(this).bind('click', function(e) { 2190 e.preventDefault(); 2191 2192 var link = jQuery(this).attr('href'); 2193 2194 if (typeof link == 'undefined') { 2195 var childLinkTag = jQuery(this).find('a'); 2196 link = jQuery(this).attr('href'); 2197 2198 if (typeof link == 'undefined') { 2199 return false; 2200 } 2201 } 2202 2203 if (iframeCount > 1) { 2204 return false; 2205 } 2206 ++iframeCount; 2207 jQuery(window).trigger('sgpbIframeEvent', popupOptions); 2208 setTimeout(function() { 2209 popupOptions['sgpb-iframe-' + popupId] = link; 2210 popupObj.setPopupData(popupOptions); 2211 2212 popupObj.prepareOpen(); 2213 var currentIframe = jQuery('.sgpb-popup-builder-content-' + popupId).find('iframe'); 2214 currentIframe.data('attr-src', link); 2215 iframeCount = 1; 2216 return false; 2217 }, delay); 2218 }); 2219 }); 2220}; 2221 2222SgpbEventListener.prototype.sgpbAttronload = function(listenerObj, eventData) 2223{ 2224 var that = listenerObj; 2225 var popupObj = that.getPopupObj(); 2226 var popupId = parseInt(popupObj.id); 2227 popupId = listenerObj.filterPopupId(popupId); 2228 var popupOptions = popupObj.getPopupData(); 2229 var delay = parseInt(popupOptions['sgpb-popup-delay']) * 1000; 2230 jQuery(window).trigger('sgpbAttronloadEvent', popupOptions); 2231 2232 setTimeout(function() { 2233 popupObj.prepareOpen(); 2234 }, delay); 2235}; 2236 2237/*for the old popups*/ 2238SgpbEventListener.prototype.filterPopupId = function(popupId) 2239{ 2240 var convertedIds = SGPB_POPUP_PARAMS.convertedIdsReverse; 2241 2242 if (convertedIds[popupId]) { 2243 return convertedIds[popupId]; 2244 } 2245 2246 return popupId; 2247}; 2248 2249SgpbEventListener.findCF7InPopup = function(popupId) 2250{ 2251 return document.querySelector('#sg-popup-content-wrapper-'+popupId+' .wpcf7'); 2252}; 2253 2254SgpbEventListener.processCF7MailSent = function(popupId, options) 2255{ 2256 var wpcf7Elm = SgpbEventListener.findCF7InPopup(popupId); 2257 2258 if (wpcf7Elm) { 2259 wpcf7Elm.addEventListener('wpcf7mailsent', function(event) { 2260 if (typeof options['operator'] == 'undefined') { 2261 return; 2262 } 2263 2264 if (options['operator'] == 'close-popup') { 2265 setTimeout(function() { 2266 SGPBPopup.closePopupById(popupId); 2267 }, parseInt(options['value'])*1000); 2268 } 2269 else if (options['operator'] == 'redirect-url') { 2270 window.location.href = options['value']; 2271 } 2272 else if (options['operator'] == 'open-popup') { 2273 SGPBPopup.closePopupById(popupId); 2274 var popupObj = SGPBPopup.createPopupObjById(Object.keys(options['value'])[0]); 2275 popupObj.prepareOpen(); 2276 } 2277 }, false); 2278 } 2279}; 2280 2281jQuery(document).ready(function(e) { 2282 SgpbEventListener.init(); 2283});
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.