Skip to content

Instantly share code, notes, and snippets.

@jtsternberg
Last active September 6, 2018 13:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jtsternberg/9ffa1caa91595cc8fc27ac2557ee2897 to your computer and use it in GitHub Desktop.
Save jtsternberg/9ffa1caa91595cc8fc27ac2557ee2897 to your computer and use it in GitHub Desktop.
OM campaign JS which hides the campaign initially and waits for a button to be clicked
<style id="removeMe">
body:not(.app) #om-vxgsvpbsp3jq2n3y5z5r {
display: none !important;
}
</style>
<script>
// CSS class for the bottom slide in button
var buttonClass = 'popup-slide-in';
// Button text of the bottom slide in button
var buttonText = 'Save 15%';
// Set to true if inner page or mobile popup
var hideOnLoad = true;
document.addEventListener('om.Html.append.before', function (event) {
if (!document.getElementsByClassName(buttonClass).length) {
var popupCampaign = event.detail.Campaign;
var prevLoad = popupCampaign.load;
var showPopup = function() {
if ( document.getElementById('removeMe') ) {
document.getElementById('removeMe').remove();
}
return prevLoad.call( popupCampaign );
}
var button = document.createElement('button');
button.innerHTML = buttonText;
button.classList.add(buttonClass);
button.addEventListener('click', function (event) {
showPopup();
this.classList.remove('shown');
}, false);
popupCampaign.load = function() {
if ( window.hideOnLoad ) {
popupCampaign.close();
return new Promise(function(r){ return r()});
}
return showPopup();
};
document.getElementsByTagName('body')[0].appendChild(button);
}
});
document.addEventListener('om.Campaign.afterClose', function (event) {
document.getElementsByClassName(buttonClass)[0].classList.add('shown');
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment