//Author : FBolaji //Date : 22-5-2015 /* Brief : Pop-In can be enabled per market and nameplate. Returning visitors to the site who have previously completed a * configuration (pop up shown on entry page except when the entry page is /buildandprice, or SBE pages). * Cookie length: up to 10 days. The cookie stores the details of the configured nameplate, such as model, price and colour etc. * * The pop up for a particular configuration should only be shown once to a returning visitor i.e Returning visitor who have configured a nameplate * will see a pop-in after 5 seconds, and if closed it never display again, unless customer configure another nameplate again. * * If a particular nameplate has been previously configured and disabled the pop-in per nameplate, then the pop-in shouldn't be displayed. * * Meanwhile if pop-in enabled, it will take precedence over any overlay such as EP2defaultOverlay, Psyma, and iPerceptions. */ var EP2 = EP2 || {}; var EngineGlobals = EngineGlobals || {}; !(function($ ,exports,window,undefined){ "use strict"; EP2.popInOverlay = function(options){ var defaults = { expr : -1, enabled : "false" }; this.options = $.extend({}, defaults, options); this.expr = parseInt(this.options.expr); this.enabled = this.options.enabled; this.init(); }; EP2.popInOverlay.prototype = { init : function() { this.$el = $('#popinOverlay'); this.isLocalStorage(); }, isLocalStorage : function() { var noopKey = 'noopData', storage = window.localStorage; try{ storage.setItem('noopKey', 1); storage.removeItem('noopKey'); this.checkCookie(); }catch(e){ console.log('Your web browser does not support storing settings locally. In Safari, the most common cause of this is using "Private Browsing Mode". Some settings may not save or some features may not work properly for you.'); return false; } return true; }, setCookie : function(enabled, expr) { //get cookie enabled and expr opts. var popinVal = enabled, exprDays = expr, d = new Date(); d.setTime(d.getTime() + (exprDays *24*60*60*1000)); this.setData(popinVal, d); }, setData : function(popinVal, d) { this.w = $(window).innerWidth(); var siteTermsEle = $('#buildandprice'); if (this.w >= 768 && popinVal === "true") { var nameplatePopInDisabled = siteTermsEle.data('popin-bootstrap').namePlatePopInDisable; var storedData = JSON.parse(localStorage.getItem('configuredNameplateData')) || {}; var seriesDisabledAjaxURL = ""; var expires ="expires=" + d.toGMTString(); var popIn = "popIn="+popinVal+";", $mobileBnP = $('#mobileBuildPrice'), marketDisclaimer = siteTermsEle.data('popin-bootstrap').NLDisclaimer, displayPriceObj = []; if (bp.nameplateJson === undefined) { bp.nameplateJson = {code:""}; } try { if (nameplatePopInDisabled !== "true") { //check if nameplate uscCode is the same if($.isEmptyObject(storedData) || (!$.isEmptyObject(storedData) && storedData.uscCode.nameplateCode !== (modelCode || bp.nameplateJson.code))){ document.cookie = popIn + expires+";path=/"; } if ($mobileBnP.length) { // for each price block in configuration page $('#basket').find('li span.price').each(function(i,v) { var price = $.trim($(this).text()), type = $.trim($(this).closest('li').attr('class')), moreInfo = ""; if (type === "additional priceDisclaimerWrap") { moreInfo = $.trim($('#retailDisclaimer p:first').text()); } else { moreInfo = $.trim($('#promoDisclaimer p:first').text()); } displayPriceObj.push({price : price, moreInfo:moreInfo, type:type}); }); } else { $('.priceBlock section span.price').each(function(i,v) { var price = $.trim($(this).text()), type = $.trim($(this).closest('section').attr('id')), moreInfo = ""; if (type === "orgPriceBlock") { moreInfo = $.trim($('#price-popover').text()); } else { moreInfo = $.trim($('#discount-popover').text()); } displayPriceObj.push({price : price, moreInfo:moreInfo, type:type}); }); } var co2AjaxUrl = "", co2Data = this.grabCo2tableStructure(); if ($mobileBnP.length) { try { seriesDisabledAjaxURL = '/cs/ContentServer?pagename='+ EP2.Globals.siteName + '/EP2/body/cars/bp/PopInNamePlateService&code='+ modelCode +'&seriesCode='+ bp.mobile.series.code + '&format=mobile'; } catch(e) { //console.log("bp.mobile is not defined.."); } } else { seriesDisabledAjaxURL = '/cs/ContentServer?pagename='+ EP2.Globals.siteName + '/EP2/body/cars/bp/PopInNamePlateService&code='+ bp.nameplateJson.code+'&seriesCode='+ bp.context.series.code; } //for mobile purpose this.brandDesc = ""; this.brand = ""; this.nameplateModel = ""; this.nameplateSeriesName = ""; this.nameplateColor = ""; this.nameplateColorCode = ""; this.modelCode = ""; this.uscSeriesCode = ""; this.image = ""; if (bp.hasOwnProperty("context")) { //for desktop site this.brandDesc = bp.nameplateData.brandDesc; this.brand = bp.nameplateData.brand; this.nameplateSeriesName = bp.context.series.name; this.nameplateColor = bp.context.color.name; this.nameplateColorCode = bp.context.color.code; this.uscSeriesCode = bp.context.series.code; this.imageURL = bp.context.ImageSet.EXTERIOR1.HERO[0].imageURL; } if (typeof model === "undefined") { //for desktop site this.nameplateModel = bp.nameplateData.NameBPOverview || siteTermsEle.data('popin-bootstrap').namePlateName; this.modelCode = bp.nameplateJson.code; } else { // for mobile site try { this.brand = siteTermsEle.data('popin-bootstrap').brand; this.nameplateModel = siteTermsEle.data('popin-bootstrap').namePlateName; this.nameplateSeriesName = bp.mobile.series.name; this.uscSeriesCode = bp.mobile.series.code; this.nameplateColor = bp.mobile.color.name; this.nameplateColorCode = bp.mobile.color.code; this.modelCode = bp.mobile.modelCode; this.imageURL = bp.mobile.ImageSet.exterior[0].Hero; } catch(e) { console.log("bp.mobile is not defined.."); } } //store in local storage try { console.log(this.modelCode); if (this.modelCode !== "") { localStorage.setItem('configuredNameplateData', JSON.stringify({ disabledNameplateSeriesAjaxURL : seriesDisabledAjaxURL, nameplate : {brandDesc: this.brandDesc, brand : this.brand, model : this.nameplateModel, series: this.nameplateSeriesName}, color : {name:this.nameplateColor, code: this.nameplateColorCode}, uscCode :{nameplateCode: this.modelCode, seriesCode: this.uscSeriesCode}, image : this.imageURL, ctaBtn:siteTermsEle.data('popin-bootstrap').ctaBtn, displayPrice: displayPriceObj, configpage : siteTermsEle.data('popin-bootstrap').configpage, testdrvpage: siteTermsEle.data('popin-bootstrap').testdrivepage, dealerlocpage: siteTermsEle.data('popin-bootstrap').dealerlocatorpage, marketDisclaimer : marketDisclaimer, minDisclaimer : siteTermsEle.data('popin-bootstrap').miniDisclaimer, co2 : co2Data })); console.log("Configured nameplate data saved.."); } } catch(e) { } } else { //console.log("Pop In disabled for this nameplate/series"); return; } } catch(e) { console.log("popin nameplate cookie not set..terminated!", e); } } }, isMobileUpdateLocalStorage : function() { var siteTermsEle = $('#buildandprice'); var nameplatePopInDisabled = siteTermsEle.data('popin-bootstrap'); var exprDays = nameplatePopInDisabled.expr, d = new Date(); d.setTime(d.getTime() + (exprDays *24*60*60*1000)); EP2.popInOverlay.prototype.setData("true", d); }, getCookie : function(popinbox) { var name = popinbox + "="; var splitCookie = document.cookie.split(';'); for(var i=0; i= 768 && popup === "true") { // console.log("cookie is set :",popup ); this.supressOtherOverlayPops(); this.createOverlayerBox(); return; } else { this.setCookie(this.enabled, this.expr); return; } }, createOverlayerBox : function() { var getPath = window.location.pathname.split("/"), firstPart = getPath[1], retrieveConfiguredVehicle = JSON.parse(localStorage.getItem('configuredNameplateData')) || {}, localConfig = {modelCode : retrieveConfiguredVehicle.uscCode.nameplateCode, model: retrieveConfiguredVehicle.nameplate.model}, displayContent="", proto = EP2.popInOverlay.prototype, injectCTAbtn = "", price="", configpage = retrieveConfiguredVehicle.configpage, sbePages = ["SBE",configpage], co2DataTable = "", co2Data = retrieveConfiguredVehicle.co2; var $mobileBPpage = $('#mobileBuildPrice'); var isMobileSBEpage =$('body[data-featuredisabled]'); // checking if data-featuredisabled is defined var isFeatured = $('body').attr('data-featuredisabled'); //check and get the value of data-featuredisabled var isDisabled = ""; var delayFn = 0; var isDeviceType = 'desktop'; // need EngineGlobals defined if(!$.isEmptyObject(EngineGlobals)){ if(EngineGlobals.isMobile === true){ isDeviceType = 'phone'; } }else{ // forced isDeviceType to phone isDeviceType = 'phone'; } if(isMobileSBEpage !== undefined && isFeatured !== "popIn1"){ delayFn = 2500; }else{ return; } setTimeout(function(){ // if(isMobileSBEpage !=="popIn1"){ $.ajax({ type:'POST', url:retrieveConfiguredVehicle.disabledNameplateSeriesAjaxURL, dataType:'json' }) .done(function( data ) { var result = data; isDisabled = result.namePlatePopInDisable; }) .complete(function(event, xhr, settings){ if(event.status !== 200){ return; } //TagIT //console.log(isDeviceType, 'uscCode: ', localConfig.modelCode); if(typeof TK != ("undefined" || null)){ TK.broadcast(document.body, 'brand:overlay:build_price_return_pop-in:', { config : localConfig, deviceType : isDeviceType }); } prepareView(); }).error(function(){ console.log("Error! can not show overlay, terminate"); return; }); // } },delayFn); function prepareView(){ if(isDisabled === "true"){ document.cookie = "popIn="+ false+";" + "expires=-1;path=/"; localStorage.removeItem('configuredNameplateData'); console.log("pop-in disabled for ", retrieveConfiguredVehicle.nameplate.model, 'series', retrieveConfiguredVehicle.uscCode.seriesCode ); return; } // display cta buttons if(typeof retrieveConfiguredVehicle.ctaBtn !== undefined){ $.each(retrieveConfiguredVehicle.ctaBtn, function(i,v){ if(this.btnLabel !== 'undefined'){ if(i === 0){ injectCTAbtn += '
'; }else{ injectCTAbtn += ''; } } }); } // price display if(typeof retrieveConfiguredVehicle.displayPrice !== undefined){ $.each(retrieveConfiguredVehicle.displayPrice, function(i,v){ var addClass = ""; if(i === 0){ addClass = "bigHeading"; }else{ addClass = "smallHeading"; } if(this.price != ""){ price += '

