Created
October 21, 2011 19:34
-
-
Save matharchod/1304724 to your computer and use it in GitHub Desktop.
A jQuery script that uses jQuery UI, Modal Popups and Cookies to show content based on a timer and/or a cookie value: used as a way to serve modal content through a JavaScript ad server.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//AD MODALS | |
function myModalClose() { | |
$('.myOverlay, #exposeMask').fadeOut('slow'); | |
$('.ad').css({'position':'relative','margin-left':'auto'}); //SHOW ADS | |
}; | |
function myModalPop(type,timer,target,link,creative,width,height) { //setup for variables coming from ad server script | |
var date = new Date(); | |
date.setTime(date.getTime() + (4 * 60 * 60 * 1000)); //SETTING EXPIRATION TIME FOR COOKIES, in hours*minutes*seconds*milliseconds */ | |
var timer = setTimeout(function(){ | |
var checkOverlay = $('#exposeMask').css('display'); //CHECK TO SEE IF AN OVERLAY IS ALREADY OPEN | |
var checkCookie = $.cookie('myModal'); //CHECK TO SEE IF EMAILGATE HAS FIRED ALREADY | |
if ( checkOverlay == 'block' || checkColorbox == 'block' ) { | |
return false; | |
} | |
else { | |
$('.myOverlay').remove(); //REMOVES ANY EXISTING AD OVERLAY | |
if (type.indexOf('emailgate') > -1) { //if the 'type' contains 'emailgate', create and iFrame in the modal | |
$('body').append('<div class='myOverlay emailgate' id='' + type + ''><iframe src='' + link + '' name='myModaliFrame_Email' width='' + width + '' marginwidth='0' height='' + height + '' marginheight='0' align='top' scrolling='no' frameborder='0' hspace='0' vspace='0'></iframe><img src='' + creative + '' class='hidden'/><a class='myOverlayClose' href='#' onClick='myModalClose();'>CLOSE WINDOW</a></div>'); //CREATE HTML AD | |
} | |
else { | |
$('body').append('<div class='myOverlay' id=''+ type +''><a href='' + link + '' target='' + target + ''><img src='' + creative + '' width='950' /></a></div>'); //CREATE IMAGE AD | |
} | |
$('.myOverlay').overlay({ // overlay settings | |
left: 'center', | |
expose: { | |
color: '#000', loadSpeed: 0, opacity: 0.8, loadSpeed: 'slow' | |
}, | |
absolute: true, oneInstance: true, fixed: true, | |
onBeforeLoad: function(){ | |
$('.ad').css({'position':'absolute','margin-left':'-100000px'}); //HIDE ADS | |
var value = $.cookie('myModal'); //CHECK VALUE OF myModal | |
if (value == '' || value == null) { //if myModal does not exist or if it's an iFrame, create it and add type to value | |
$.cookie('myModal', type , { path: '/', domain: 'mysite.com'}); //creates cookie called myModal, sets value to type | |
} | |
else if (value.indexOf(type) > -1) { //if value already exists in myModal, do not duplicate | |
return true; | |
} | |
else { | |
$.cookie('myModal', value + '&' + type , { path: '/', domain: 'mysite.com', expires: date}); //if myModal does exist, add new value with delimiter | |
} | |
}, | |
onClose: function(){ | |
$('.ad').css({'position':'relative','margin-left':'auto'}); //SHOW ADS | |
$('.myOverlay, #exposeMask').css({'display':'none'}); | |
}, | |
closeOnClick: true, closeOnEsc: true, api: true | |
}).load(); //load overlay | |
} | |
}, timer ); //set the timer, variables coming from ad script | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment