Skip to content

Instantly share code, notes, and snippets.

@neodigm
Created December 13, 2018 21:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save neodigm/84560e91f1a07680fd1a23c9e5da6bec to your computer and use it in GitHub Desktop.
Save neodigm/84560e91f1a07680fd1a23c9e5da6bec to your computer and use it in GitHub Desktop.
The email promo dialog script and markup are below. The markup must exist in the DOM before the JS is executed. The modal will show once every seven (7) days. The image displayed will be determined by the site brand. Clicking on the image will open the drawer and the email panel then close the reveal. If the reveal component is not on the page t…
"use strict";
// Show email promo image (branded) reveal once, every 7 days
// Open drawer to email panel when clicked
var fElmRevPromo = function( _d, _aIds ){
var _eRev = _d.getElementById( _aIds[0] ), _sBrand="LTD";
var _eRevI = _d.getElementsByClassName( _aIds[1] )[0];
return {
init: function( sBrand ){
if( sBrand && ( typeof _eRevI != "undefined") ){
_sBrand = (sBrand.toUpperCase() == "LTD") ? "LTD" : "LSC";
_eRevI.addEventListener("click", function( e ){
if( typeof ltdc_promo_drawer != "undefined" ){
if(typeof ltdc_reveal != "undefined"){
ltdc_reveal.close();
}else{
$("#" + _aIds[0] ).foundation("reveal", "close");
}
ltdc_promo_drawer.open("email", "e_leftnav_email_p");
}
}, true );
this.open();
}
},
open: function(){
var sLocSt = localStorage.getItem("ltdc_elm_rev_promo");
if( sLocSt ){ // Reset if time limit elapsed
var dLS = new Date( Number( sLocSt ) ), dNow = new Date();
if( dLS < dNow ){
sLocSt = null;
localStorage.removeItem("ltdc_elm_rev_promo");
}
}
if( !sLocSt ){ // Only on first engagement
var dPlus7days = new Date(Date.now() + 7*24*60*60*1000);
localStorage.setItem("ltdc_elm_rev_promo", dPlus7days.getTime() );
_eRevI.src = _eRevI.dataset.brandSrc.replace( "##", _sBrand );
if( typeof ltdc_reveal != "undefined" ){
ltdc_reveal.autoOpen("js-elmRev__promo--id");
}else{
$("#" + _aIds[0] ).foundation("reveal", "open");
}
}
}
}
}( document, ["js-elmRev__promo--id", "js-elmRev__image"]);
fElmRevPromo.init( document.body.dataset.brand );
<ltdc-reveal class="l-reveal reveal__init">
<a data-reveal-id="js-elmRev__promo--id" href="#" aria-label="Email Promo"></a>
<section id="js-elmRev__promo--id" class="reveal-modal small" data-reveal="" aria-hidden="true"
style="max-width:404px;">
<a class="close-reveal-modal resp_x eml-msg__x">
<svg fill="#FFF" height="38" viewBox="0 0 38 38" width="38" xmlns="http://www.w3.org/2000/svg"><path d="M0 0h24v24H0z" fill="none"></path><path d="M14.59 8L12 10.59 9.41 8 8 9.41 10.59 12 8 14.59 9.41 16 12 13.41 14.59 16 16 14.59 13.41 12 16 9.41 14.59 8zM12 2C6.47 2 2 6.47 2 12s4.47 10 10 10 10-4.47 10-10S17.53 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8z"></path></svg>
</a>
<img class="js-elmRev__image"
style="cursor:pointer;"
data-brand-src="/images/##-EMAIL-POP-UP-BANNER.png" alt="Email Promo">
</section>
</ltdc-reveal>
@neodigm
Copy link
Author

neodigm commented Dec 13, 2018

Modified so that the branded image will not be requested unless reveal (popup lightbox) is going to open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment