/** * This is the class that will implement the Splash Page or the light box content type. * * Use init() method to instantiate it. Pass the options object while invoking init. * * */ SplashLightbox = function () { var config = {}; var setCookies = function () { /* Set The Cookie */ var cookieObj = { 'path': '/' }; if (jQuery.cookie(config.cookieName) == null) { var milliSeconds; if (config.displayRate === "0") { cookieObj.expires = new Date(); } else if (config.displayRate == "-1") { cookieObj.expires = null; } else { milliSeconds = getMilliSeconds(config.displayRate); var date = new Date(); date.setTime(date.getTime() + milliSeconds); cookieObj.expires = date; } jQuery.cookie(config.cookieName, 1, cookieObj); } }; var showLightbox = function () { /*If it is mobile, insert it as the first child of body. */ if (window.matchMedia("only screen and (max-width : 767px)").matches) { /*mobile*/ showLightboxMobile(); } else { showLightboxDesktop(); } }; var showLightboxMobile = function () { var lbParent = config.blockSelector; var $lightBoxContent = jQuery(lbParent + " " + ".lightBoxContent"); $lightBoxContent.prependTo("body").show(); jQuery(".lightBoxContent .lightBoxClose a").click(function () { $lbParent = jQuery(this).parents(".lightBoxContent"); if ($lbParent.hasClass("tkt")) { jQuery("#lightBoxContent.lightBoxContent.tkt").removeClass('show_toaster').addClass('hide_toaster'); } else { $lbParent.hide(); jQuery('#page').show(); } }); }; var showLightboxDesktop = function () { /*Check if there is a front page*/ var lbParent = config.blockSelector; var $lightBoxContent = jQuery(lbParent + " " + ".lightBoxContent"); var $frontPage = jQuery('body.front #page'); if (!jQuery("body").hasClass("toaster")) { jQuery('body').append("
"); jQuery(".splash_overall").fadeIn(); jQuery(".splash_overall").click(function () { hideSplashPage(); }); } jQuery('body.front #page').css('overflow', 'visible'); jQuery(lbParent + " " + ".lightBox").fadeIn(); jQuery(lbParent + " " + ".lightBoxWrapper").fadeIn(); $lightBoxContent.fadeIn(); var win_height = document.documentElement.clientHeight; var set_height = (win_height - config.lboxHeight) / 2; var win_width = document.documentElement.clientWidth; var set_width = (win_width - config.lboxWidth) / 2; $lightBoxContent.css('top', set_height + 'px'); $lightBoxContent.css('left', set_width + 'px'); $lightBoxContent.css('width', config.lboxWidth + 'px'); $lightBoxContent.css('height', config.lboxHeight + 'px'); jQuery(".lightBoxClose a").click(function () { $lbParent = jQuery(this).parents(".lightBoxContent"); if ($lbParent.hasClass("tkt")) { $lbParent.removeClass('show_toaster').addClass('hide_toaster'); } else { hideSplashPage(); } }); if (jQuery(window).height() < 600) { jQuery('body.front .view-splash .lightBoxContent iframe').css('height', '600px'); } if (!lbParent === "#tktContainer" || !lbParent === "#tklbContainer") { jQuery(window).load(function () { customLBTracking(); }); } }; var hideSplashPage = function () { var $frontPage = jQuery('body.front #page'); jQuery(".splash_overall").fadeOut(); jQuery(".lightBoxContent:not(.tkt)").fadeOut(); $frontPage.css('overflow', 'hidden'); }; var showNoShow = function () { var yn = true; var inital_cookie = jQuery.cookie(config.cookieName); if (inital_cookie !== null && typeof inital_cookie !== "undefined") { yn = false; } return yn; }; var redirect = function () { /*Check if you can extract the url from the nodeLink*/ //location.href = config.nodeLink; var nodeLink = config.nodeLink; window.location.replace(nodeLink); }; var getMilliSeconds = function (dateString) { var minPattern = /([\d\.]+)m/; var hourPattern = /([\d\.]+)h/; var dayPattern = /([\d\.]+)d/; var milliSeconds = 0; var resultArray; if ((resultArray = minPattern.exec(dateString)) !== null) { milliSeconds = resultArray[1] * 60 * 1000; } if ((resultArray = hourPattern.exec(dateString)) !== null) { milliSeconds += resultArray[1] * 60 * 60 * 1000; } if ((resultArray = dayPattern.exec(dateString)) !== null) { milliSeconds += resultArray[1] * 24 * 60 * 60 * 1000; } return milliSeconds; }; var customLBTracking = function () { var omniVars = {}; omniVars.prop1 = s_dtm.prop1; omniVars.eVar4 = s_dtm.eVar4; omniVars.events = "event16"; omniVars.linkTrackEvents = "event16"; var _campaignName = jQuery(config.blockSelector).find('.views-field-title .field-content').text().trim(); if (_campaignName !== "") { var description = s_dtm.pageName + ":Lightbox:" + _campaignName; } else { var description = s_dtm.pageName + ":Lightbox:" + turnkeyLighboxTitle; } function OmniPrep(omniVars, description) { if (typeof omniVars === "string") { s_dtm.linkTrackVars = 'events'; s_dtm.linkTrackEvents = omniVars; s_dtm.events = omniVars; } else { s_dtm.linkTrackVars = Object.keys(omniVars); s_dtm = jQuery.extend(s_dtm, omniVars); } s_dtm.tl(this, 'o', description); } OmniPrep(omniVars, description); //linktrack jQuery(config.blockSelector).find('.eventtrack-link').unbind('click'); jQuery(config.blockSelector).find('.eventtrack-link').click(function (event) { event.preventDefault(); omniVars = {}; omniVars.prop1 = s_dtm.prop1; omniVars.eVar4 = s_dtm.eVar4; var elementID = jQuery(this).attr('id'); var _description = s_dtm.pageName + ':' + _campaignName + ':' + 'Lightbox' + ':' + WMG.OmnitureConfig.customOmniConfig.EventDescription[elementID]; s_dtm.linkTrackVars = Object.keys(omniVars); s_dtm = jQuery.extend(s_dtm, omniVars); s_dtm.tl(this, 'o', _description); }); }; var getParameterByName = function (name) { name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]"); var regexS = "[\\?&]" + name + "=([^]*)"; var regex = new RegExp(regexS); var results = regex.exec(window.location.search); if (results == null) return ""; else return decodeURIComponent(results[1].replace(/\+/g, " ")); }; var init = function (options) { /*Algorithm * 1. Get the config file for this page. * 3. Set the cookie. * 2. If it is lightbox then call it. * 3. If it is splash call redirect it. * */ if (typeof options !== "undefined") { options = jQuery.parseJSON(options); if (options !== null) { jQuery.extend(true, config, options); } else { return; } } else { return; } var show = showNoShow(); setCookies(); if (show) { if (config.isLightBox === "splash") { if (getParameterByName("frontpage") != "true") { redirect(); } } else { showLightbox(); } } }; return { init: init }; }();