'+ this.price +''+ this.moreInfo +'

'; } }); } if(co2Data.emission.rowColTxt.length && co2Data.emission.columHdr.length){ var insertRowVal = ""; $.each(co2Data.emission.rowColTxt, function(i,v){ if(i !== 0){ insertRowVal += ""+v+""; //console.log(v); } }); $('#popinOverlay').find('table.gridtable td:eq(1)').empty().append(insertRowVal); co2DataTable +=''; co2DataTable +=''; co2DataTable +=''; co2DataTable +=''; //co2DataTable +=''; co2DataTable +='
'+co2Data.emission.columHdr[0]+''+co2Data.emission.columHdr[1]+'
'+co2Data.emission.rowColTxt[0]+''+ insertRowVal +''+co2Data.emission.rowColTxt[1]+''+co2Data.emission.rowColTxt[2]+''+co2Data.emission.rowColTxt[3]+''+co2Data.emission.rowColTxt[4]+''+co2Data.emission.rowColTxt[5]+''+co2Data.emission.rowColTxt[6]+''+co2Data.emission.rowColTxt[7]+'
'; } if(!$.isEmptyObject(retrieveConfiguredVehicle)){ // View displayContent = '
'; displayContent += '

'; displayContent += ''; if(!$.isEmptyObject(retrieveConfiguredVehicle.nameplate.brandDesc)){ displayContent += retrieveConfiguredVehicle.nameplate.brandDesc +' '; } if(!$.isEmptyObject(retrieveConfiguredVehicle.nameplate.brand)){ displayContent += retrieveConfiguredVehicle.nameplate.brand +' '; } displayContent += ''; if(!$.isEmptyObject(retrieveConfiguredVehicle.nameplate.model)){ displayContent += ''+ retrieveConfiguredVehicle.nameplate.model +' '; } if(!$.isEmptyObject(retrieveConfiguredVehicle.nameplate.series)){ displayContent += ''+ retrieveConfiguredVehicle.nameplate.series +''; } displayContent += '

