Skip to content

Instantly share code, notes, and snippets.

@davidbbe
Created June 15, 2015 18:10
Show Gist options
  • Save davidbbe/6ad19ee494c2c46bae62 to your computer and use it in GitHub Desktop.
Save davidbbe/6ad19ee494c2c46bae62 to your computer and use it in GitHub Desktop.
Maker Media set cookie function for hiding and showing newsletter modal- Uses the fancybox.js modal library
<!-- ======================== FANCYBOX NEWSLETTER MODAL ======================== -->
<link rel="stylesheet" href="{{ 'jquery.fancybox.css' | asset_url }}" type="text/css" media="screen" />
<script type="text/javascript" src="{{ 'jquery.fancybox.pack.js' | asset_url }}"></script>
<script>
function getCookie(name) {
var dc = document.cookie;
var prefix = name + "=";
var begin = dc.indexOf("; " + prefix);
if (begin == -1) {
begin = dc.indexOf(prefix);
if (begin != 0) return null;
} else {
begin += 2;
var end = document.cookie.indexOf(";", begin);
if (end == -1) {
end = dc.length;
}
}
return unescape(dc.substring(begin + prefix.length, end));
}
$(function() {
if ( document.location.href.indexOf('campaign') > -1 ) {
var date = new Date();
date.setTime(date.getTime()+(60*24*60*60*1000));
date = date.toGMTString();
document.cookie="Newsletter-signup=; expires=" + date + "; path=/";
}
});
$(function() {
var news_close = getCookie("Newsletter-closed");
var news_signup = getCookie("Newsletter-signup");
if ( news_signup == null ) {
if ( news_close == null ) {
$(".fancybox").fancybox({
openEffect : 'none',
closeEffect : 'none',
autoSize : false,
width : 465,
height : 200,
afterLoad : function() {
this.content = this.content.html();
}
});
// Launch fancyBox on first element
$(".fancybox").fancybox().trigger('click');
$( ".newsletter-set-cookie" ).click(function() {
var date = new Date();
date.setTime(date.getTime()+(60*24*60*60*1000));
date = date.toGMTString();
document.cookie="Newsletter-signup=; expires=" + date + "; path=/";
});
$( ".fancybox-close" ).click(function() {
var date = new Date();
date.setTime(date.getTime()+(7*24*60*60*1000));
date = date.toGMTString();
document.cookie="Newsletter-closed=; expires=" + date + "; path=/";
});
}
}
});
</script>
<div class="fancybox" style="display:none;">
<h3>Sign up today for new product announcements and special offers from Maker Shed</h3>
<script>
$(function() {
$( "input[name='custom_url']" ).val( window.location.href );
});
</script>
<form name="MailingList" action="http://whatcounts.com/bin/listctrl" method="POST">
<input type=hidden name="slid" value="6B5869DC547D3D46510F6AB3E701BA0A" />
<input type="hidden" name="cmd" value="subscribe" />
<input type="hidden" name="custom_host" value="makershed.com" />
<input type="hidden" name="custom_incentive" value="none" />
<input type="hidden" name="custom_source" value="modal" />
<input type="hidden" name="goto" value="http://www.makershed.com/?thankyou" />
<input type="hidden" name="custom_url" value="" />
<input type="email" id="titllrt-titllrt" name="email" placeholder="Your E-mail" required>
<input type="submit" name="Submit" id="newsletter-set-cookie" value="Sign Me Up" class="btn-modal newsletter-set-cookie">
<input type="hidden" id="format_mime" name="format" value="mime" />
</form>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment