function sgAddEvent(element, eventName, fn) { if (element.addEventListener) element.addEventListener(eventName, fn, false); else if (element.attachEvent) element.attachEvent('on' + eventName, fn); } /*Popup order count*/ window.SGPB_ORDER = 0; function SGPBPopup() { this.id = null; this.eventName = ''; this.popupData = null; this.additionalPopupData = {}; this.popupConfig = {}; this.popupObj = null; this.onceListener(); this.initialsListeners(); this.countPopupOpen = true; this.closeButtonDefaultPositions = {}; this.closeButtonDefaultPositions[1] = { 'left': 9, 'right': 9, 'bottom': 9 }; this.closeButtonDefaultPositions[2] = { 'left': 0, 'right': 0, 'top': parseInt('-20'), 'bottom': parseInt('-20') }; this.closeButtonDefaultPositions[3] = { 'right': 4, 'bottom': 4, 'left': 4, 'top': 4 }; this.closeButtonDefaultPositions[4] = { 'left': 12, 'right': 12, 'bottom': 9 }; this.closeButtonDefaultPositions[5] = { 'left': 8, 'right': 8, 'bottom': 8 }; this.closeButtonDefaultPositions[6] = { 'left': parseInt('-18.5'), 'right': parseInt('-18.5'), 'bottom': parseInt('-18.5'), 'top': parseInt('-18.5') }; } SGPBPopup.htmlCustomButton = function() { var buttons = jQuery('.sgpb-html-custom-button'); var buttonActionBehaviors = function(button, settings) { button.bind('click', function() { var behavior = settings['sgpb-custom-button']; if (behavior === 'redirectToURL') { if (settings['sgpb-custom-button-redirect-new-tab']) { window.open(settings['sgpb-custom-button-redirect-URL']); } else { window.location.href = settings['sgpb-custom-button-redirect-URL']; } } if (behavior === 'hidePopup') { SGPBPopup.closePopup(); } if (behavior === 'copyToClipBoard') { var tempInputId = 1; var value = settings['sgpb-custom-button-copy-to-clipboard-text']; var tempInput = document.createElement("input"); tempInput.id = tempInputId; tempInput.value = value; tempInput.style = 'position: absolute; right: -10000px'; if (!document.getElementById(tempInputId)) { document.body.appendChild(tempInput); } tempInput.select(); document.execCommand("copy"); if (settings['sgpb-copy-to-clipboard-close-popup']) { SGPBPopup.closePopup(); } if (settings['sgpb-custom-button-copy-to-clipboard-alert']) { alert(settings['sgpb-custom-button-copy-to-clipboard-message']); } } }); }; buttons.each(function() { var settings = jQuery.parseJSON(decodeURIComponent(jQuery(this).attr('data-options'))); buttonActionBehaviors(jQuery(this), settings); }); }; SGPBPopup.listeners = function () { var that = this; sgAddEvent(window, 'sgpbPopupBuilderAdditionalDimensionSettings', function(e) { SGPBPopup.mobileSafariAdditionalSettings(e); }); sgAddEvent(window, 'sgpbDidOpen', function(e) { /*for mobile landscape issue*/ if (typeof (Event) === 'function') { var event = new CustomEvent('resize', { bubbles: true, cancelable: true }); } else { if (SGPBPopup.isIE()) { var event = document.createEvent('Event'); event.initEvent('resize', true, true); } else { var event = new CustomEvent('resize', { bubbles: true, cancelable: true }); } } window.dispatchEvent(event); SGPBPopup.mobileSafariAdditionalSettings(e); var args = e.detail; var popupOptions = args.popupData; var obj = e.detail.currentObj.sgpbPopupObj; /* if no analytics extension */ if (typeof SGPB_ANALYTICS_PARAMS === 'undefined') { if (obj.getCountPopupOpen()) { obj.addToCounter(popupOptions); } } if (popupOptions['sgpb-show-popup-same-user']) { obj.setPopupLimitationCookie(popupOptions); } SGPBPopup.htmlCustomButton(); }); setInterval(function() { var openedPopups = window.sgpbOpenedPopup || {}; if (!Object.keys(openedPopups).length) { return false; } var params = {}; params.popupsIdCollection = window.sgpbOpenedPopup; var data = { action: 'sgpb_send_to_open_counter', nonce: SGPB_JS_PARAMS.nonce, params: params }; window.sgpbOpenedPopup = {}; jQuery.post(SGPB_JS_PARAMS.ajaxUrl, data, function(res) { }); }, 600); }; SGPBPopup.mobileSafariAdditionalSettings = function(e) { if (typeof e === 'undefined') { var args = SGPBPopup.prototype.getAdditionalPopupData(); if (typeof args === 'undefined') { return false; } var popupOptions = args.popupData; var popupId = parseInt(args.popupId); } else { var args = e.detail; var alreadySavedArgs = SGPBPopup.prototype.getAdditionalPopupData(); if (jQuery.isEmptyObject(alreadySavedArgs)) { SGPBPopup.prototype.setAdditionalPopupData(args); } var popupOptions = args.popupData; var popupId = parseInt(args.popupId); } var userAgent = window.navigator.userAgent; if (userAgent.match(/iPad/i) || userAgent.match(/iPhone/i)) { if (typeof popupOptions['sgpb-popup-dimension-mode'] !== 'undefined' && popupOptions['sgpb-popup-dimension-mode'] === 'responsiveMode') { var openedPopupWidth = parseInt(window.innerHeight-100); if (e.detail.popupData['sgpb-type'] === 'iframe' || e.detail.popupData['sgpb-type'] === 'video') { if (jQuery('.sgpb-popup-builder-content-'+popupId +' iframe').length) { jQuery('.sgpb-popup-builder-content-'+popupId).attr('style', 'height:'+openedPopupWidth+'px !important;'); } } } } }; SGPBPopup.prototype.setAdditionalPopupData = function(additionalPopupData) { this.additionalPopupData = additionalPopupData; }; SGPBPopup.prototype.getAdditionalPopupData = function() { return this.additionalPopupData; }; SGPBPopup.prototype.setCountPopupOpen = function(countPopupOpen) { this.countPopupOpen = countPopupOpen; }; SGPBPopup.prototype.getCountPopupOpen = function() { return this.countPopupOpen; }; SGPBPopup.playMusic = function(e) { var args = e.detail; var popupId = parseInt(args.popupId); var options = SGPBPopup.getPopupOptionsById(popupId); var soundUrl = options['sgpb-sound-url']; var soundStatus = options['sgpb-open-sound']; if (soundStatus && soundUrl && !window.SGPB_SOUND[popupId]) { var audio = new Audio(soundUrl); audio.play(); window.SGPB_SOUND[popupId] = audio; } }; SGPBPopup.floatingButton = function (e) { SGPBPopup.showFloatingButton(e); jQuery(window).on('sgpbFormSuccess', function (e){ SGPBPopup.hideFloatingButton(); }); }; SGPBPopup.showFloatingButton = function (e) { var popupObj = e || {}; var popupId = 0; var shouldShowFloatingButton = true; /* if argument e is event reference the popup object is wrapped inside e.detail.currentObj.sgpbPopupObj */ if (e.hasOwnProperty('sgpbPopupObj')) { popupObj = e.detail.currentObj.sgpbPopupObj; } if (popupObj instanceof SGPBPopup) { popupId = parseInt(popupObj.id); shouldShowFloatingButton = popupObj.forceCheckCurrentPopupType(popupObj); } /* If there is no cookie which will prevent popup opening we will show floating button */ if (shouldShowFloatingButton) { /* if we have popup id we detect exact button */ if (popupId) { jQuery('.sgpb-floating-button.sg-popup-id-' + popupId).show(); } else { jQuery('.sgpb-floating-button').show(); } } }; SGPBPopup.hideFloatingButton = function (popupId) { /* if we have popup id we detect exact button */ if (popupId) { jQuery('.sgpb-floating-button.sg-popup-id-' + popupId).fadeOut(); } else { jQuery('.sgpb-floating-button').fadeOut(); } }; SGPBPopup.prototype.initialsListeners = function() { /* one time calling events (sgpbDidOpen, sgpbDidClose ...) */ var that = this; sgAddEvent(window, 'sgpbDidOpen', function(e) { jQuery('.sg-popup-close').unbind('click').bind('click',function(){ var currentPopupId = jQuery(this).parents('.sg-popup-builder-content').attr('data-id'); SGPBPopup.closePopupById(currentPopupId); }); }); sgAddEvent(window, 'sgpbDidClose', function(e) { var args = e.detail; var popupId = parseInt(args.popupId); that.htmlIframeFilterForOpen(popupId, 'close'); }); }; SGPBPopup.prototype.onceListener = function() { var that = this; sgAddEvent(window, 'sgpbDidOpen', function(e) { document.onkeydown = function(e) { e = e || window.event; if (e.keyCode === 27) { /*esc pressed*/ var currentPopup = that.getPopupIdForNextEsc(); if (!currentPopup) { return false; } var lastPopupId = parseInt(currentPopup['popupId']); SGPBPopup.closePopupById(lastPopupId); } }; }); sgAddEvent(window, 'sgpbDidClose', function(e) { if (window.sgPopupBuilder.length !== 0) { var popups = [].concat(window.sgPopupBuilder).reverse(); for (var i in popups) { var nextIndex = ++i; var nextObj = popups[nextIndex]; if (typeof nextObj === 'undefined') { jQuery('html').removeClass('sgpb-overflow-hidden'); jQuery('body').removeClass('sgpb-overflow-hidden-body'); break; } if (nextObj.isOpen === false) { continue; } var options = SGPBPopup.getPopupOptionsById(nextObj.popupId); if (typeof options['sgpb-disable-page-scrolling'] === 'undefined') { jQuery('html').removeClass('sgpb-overflow-hidden'); jQuery('body').removeClass('sgpb-overflow-hidden-body'); } else { jQuery('html').addClass('sgpb-overflow-hidden'); jQuery('body').addClass('sgpb-overflow-hidden-body'); } break; } } else { jQuery('html').addClass('sgpb-overflow-hidden'); jQuery('body').addClass('sgpb-overflow-hidden-body'); } }); }; SGPBPopup.prototype.getPopupIdForNextEsc = function() { var popups = window.sgPopupBuilder; var popup = false; if (!popups.length) { return popup; } var searchPopups = [].concat(popups).reverse(); for (var i in searchPopups) { var popupData = searchPopups[i]; if (popupData.isOpen) { var popupId = parseInt(popupData['popupId']); var popupOptions = SGPBPopup.getPopupOptionsById(popupId); if (!popupOptions['sgpb-disable-popup-closing'] && popupOptions['sgpb-esc-key']) { popup = popupData; break; } } } return popup; }; SGPBPopup.prototype.setPopupId = function(popupId) { this.id = parseInt(popupId); }; SGPBPopup.prototype.getPopupId = function() { return this.id; }; SGPBPopup.prototype.setPopupObj = function(popupObj) { this.popupObj = popupObj; }; SGPBPopup.prototype.getPopupObj = function() { return this.popupObj; }; SGPBPopup.prototype.setPopupData = function(popupData) { if (typeof popupData == 'string') { var popupData = SGPBPopup.JSONParse(popupData); } this.popupData = popupData; }; SGPBPopup.prototype.getPopupData = function() { return this.popupData; }; SGPBPopup.prototype.setPopupConfig = function(config) { this.popupConfig = config; }; SGPBPopup.prototype.getPopupConfig = function() { return this.popupConfig; }; SGPBPopup.prototype.setUpPopupConfig = function() { var popupConfig = new PopupConfig(); this.setPopupConfig(popupConfig); }; SGPBPopup.createPopupObjById = function(popupId) { var options = SGPBPopup.getPopupOptionsById(popupId); if (!options) { return false; } var popupObj = new SGPBPopup(); popupObj.setPopupId(popupId); popupObj.setPopupData(options); return popupObj; }; SGPBPopup.getPopupOptionsById = function(popupId) { var popupDataDiv = jQuery('#sg-popup-content-wrapper-'+popupId); if (!popupDataDiv.length) { return false; } var options = popupDataDiv.attr('data-options'); return SGPBPopup.JSONParse(options); }; SGPBPopup.prototype.getCompatibleZiIndex = function(popupZIndex) { /*2147483647 it's maximal z index value*/ if (popupZIndex > 2147483647) { return 2147483627; } return popupZIndex; }; SGPBPopup.prototype.prepareOpen = function() { var popupId = this.getPopupId(); var popupData = this.getPopupData(); var popupZIndex = this.getCompatibleZiIndex(popupData['sgpb-popup-z-index']); var popupType = this.popupData['sgpb-type']; this.setUpPopupConfig(); var that = this; var popupConfig = this.getPopupConfig(); function decodeEntities(encodedString) { if (typeof encodedString == 'undefined') { return ''; } var suspiciousStrings = ['document.createElement', 'createElement', 'String.fromCharCode', 'fromCharCode']; for (var i in suspiciousStrings) { if (encodedString.indexOf(suspiciousStrings[i]) > 0) { return ''; } } var textArea = document.createElement('textarea'); textArea.innerHTML = encodedString; return textArea.value; } popupConfig.customShouldOpen = function() { var instructions = popupData['sgpb-ShouldOpen']; instructions = decodeEntities(instructions); var F = new Function (instructions); return(F()); }; popupConfig.customShouldClose = function() { var instructions = popupData['sgpb-ShouldClose']; instructions = decodeEntities(instructions); var F = new Function (instructions); return(F()); }; this.setPopupDimensions(); if (popupData['sgpb-disable-popup-closing'] == 'on') { popupData['sgpb-enable-close-button'] = ''; popupData['sgpb-esc-key'] = ''; popupData['sgpb-overlay-click'] = ''; } /*used in the analytics*/ popupData['eventName'] = this.eventName; if (SGPBPopup.varToBool(popupData['sgpb-enable-close-button'])) { popupConfig.magicCall('setCloseButtonDelay', parseInt(popupData['sgpb-close-button-delay'])); } popupConfig.magicCall('setShowButton', SGPBPopup.varToBool(popupData['sgpb-enable-close-button'])); /* Convert seconds to micro seconds */ var openAnimationSpeed = parseFloat(popupData['sgpb-open-animation-speed'])*1000; var closeAnimationSpeed = parseFloat(popupData['sgpb-close-animation-speed'])*1000; popupConfig.magicCall('setOpenAnimationEffect', popupData['sgpb-open-animation-effect']); popupConfig.magicCall('setCloseAnimationEffect', popupData['sgpb-close-animation-effect']); popupConfig.magicCall('setOpenAnimationSpeed', openAnimationSpeed); popupConfig.magicCall('setCloseAnimationSpeed', closeAnimationSpeed); popupConfig.magicCall('setOpenAnimationStatus', popupData['sgpb-open-animation']); popupConfig.magicCall('setCloseAnimationStatus', popupData['sgpb-close-animation']); popupConfig.magicCall('setContentPadding', popupData['sgpb-content-padding']); if (typeof SgpbRecentSalesPopupType != 'undefined') { if (popupType == SgpbRecentSalesPopupType) { /* set max z index for recent sales popup */ popupZIndex = 2147483647; popupConfig.magicCall('setCloseAnimationEffect', 'fade'); popupConfig.magicCall('setCloseAnimationSpeed', 1000); popupConfig.magicCall('setCloseAnimationStatus', 'on'); } } popupConfig.magicCall('setZIndex', popupZIndex); popupConfig.magicCall('setCloseButtonWidth', popupData['sgpb-button-image-width']); popupConfig.magicCall('setCloseButtonHeight', popupData['sgpb-button-image-height']); popupConfig.magicCall('setPopupId', popupId); popupConfig.magicCall('setPopupData', popupData); popupConfig.magicCall('setAllowed', !SGPBPopup.varToBool(popupData['sgpb-disable-popup-closing'])); if (popupData['sgpb-type'] == SGPB_POPUP_PARAMS.popupTypeAgeRestriction) { popupConfig.magicCall('setAllowed', false); } popupConfig.magicCall('setEscShouldClose', SGPBPopup.varToBool(popupData['sgpb-esc-key'])); popupConfig.magicCall('setOverlayShouldClose', SGPBPopup.varToBool(popupData['sgpb-overlay-click'])); popupConfig.magicCall('setScrollingEnabled', SGPBPopup.varToBool(popupData['sgpb-enable-content-scrolling'])); if (SGPBPopup.varToBool(popupData['sgpb-content-click'])) { this.contentCloseBehavior(); } sgAddEvent(window, 'sgpbWillOpen', function(e) { if (popupId != e.detail.popupId || e.detail.popupData['sgpb-content-click'] == 'undefined') { return false; } /* triggering any popup content click (analytics) */ that.popupContentClick(e); }); if (SGPBPopup.varToBool(popupData['sgpb-popup-fixed'])) { this.addFixedPosition(); } /*ThemeCreator*/ this.themeCreator(); this.themeCustomizations(); popupConfig.magicCall('setContents', document.getElementById('sg-popup-content-wrapper-'+popupId)); popupConfig.magicCall('setPopupType', popupType); this.setPopupConfig(popupConfig); this.popupTriggeringListeners(); /* check popup type, then check if popup can be opened by popup type */ var allowToOpen = this.checkCurrentPopupType(); if (allowToOpen) { this.open(); } }; SGPBPopup.prototype.popupContentClick = function(e) { var args = e.detail; var popupId = parseInt(args['popupId']); jQuery('.sgpb-content-' + popupId).on('click', function(event) { var settings = { popupId: popupId, eventName: 'sgpbPopupContentclick' }; jQuery(window).trigger('sgpbPopupContentclick', settings); }); }; SGPBPopup.prototype.forceCheckCurrentPopupType = function(popupObj) { var allowToOpen = true; var popupConfig = new PopupConfig(); var className = popupObj.popupData['sgpb-type']; if (typeof className == 'undefined' || className == 'undefined') { return false; } if (typeof SGPB_POPUP_PARAMS.conditionalJsClasses != 'undefined' && SGPB_POPUP_PARAMS.conditionalJsClasses.length) { var isAllowConditions = this.forceIsAllowJsConditions(popupObj); if (!isAllowConditions) { return false; } } var popupConfig = new PopupConfig(); var className = this.popupData['sgpb-type']; /* make the first letter of a string uppercase, then concat prefix (uppercase all prefix string) */ className = popupConfig.prefix.toUpperCase() + PopupConfig.firstToUpperCase(className); /* hasOwnProperty returns boolean value */ if (window.hasOwnProperty(className)) { className = eval(className); /* create current popup type object */ var obj = new className; /* call allowToOpen function if exists */ if (typeof obj.allowToOpen === 'function') { allowToOpen = obj.allowToOpen(this.id); if (!allowToOpen) { isAllow = allowToOpen; } } } var allowToOpen = this.checkCurrentPopupType(); if (!allowToOpen) { return false; } return allowToOpen; }; SGPBPopup.prototype.checkCurrentPopupType = function() { var allowToOpen = true; var popupConfig = new PopupConfig(); var isPreview = parseInt(this.popupData['sgpb-is-preview']); if (!isNaN(isPreview) && isPreview == 1) { return allowToOpen; } var popupHasLimit = this.isSatistfyForShowingLimitation(this.popupData); if (!popupHasLimit) { return false; } var dontShowPopupCookieName = 'sgDontShowPopup' + this.popupData['sgpb-post-id']; var dontShowPopup = SGPopup.getCookie(dontShowPopupCookieName); if (dontShowPopup != '') { return false; } var className = this.popupData['sgpb-type']; if (typeof className == 'undefined' || className == 'undefined') { return false; } if (typeof SGPB_POPUP_PARAMS.conditionalJsClasses != 'undefined' && SGPB_POPUP_PARAMS.conditionalJsClasses.length) { var isAllowConditions = this.isAllowJsConditions(); if (!isAllowConditions) { return false; } } /* make the first letter of a string uppercase, then concat prefix (uppercase all prefix string) */ className = popupConfig.prefix.toUpperCase() + PopupConfig.firstToUpperCase(className); /* hasOwnProperty returns boolean value */ if (window.hasOwnProperty(className)) { className = eval(className); /* create current popup type object */ var obj = new className; /* call allowToOpen function if exists */ if (typeof obj.allowToOpen === 'function') { allowToOpen = obj.allowToOpen(this.id); } } return allowToOpen; }; SGPBPopup.prototype.forceIsAllowJsConditions = function(popupObj) { var conditions = SGPB_POPUP_PARAMS.conditionalJsClasses; var isAllow = true; for (var i in conditions) { if (!conditions.hasOwnProperty(i)) { break; } try { var className = eval(conditions[i]); } catch (e) { continue; } var obj = new className; /* call allowToOpen function if exists */ if (typeof obj.forceAllowToOpen === 'function') { var popupData = this.getPopupData(); var allowToOpen = obj.forceAllowToOpen(popupObj.id, popupObj); if (!allowToOpen) { isAllow = allowToOpen; break; } } } return isAllow; }; SGPBPopup.prototype.isAllowJsConditions = function() { var conditions = SGPB_POPUP_PARAMS.conditionalJsClasses; var isAllow = true; for (var i in conditions) { if (!conditions.hasOwnProperty(i)) { break; } try { var className = eval(conditions[i]); } catch (e) { continue; } var obj = new className; /* call allowToOpen function if exists */ if (typeof obj.allowToOpen === 'function') { var allowToOpen = obj.allowToOpen(this.id, this); if (!allowToOpen) { isAllow = allowToOpen; break; } } } return isAllow; }; SGPBPopup.prototype.setPopupLimitationCookie = function(popupData) { var cookieData = this.getPopupShowLimitationCookie(popupData); var cookie = cookieData.cookie || {}; var openingCount = cookie.openingCount || 0; var currentUrl = window.location.href; if (!popupData['sgpb-show-popup-same-user-page-level']) { currentUrl = ''; } cookie.openingCount = openingCount + 1; cookie.openingPage = currentUrl; var popupShowingLimitExpiry = parseInt(popupData['sgpb-show-popup-same-user-expiry']); SGPBPopup.setCookie(cookieData.cookieName, JSON.stringify(cookie), popupShowingLimitExpiry, currentUrl); }; SGPBPopup.prototype.isSatistfyForShowingLimitation = function(popupData) { /*enable||disable*/ var popupLimitation = popupData['sgpb-show-popup-same-user']; /*if this option unchecked popup must be show*/ if (!popupLimitation) { return true; } var cookieData = this.getPopupShowLimitationCookie(popupData); /*when there is not*/ if (!cookieData.cookie) { return true; } return popupData['sgpb-show-popup-same-user-count'] > cookieData.cookie.openingCount; }; SGPBPopup.prototype.getPopupShowLimitationCookie = function(popupData) { var savedCookie = this.getPopupShowLimitationCookieDetails(popupData); var savedCookie = this.filterPopupLimitationCookie(savedCookie); return savedCookie; }; SGPBPopup.prototype.filterPopupLimitationCookie = function(cookie) { var result = {}; result.cookie = ''; if (cookie.isPageLevel) { result.cookieName = cookie.pageLevelCookieName; if (cookie.pageLevelCookie) { result.cookie = jQuery.parseJSON(cookie.pageLevelCookie); } SGPBPopup.deleteCookie(cookie.domainLevelCookieName); return result; } result.cookieName = cookie.domainLevelCookieName; if (cookie.domainLevelCookie) { result.cookie = jQuery.parseJSON(cookie.domainLevelCookie); } var currentUrl = window.location.href; SGPBPopup.deleteCookie(cookie.pageLevelCookieName, currentUrl); return result; }; SGPBPopup.prototype.getPopupShowLimitationCookieDetails = function(popupData) { var result = false; var currentUrl = window.location.href; var currentPopupId = popupData['sgpb-post-id']; /*Cookie names*/ var popupLimitationCookieHomePageLevelName = 'SGPBShowingLimitationHomePage' + currentPopupId; var popupLimitationCookiePageLevelName = 'SGPBShowingLimitationPage' + currentPopupId; var popupLimitationCookieDomainName = 'SGPBShowingLimitationDomain' + currentPopupId; var pageLevelCookie = popupData['sgpb-show-popup-same-user-page-level'] || false; /*check if current url is home page*/ if (currentUrl == SGPB_POPUP_PARAMS.homePageUrl) { popupLimitationCookiePageLevelName = popupLimitationCookieHomePageLevelName; } var popupLimitationPageLevelCookie = SGPopup.getCookie(popupLimitationCookiePageLevelName); var popupLimitationDomainCookie = SGPopup.getCookie(popupLimitationCookieDomainName); result = { 'pageLevelCookieName': popupLimitationCookiePageLevelName, 'domainLevelCookieName': popupLimitationCookieDomainName, 'pageLevelCookie': popupLimitationPageLevelCookie, 'domainLevelCookie': popupLimitationDomainCookie, 'isPageLevel': pageLevelCookie }; return result; }; SGPBPopup.prototype.themeCreator = function() { var noPositionSelected = false; var popupData = this.getPopupData(); var popupId = this.getPopupId(); var popupConfig = this.getPopupConfig(); var forceRtlClass = ''; var forceRtl = SGPBPopup.varToBool(popupData['sgpb-force-rtl']); var popupTheme = popupData['sgpb-popup-themes']; var popupType = popupData['sgpb-type']; var closeButtonWidth = popupData['sgpb-button-image-width']; var closeButtonHeight = popupData['sgpb-button-image-height']; var contentPadding = parseInt(popupData['sgpb-content-padding']); /* close button position */ var top = parseInt(popupData['sgpb-button-position-top']); var right = parseInt(popupData['sgpb-button-position-right']); var bottom = parseInt(popupData['sgpb-button-position-bottom']); var left = parseInt(popupData['sgpb-button-position-left']); var contentClass = popupData['sgpb-content-custom-class']; /* for the 2-nd and 3-rd themes only */ var popupBorder = SGPBPopup.varToBool(popupData['sgpb-disable-border']); var closeButtonImage = popupConfig.closeButtonImage; var themeNumber = 1; var backgroundColor = 'black'; var borderColor = 'inherit'; var recentSalesPopup = false; if (typeof SgpbRecentSalesPopupType != 'undefined') { if (popupType == SgpbRecentSalesPopupType) { recentSalesPopup = true; popupTheme = 'sgpb-theme-2'; closeButtonPosition = 'topRight'; backgroundColor = 'white'; borderColor = '#ececec'; top = '-10'; right = '-10'; popupConfig.magicCall('setShadowSpread', 1); popupConfig.magicCall('setContentShadowBlur', 5); popupConfig.magicCall('setOverlayVisible', false); popupConfig.magicCall('setContentShadowColor', '#000000b3'); popupConfig.magicCall('setContentBorderRadius', '5px'); } } var themeIndexNum = popupTheme[popupTheme.length -1]; if (isNaN(top)) { top = this.closeButtonDefaultPositions[themeIndexNum].top; } if (isNaN(right)) { right = this.closeButtonDefaultPositions[themeIndexNum].right; } if (isNaN(bottom)) { bottom = this.closeButtonDefaultPositions[themeIndexNum].bottom; } if (isNaN(left)) { left = this.closeButtonDefaultPositions[themeIndexNum].left; } if (forceRtl) { forceRtlClass = ' sgpb-popup-content-direction-right'; } if (popupData['sgpb-type'] == 'countdown') { popupConfig.magicCall('setMinWidth', 300); } popupConfig.magicCall('setContentPadding', contentPadding); popupConfig.magicCall('setOverlayAddClass', popupTheme+'-overlay sgpb-popup-overlay-' + popupId); popupConfig.magicCall('setContentAddClass', 'sgpb-content sgpb-content-'+popupId+' ' + popupTheme+'-content ' + contentClass + forceRtlClass); if (typeof popupData['sgpb-close-button-position'] == 'undefined' || popupData['sgpb-close-button-position'] == '') { /* * in the old version we don't have close button position option * and if noPositionSelected is true, the popup was not edited */ var noPositionSelected = true; } else { var closeButtonPosition = popupData['sgpb-close-button-position']; popupConfig.magicCall('setButtonPosition', closeButtonPosition); } if (popupTheme == 'sgpb-theme-1') { themeNumber = 1; popupConfig.magicCall('setShadowSpread', 14); /* 9px theme default close button position for all cases */ if (noPositionSelected || closeButtonPosition == 'bottomRight') { popupConfig.magicCall('setCloseButtonPositionRight', right+'px'); popupConfig.magicCall('setCloseButtonPositionBottom', bottom+'px'); } else { popupConfig.magicCall('setCloseButtonPositionLeft', left+'px'); popupConfig.magicCall('setCloseButtonPositionBottom', bottom+'px'); } } else if (popupTheme == 'sgpb-theme-2') { themeNumber = 2; popupConfig.magicCall('setButtonInside', false); popupConfig.magicCall('setContentBorderWidth', 1); popupConfig.magicCall('setContentBackgroundColor', backgroundColor); popupConfig.magicCall('setContentBorderColor', borderColor); popupConfig.magicCall('setOverlayColor', 'white'); var rightPosition = '0'; var topPosition = '-' + closeButtonHeight + 'px'; if (recentSalesPopup) { rightPosition = '-' + (closeButtonWidth / 2) + 'px'; topPosition = '-' + (closeButtonHeight / 2) + 'px'; themeNumber = 6; } if (noPositionSelected || closeButtonPosition == 'topRight') { /* this theme has 1px border */ popupConfig.magicCall('setCloseButtonPositionRight', right+'px'); popupConfig.magicCall('setCloseButtonPositionTop', top+'px'); } else { if (closeButtonPosition == 'topLeft') { popupConfig.magicCall('setCloseButtonPositionLeft', left+'px'); popupConfig.magicCall('setCloseButtonPositionTop', top+'px'); } else if (closeButtonPosition == 'bottomRight') { popupConfig.magicCall('setCloseButtonPositionRight', right+'px'); popupConfig.magicCall('setCloseButtonPositionBottom', bottom+'px'); } else if (closeButtonPosition == 'bottomLeft') { popupConfig.magicCall('setCloseButtonPositionLeft', left+'px'); popupConfig.magicCall('setCloseButtonPositionBottom', bottom+'px'); } } if (popupBorder) { popupConfig.magicCall('setContentBorderWidth', 0); } } else if (popupTheme == 'sgpb-theme-3') { themeNumber = 3; popupConfig.magicCall('setContentBorderWidth', 5); popupConfig.magicCall('setContentBorderRadius', popupData['sgpb-border-radius']); popupConfig.magicCall('setContentBorderRadiusType', popupData['sgpb-border-radius-type']); popupConfig.magicCall('setContentBorderColor', popupData['sgpb-border-color']); var closeButtonPositionPx = '4px'; if (popupBorder) { popupConfig.magicCall('setContentBorderWidth', 0); closeButtonPositionPx = '0px'; } if (noPositionSelected) { popupConfig.magicCall('setCloseButtonWidth', 38); popupConfig.magicCall('setCloseButtonHeight', 19); popupConfig.magicCall('setCloseButtonPositionRight', right+'px'); popupConfig.magicCall('setCloseButtonPositionTop', top+'px'); } else { if (closeButtonPosition == 'topRight') { popupConfig.magicCall('setCloseButtonPositionRight', right+'px'); popupConfig.magicCall('setCloseButtonPositionTop', top+'px'); } else if (closeButtonPosition == 'topLeft') { popupConfig.magicCall('setCloseButtonPositionLeft', left+'px'); popupConfig.magicCall('setCloseButtonPositionTop', top+'px'); } else if (closeButtonPosition == 'bottomRight') { popupConfig.magicCall('setCloseButtonPositionLeft', right+'px'); popupConfig.magicCall('setCloseButtonPositionBottom', bottom+'px'); } else if (closeButtonPosition == 'bottomLeft') { popupConfig.magicCall('setCloseButtonPositionLeft', left+'px'); popupConfig.magicCall('setCloseButtonPositionBottom', bottom+'px'); } } } else if (popupTheme == 'sgpb-theme-4') { /* in theme-4 close button type is button,not image, * then set type to button, default is image and * set text */ themeNumber = 4; popupConfig.magicCall('setButtonImage', popupData['sgpb-button-text']); popupConfig.magicCall('setCloseButtonType', 'button'); popupConfig.magicCall('setCloseButtonText', popupData['sgpb-button-text']); popupConfig.magicCall('setContentBorderWidth', 0); popupConfig.magicCall('setContentBackgroundColor', 'white'); popupConfig.magicCall('setContentBorderColor', 'white'); popupConfig.magicCall('setOverlayColor', 'white'); popupConfig.magicCall('setShadowSpread', 4); popupConfig.magicCall('setContentShadowBlur', 8); /* 8px/12px theme default close button position for all cases */ if (noPositionSelected || closeButtonPosition == 'bottomRight') { popupConfig.magicCall('setCloseButtonPositionRight', right+'px'); popupConfig.magicCall('setCloseButtonPositionBottom', bottom+'px'); } else { popupConfig.magicCall('setCloseButtonPositionLeft', left+'px'); popupConfig.magicCall('setCloseButtonPositionBottom', bottom+'px'); } } else if (popupTheme == 'sgpb-theme-5') { themeNumber = 5; popupConfig.magicCall('setBoxBorderWidth', 10); popupConfig.magicCall('setContentBorderColor', '#4B4B4B'); if (noPositionSelected || closeButtonPosition == 'bottomRight') { popupConfig.magicCall('setCloseButtonPositionRight', right+'px'); popupConfig.magicCall('setCloseButtonPositionBottom', bottom+'px'); } else { popupConfig.magicCall('setCloseButtonPositionLeft', left+'px'); popupConfig.magicCall('setCloseButtonPositionBottom', bottom+'px'); } } else if (popupTheme == 'sgpb-theme-6') { themeNumber = 6; popupConfig.magicCall('setButtonInside', false); popupConfig.magicCall('setContentBorderRadius', 7); popupConfig.magicCall('setContentBorderRadiusType', 'px'); if (noPositionSelected) { popupConfig.magicCall('setCloseButtonWidth', 37); popupConfig.magicCall('setCloseButtonHeight', 37); popupConfig.magicCall('setCloseButtonPositionRight', right+'px'); popupConfig.magicCall('setCloseButtonPositionTop', top+'px'); } else { if (typeof popupData['sgpb-button-position-right'] == 'undefined') { right = '-' + (closeButtonWidth / 2); top = '-' + (closeButtonHeight / 2); left = '-' + (closeButtonWidth / 2); bottom = '-' + (closeButtonHeight / 2); } if (closeButtonPosition == 'topRight') { popupConfig.magicCall('setCloseButtonPositionRight', right + 'px'); popupConfig.magicCall('setCloseButtonPositionTop', top + 'px'); } else if (closeButtonPosition == 'topLeft') { popupConfig.magicCall('setCloseButtonPositionLeft', left + 'px'); popupConfig.magicCall('setCloseButtonPositionTop', top + 'px'); } else if (closeButtonPosition == 'bottomRight') { popupConfig.magicCall('setCloseButtonPositionRight', right + 'px'); popupConfig.magicCall('setCloseButtonPositionBottom', bottom + 'px'); } else if (closeButtonPosition == 'bottomLeft') { popupConfig.magicCall('setCloseButtonPositionLeft', left + 'px'); popupConfig.magicCall('setCloseButtonPositionBottom', bottom + 'px'); } } } popupConfig.magicCall('setPopupTheme', themeNumber); if (!popupData['sgpb-button-image']) { closeButtonImage = SGPB_POPUP_PARAMS.defaultThemeImages[themeNumber]; if (typeof closeButtonImage != 'undefined') { popupConfig.magicCall('setButtonImage', closeButtonImage); } } else { popupConfig.magicCall('setButtonImage', 'data:image/png;base64,'+popupData['sgpb-button-image-data']); if (popupData['sgpb-button-image-data'] == '' || popupData['sgpb-button-image-data'].indexOf('http') != -1) { popupConfig.magicCall('setButtonImage', popupData['sgpb-button-image']); } } }; SGPBPopup.prototype.themeCustomizations = function() { var popupId = this.getPopupId(); var popupData = this.getPopupData(); var popupConfig = this.getPopupConfig(); var contentOpacity = popupData['sgpb-content-opacity']; var contentBgColor = popupData['sgpb-background-color']; if (popupData['sgpb-background-image-data']) { var contentBgImage = 'data:image/png;base64,'+popupData['sgpb-background-image-data']; } else { var contentBgImage = popupData['sgpb-background-image']; } var showContentBackground = popupData['sgpb-show-background']; var contentBgImageMode = popupData['sgpb-background-image-mode']; var overlayColor = popupData['sgpb-overlay-color']; var popupTheme = popupData['sgpb-popup-themes']; var popupType = popupData['sgpb-type']; if (typeof popupData['sgpb-overlay-custom-class'] == 'undefined') { popupData['sgpb-overlay-custom-class'] = 'sgpb-popup-overlay'; } if (typeof popupData['sgpb-popup-themes'] == 'undefined') { popupTheme = 'sgpb-theme-2'; } if (typeof showContentBackground == 'undefined') { contentBgColor = ''; contentBgImage = ''; contentBgImageMode = ''; } if (typeof SgpbRecentSalesPopupType != 'undefined') { if (popupType == SgpbRecentSalesPopupType) { showContentBackground = 'on'; contentBgColor = popupData['sgpb-background-color']; contentOpacity = popupData['sgpb-content-opacity']; } } if (contentOpacity) { popupConfig.magicCall('setContentBackgroundOpacity', contentOpacity); } if (contentBgImageMode) { popupConfig.magicCall('setContentBackgroundMode', contentBgImageMode); } if (contentBgImage) { popupConfig.magicCall('setContentBackgroundImage', contentBgImage); } if (contentBgColor) { contentBgColor = SGPBPopup.hexToRgba(contentBgColor, contentOpacity); popupConfig.magicCall('setContentBackgroundColor', contentBgColor); } if (overlayColor) { popupConfig.magicCall('setOverlayColor', overlayColor); } var overlayClasses = popupTheme+'-overlay sgpb-popup-overlay-'+popupId; if (SGPB_JS_PACKAGES.extensions['advanced-closing']) { if (typeof popupData['sgpb-enable-popup-overlay'] != 'undefined' && popupData['sgpb-enable-popup-overlay'] == 'on') { popupData['sgpb-enable-popup-overlay'] = true; } else if (typeof popupData['sgpb-enable-popup-overlay'] == 'undefined') { popupData['sgpb-enable-popup-overlay'] = false; } } else { popupData['sgpb-enable-popup-overlay'] = true; } popupConfig.magicCall('setOverlayVisible', SGPBPopup.varToBool(popupData['sgpb-enable-popup-overlay'])); if (typeof SgpbRecentSalesPopupType != 'undefined') { popupConfig.magicCall('setOverlayVisible', false); } if (SGPBPopup.varToBool(popupData['sgpb-enable-popup-overlay'])) { popupConfig.magicCall('setOverlayAddClass', overlayClasses + ' ' + popupData['sgpb-overlay-custom-class']); var overlayOpacity = popupData['sgpb-overlay-opacity'] || 0.8; popupConfig.magicCall('setOverlayOpacity', overlayOpacity * 100); } }; SGPBPopup.prototype.formSubmissionDetection = function(args) { if (args.length) { return false; } var popupId = args.popupId; var options = SGPBPopup.getPopupOptionsById(popupId); if (!options['sgpb-reopen-after-form-submission']) { return false; } jQuery('.sgpb-popup-builder-content-' + popupId + ' form').submit(function() { SGPBPopup.setCookie('SGPBSubmissionReloadPopup', popupId); }); }; SGPBPopup.prototype.htmlIframeFilterForOpen = function(popupId, popupEventName) { var popupContent = jQuery('.sgpb-content-' + popupId); if (!popupContent.length) { return false; } popupContent.find('iframe').each(function() { if (popupEventName != 'open') { /* for do not affect facebook type buttons iframe only */ if (jQuery(this).closest('.fb_iframe_widget').length) { return true; } /*close*/ if (typeof jQuery(this).attr('data-attr-src') == 'undefined') { var src = jQuery(this).attr('src'); if (src != '') { jQuery(this).attr('data-attr-src', src); jQuery(this).attr('src', ''); } return true; } else { var src = jQuery(this).attr('src'); if (src != '') { jQuery(this).attr('data-attr-src', src); jQuery(this).attr('src', ''); } return true; } } else { /*open*/ if (typeof jQuery(this).attr('data-attr-src') == 'undefined') { var src = jQuery(this).attr('src'); if (src != '') { jQuery(this).attr('data-attr-src', src); } return true; } else { var src = jQuery(this).attr('data-attr-src'); if (src != '') { jQuery(this).attr('src', src); jQuery(this).attr('data-attr-src', src); } return true; } } }); }; SGPBPopup.prototype.iframeSizesInHtml = function(args) { var popupId = args['popupId']; var popupOptions = args.popupData; var popupContent = jQuery('.sgpb-content-' + popupId); if (!popupContent.length) { return false; } popupContent.find('iframe').each(function() { if (typeof jQuery(this) == 'undefined') { return false; } if (popupOptions['sgpb-popup-dimension-mode'] == 'customMode') { if (typeof jQuery(this).attr('width') == 'undefined' && typeof popupContent.attr('height') == 'undefined') { jQuery(this).css({'width': popupOptions['sgpb-width'], 'height': popupOptions['sgpb-height']}); } } }); }; SGPBPopup.prototype.getSearchDataFromContent = function(content) { var pattern = /\[(\[?)(pbvariable)(?![\w-])([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]\*+(?:\[(?!\/\2\])[^\[]\*+)\*+)\[\/\2\])?)(\]?)/gi; var match; var collectedData = []; while (match = pattern.exec(content)) { var currentSearchData = []; var attributes; var attributesKeyValue = []; var parseAttributes = /\s(\w+?)="(.+?)"/g; currentSearchData['replaceString'] = this.htmlDecode(match[0]); while (attributes = parseAttributes.exec(match[3])) { attributesKeyValue[attributes[1]] = this.htmlDecode(attributes[2]); } currentSearchData['searchData'] = attributesKeyValue; collectedData.push(currentSearchData); } return collectedData; }; SGPBPopup.prototype.replaceWithCustomShortcode = function(popupId) { var currentHtmlContent = jQuery('.sgpb-content-'+popupId).html(); var searchData = this.getSearchDataFromContent(currentHtmlContent); var that = this; if (!searchData.length) { return false; } for (var index in searchData) { var currentSearchData = searchData[index]; var searchAttributes = currentSearchData['searchData']; if (typeof searchAttributes['selector'] == 'undefined' || typeof searchAttributes['attribute'] == 'undefined') { that.replaceShortCode(currentSearchData['replaceString'], '', popupId); continue; } try { if (!jQuery(searchAttributes['selector']).length) { that.replaceShortCode(currentSearchData['replaceString'], '', popupId); continue; } } catch (e) { that.replaceShortCode(currentSearchData['replaceString'], '', popupId); continue; } if (searchAttributes['attribute'] == 'text') { var replaceName = jQuery(searchAttributes['selector']).text(); } else { var replaceName = jQuery(searchAttributes['selector']).attr(searchAttributes['attribute']); } if (typeof replaceName == 'undefined') { that.replaceShortCode(currentSearchData['replaceString'], '', popupId); continue; } that.replaceShortCode(currentSearchData['replaceString'], replaceName, popupId); } }; SGPBPopup.prototype.replaceShortCode = function(shortCode, replaceText, popupId) { var popupId = parseInt(popupId); if (!popupId) { return false; } var popupContentWrapper = jQuery('.sgpb-content-' + popupId); if (!popupContentWrapper.length) { return false; } popupContentWrapper.find('div').each(function() { var currentHtmlContent = jQuery(this).contents(); if (!currentHtmlContent.length) { return false; } currentHtmlContent.html(function(i, v) { if (typeof v != 'undefined') { return v.replace(shortCode, replaceText); } }); }); return true; }; SGPBPopup.prototype.popupTriggeringListeners = function() { var that = this; var popupData = this.getPopupData(); var popupConfig = this.getPopupConfig(); sgAddEvent(window, 'sgpbDidOpen', function(e) { var args = e.detail; that.iframeSizesInHtml(args); that.formSubmissionDetection(args); var popupOptions = args.popupData; var closeButtonDelay = parseInt(popupOptions['sgpb-close-button-delay']); if (closeButtonDelay) { that.closeButtonDisplay(popupOptions['sgpb-post-id'], 'show', closeButtonDelay); } var disablePageScrolling = popupOptions['sgpb-disable-page-scrolling']; if (popupOptions['sgpb-overlay-color']) { jQuery('.sgpb-theme-1-overlay').css({'background-image': 'none'}); } if (SGPBPopup.varToBool(disablePageScrolling)) { jQuery('html').addClass('sgpb-overflow-hidden'); jQuery('body').addClass('sgpb-overflow-hidden-body'); } }); sgAddEvent(window, 'sgpbWillOpen', function(e) { var args = e.detail; var popupId = parseInt(args['popupId']); that.htmlIframeFilterForOpen(args.popupId, 'open'); that.replaceWithCustomShortcode(popupId); that.sgpbDontShowPopup(popupId); var closeButtonDelay = parseInt(popupData['sgpb-close-button-delay']); if (closeButtonDelay) { that.closeButtonDisplay(popupData['sgpb-post-id'], 'hide'); } /* extra checker for analytics */ var settings = { popupId: popupData['sgpb-post-id'], disabledAnalytics: popupData['sgpb-popup-counting-disabled'], disabledInGeneral: SGPB_POPUP_PARAMS.disableAnalyticsGeneral }; jQuery(window).trigger('sgpbDisableAnalytics', settings); }); sgAddEvent(window, 'sgpbShouldClose', function(e) { }); sgAddEvent(window, 'sgpbWillClose', function(e) { var args = e.detail; SGPBPopup.offPopup(e.detail.currentObj); }); }; SGPBPopup.prototype.sgpbDontShowPopup = function(popupId) { var dontShowPopup = jQuery('.sgpb-content-' + popupId).parent().find('[class*="sg-popup-dont-show"]'); if (!dontShowPopup.length) { return false; } dontShowPopup.each(function() { jQuery(this).bind('click', function(e) { e.preventDefault(); var expireTime = SGPB_POPUP_PARAMS.dontShowPopupExpireTime; var cookieName = 'sgDontShowPopup' + popupId; var classNameSearch = jQuery(this).attr('class').match(/sg-popup-dont-show/); var className = classNameSearch['input']; var customExpireTime = className.match(/sg-popup-dont-show-(\d+$)/); if (customExpireTime) { expireTime = parseInt(customExpireTime[1]); } SGPBPopup.setCookie(cookieName, expireTime, expireTime); SGPBPopup.closePopupById(popupId); }); }); }; SGPBPopup.prototype.addToCounter = function(popupOptions) { if (SGPB_POPUP_PARAMS.isPreview || (typeof popupOptions['sgpb-popup-counting-disabled'] != 'undefined')) { return false; } var that = this; var openedPopups = window.sgpbOpenedPopup || {}; var popupId = parseInt(popupOptions['sgpb-post-id']); if (typeof openedPopups[popupId] == 'undefined') { openedPopups[popupId] = 1; } else { openedPopups[popupId] += 1; } window.sgpbOpenedPopup = openedPopups; }; /* * closeButtonDisplay() * close or hide close button * @param popupId * @param display * @param delay */ SGPBPopup.prototype.closeButtonDisplay = function(popupId, display, delay) { if (display == 'show') { setTimeout(function() { jQuery('.sgpb-content-' + popupId).prev().show(); }, delay * 1000 /* received values covert to milliseconds */ ); } else if (display == 'hide') { jQuery('.sgpb-content-' + popupId).prev().hide(); } }; SGPBPopup.prototype.open = function(args) { var customEvent = this.customEvent; var config = this.getPopupConfig(); var popupId = this.getPopupId(); var eventName = this.eventName; if (typeof window.sgPopupBuilder == 'undefined') { window.sgPopupBuilder = []; } var popupData = SGPBPopup.getPopupWindowDataById(popupId); if (!popupData) { window.SGPB_ORDER += 1; var currentObj = { 'eventName': eventName, 'popupId': popupId, 'order': window.SGPB_ORDER, 'isOpen': true, 'sgpbPopupObj': this }; config.currentObj = currentObj; var popupConfig = config.combineConfigObj(); var popup = new SGPopup(popupConfig); currentObj.popup = popup; window.sgPopupBuilder.push(currentObj); } else { popup = popupData['popup']; popupData['isOpen'] = true; } if (typeof args != 'undefined' && !args['countPopupOpen']) { /* don't allow to count popup opening */ this.setCountPopupOpen(false); } popup.customEvent = customEvent; popup.open(); this.setPopupObj(popup); /* contact form 7 form submission * TODO: this must be moved to a better place in the future * I'm leaving it here for now, since sgpbDidOpen() gets called way too much! */ var options = SGPBPopup.getPopupOptionsById(popupId); SgpbEventListener.CF7EventListener(popupId, options); if (typeof options['sgpb-behavior-after-special-events'] != 'undefined') { if (options['sgpb-behavior-after-special-events'].length) { options = options['sgpb-behavior-after-special-events'][0][0]; if (options['param'] == 'contact-form-7') { SgpbEventListener.processCF7MailSent(popupId, options); } } } }; SGPBPopup.varToBool = function(optionName) { var returnValue = optionName ? true : false; return returnValue; }; SGPBPopup.hexToRgba = function(hex, opacity) { var c; if (/^#([A-Fa-f0-9]{3}){1,2}$/.test(hex)){ c = hex.substring(1).split(''); if (c.length == 3){ c= [c[0], c[0], c[1], c[1], c[2], c[2]]; } c = '0x'+c.join(''); return 'rgba('+[(c>>16)&255, (c>>8)&255, c&255].join(',')+','+opacity+')'; } throw new Error('Bad Hex'); }; SGPBPopup.prototype.contentCopyToClick = function() { var popupData = this.getPopupData(); var popupId = this.getPopupId(); var tempInputId = 'content-copy-to-click-'+popupId; var value = this.htmlDecode(popupData['sgpb-copy-to-clipboard-text']); var tempInput = document.createElement("input"); tempInput.id = tempInputId; tempInput.value = value; tempInput.style = 'position: absolute; right: -10000px'; if (!document.getElementById(tempInputId)) { document.body.appendChild(tempInput); } tempInput.select(); document.execCommand("copy"); document.body.removeChild(tempInput); }; SGPBPopup.prototype.htmlDecode = function(value) { return jQuery('