'; displayContent += '
'; displayContent += '
'; displayContent += price; if(!$.isEmptyObject(retrieveConfiguredVehicle.marketDisclaimer)){ displayContent += '
'+retrieveConfiguredVehicle.marketDisclaimer + '
'; //special disclaimer for market such as NL } if(!$.isEmptyObject(retrieveConfiguredVehicle.minDisclaimer)){ displayContent += '

'+retrieveConfiguredVehicle.minDisclaimer +'

'; } displayContent += injectCTAbtn; displayContent += '
'; displayContent += '
'+co2DataTable+'
'; //CO2 data displayContent += '
'; // inject co2dataEngineTransmission after table insertion. if(co2Data.emission.rowColTxt.length){ } var launchPopInOverlay = function(){ setTimeout(function(){ overlayer.open({content:displayContent, width:700,height:"auto", callbackAfter: function(){ proto.onSmallDevices(); //TagIT bind cta button $('#popinOverlay').on('click','.test_drive_cta', function(e){ //console.log(isDeviceType, 'uscCode: ', localConfig.modelCode); if(typeof TK != ("undefined" || null)){ TK.broadcast(document.body, 'brand:overlay:build_price_return_pop-in:test_drive_cta:', { config : localConfig, deviceType : isDeviceType }); } }); $('#popinOverlay').on('click','.find_dealer_cta', function(e){ //console.log(isDeviceType, 'uscCode: ', localConfig.modelCode); if(typeof TK != ("undefined" || null)){ TK.broadcast(document.body, 'brand:overlay:build_price_return_pop-in:find_dealer_cta:', { config : localConfig, deviceType : isDeviceType }); } }); }}); $('#overlayBlock').on('click','.closeBtn', proto.popinClosed.bind(this)); $('#overlay').on('click', proto.popinClosed.bind(this)); $('#popinOverlay .moreInfo').on({ 'mouseover':function(e){ var $this=$(this), findSibling = $this.siblings('.price-popover'); findSibling.css({display:'block'}); }, 'mouseleave':function(e){ var $this=$(this), findSibling = $this.siblings('.price-popover'); findSibling.css({ display:'none'}); } }); },2000); }; if(firstPart !== sbePages[0] && firstPart !== sbePages[1]){ //check if page is not BnP, DealerLocator or TestDrive if(isMobileSBEpage !== undefined && isFeatured === "popIn1"){ return; } // console.log("page not one of these...", sbePages); launchPopInOverlay(); return; } } } }, grabCo2tableStructure : function(){ var co2HdrRowColTxt = {emission:{columHdr:[], rowColTxt:[]}}; var columnHdr = $('#co2-dataBlock dt'); var rowColTxt = $('#co2-dataBlock dd'); var $mobileBPpage = EngineGlobals.isMobile; //$('#mobileBuildPrice'); var co2MobileDataList = $('li.DEFAULT .co2-band-data, li.SELECTED .co2-band-data'); var co2MobileDataListInc = $('li.INCLUDED .co2-band-data'); var co2MobilefeatureName = $('#target5 h4').text(); // $('li.DEFAULT .co2-band-data, li.SELECTED .co2-band-data').closest('div').find('.featureName').text(); if($mobileBPpage){ if( co2MobileDataList.length ){ co2HdrRowColTxt.emission.columHdr.push($.trim(co2MobilefeatureName)); co2HdrRowColTxt.emission.columHdr.push($.trim(co2MobileDataList.find('dt').text())); co2HdrRowColTxt.emission.rowColTxt.push($.trim($('li.DEFAULT .co2-band-data, li.SELECTED .co2-band-data').closest('div').find('.featureName').text())); co2MobileDataList.find('dd').each(function(i,v){ co2HdrRowColTxt.emission.rowColTxt.push($.trim($(this).text())); }); // console.log("default or selected"); }else if(co2MobileDataListInc.size() === 1){ co2HdrRowColTxt.emission.columHdr.push($.trim(co2MobilefeatureName)); co2HdrRowColTxt.emission.columHdr.push($.trim(co2MobileDataListInc.find('dt').text())); co2HdrRowColTxt.emission.rowColTxt.push($.trim($('li.INCLUDED .co2-band-data').closest('div').find('.featureName').text())); co2MobileDataListInc.find('dd').each(function(i,v){ co2HdrRowColTxt.emission.rowColTxt.push($.trim($(this).text())); }); // console.log("no default or selected"); } } else{ columnHdr.each(function(i,v){ var el = $(v).is(':hidden'); // console.log("hdr",v, el); if(v !== undefined && el == false){ co2HdrRowColTxt.emission.columHdr.push($.trim($(this).text())); } }); rowColTxt.each(function(i,v){ var el = $(v).is(':hidden'); // console.log("rowcol",v, el); if(v !== undefined && el == false){ co2HdrRowColTxt.emission.rowColTxt.push($.trim($(this).text())); } }); //console.log(co2HdrRowColTxt ); } return co2HdrRowColTxt; }, popinClosed:function(e){ e.preventDefault(); document.cookie = "popIn="+ false+";" + "expires=-1;path=/"; localStorage.removeItem('configuredNameplateData'); console.log("Saved configured nameplate deleted..and cookie removed."); }, TagITevents: function(e){ var data = e.data; var retrieveConfiguredVehicle = JSON.parse(localStorage.getItem('configuredNameplateData')) || {}; var isDeviceType = 'desktop'; if(EngineGlobals.isMobile === true){ isDeviceType = 'phone'; } console.log("tagit broadcast",data); //brand:overlay:build price return pop-in: if(typeof TK != ("undefined" || null)){ TK.broadcast(document.body, data, { uscCode : retrieveConfiguredVehicle.nameplate.model, deviceType : isDeviceType }); } }, supressOtherOverlayPops : function(){ EP2.isOverlayOpened = false; this.$elPerceptions = $('#IPEinL'); this.$elPsyma = $('#psyma_layer'); this.Overlayblock = $('#overlayBlock'); this.overlayContent = $('#overlayContent'); var cssDisplay = {display:'none'}; if(this.$elPerceptions.length){ this.$elPerceptions.css(cssDisplay); this.$elPerceptions.closest('#ipeL').remove(); } if(this.$elPsyma.length){ this.$elPsyma.css(cssDisplay); this.$elPsyma.remove(); } if(this.Overlayblock.length){ this.Overlayblock.css(cssDisplay); $('#overlay').css(cssDisplay); } if(this.overlayContent.length){ this.overlayContent.css(cssDisplay); this.overlayContent.remove(); } // console.log('other overlay popups',this.$elPerceptions, this.$elPsyma, this.Overlayblock, EP2.isOverlayOpened); }, onSmallDevices : function(){ // hide and empty popin overlay and content $(window).on('resize',function(){ var innerW = $(this).innerWidth(); var cssObj = {'display':'none'}; var overlay = $('#overlay'); var overlayBlock = $('#overlayBlock #content'); if(typeof ForceRedirectUserAgents !== undefined){ //on desktop don't hide or empty the overlay on screen resize return; } if(typeof ForceRedirectUserAgents === undefined && innerW < 768){ //mobile device and screen resolution < 768 overlay.css(cssObj); overlayBlock.css(cssObj).empty(); return; } }); } }; return new EP2.popInOverlay(); })(jQuery, this, window);