Skip to content

Instantly share code, notes, and snippets.

@ethangardner
Last active August 29, 2015 14:04
Show Gist options
  • Save ethangardner/f05d326a6620f4faf0f4 to your computer and use it in GitHub Desktop.
Save ethangardner/f05d326a6620f4faf0f4 to your computer and use it in GitHub Desktop.
Interstitial ad object
ENGAGE.Interstitial = function(options) {
if (!(this instanceof ENGAGE.Interstitial)) {
return new ENGAGE.Interstitial(options);
}
if (typeof options !== "undefined") {
this.blocked_class = options.blocked_class || this.blocked_class;
this.close_control = options.close_control || this.close_control;
this.container = options.container || this.container;
this.countdown = options.countdown || this.countdown;
this.fade_time = options.fade_time || this.fade_time;
this.modal_screen = options.modal_screen || this.modal_screen;
this.timer = options.timer || this.timer;
}
return this;
};
ENGAGE.Interstitial.prototype.blocked_class = 'blocked';
ENGAGE.Interstitial.prototype.close_control = jQuery('#interstitial-header .close-btn');
ENGAGE.Interstitial.prototype.container = jQuery('#interstitial-container');
ENGAGE.Interstitial.prototype.countdown = jQuery("#interstitialCountdown");
ENGAGE.Interstitial.prototype.fade_time = 500;
ENGAGE.Interstitial.prototype.modal_screen = jQuery('<div class="interstitial-modal-screen"><iframe src="javascript:false;"></iframe></div>');
ENGAGE.Interstitial.prototype.timer = 15;
ENGAGE.Interstitial.prototype.open = function() {
var that = this;
jQuery('body').addClass(this.blocked_class).append(this.modal_screen);
this.modal_screen
.css('opacity', 0.9)
.height(jQuery(window).height())
.width(jQuery(window).width())
.children(0).css('opacity',0);
this.modal_screen.fadeIn(this.fade_time, function() {
that.container.show();
});
};
ENGAGE.Interstitial.prototype.close = function() {
jQuery('body').removeClass(this.blocked_class);
this.modal_screen.remove();
this.container.remove();
};
ENGAGE.Interstitial.prototype.interCountDown = function(count) {
var that = this;
if (count >= 0) {
this.countdown.html(count);
setTimeout(function () {
that.interCountDown(count - 1);
}, 1000);
}
else {
this.close();
}
};
ENGAGE.Interstitial.prototype.init = function() {
if (typeof jQuery === "undefined") {
if (window.console && window.console.log) {
console.log("jQuery is not defined before the Interstitial methods are being called");
}
return;
}
else {
var that = this;
this.open();
this.interCountDown(this.timer);
this.close_control.on('click', function() {
that.close();
});
return this;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment