Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Downloader Modal
- $(document).ready(function() {
- function downloadModal() {
- // Class alias
- var dm = this;
- // Class attributes
- dm.modal = $('.download-modal');
- dm.overlay = dm.modal.parent();
- dm.form = dm.modal.find('.download-form');
- dm.offers = [];
- dm.done = false;
- dm.clicked = false;
- dm.closed = false;
- /**
- * Constructor method that handles the modal setup.
- *
- * @return null
- */
- dm.init = function() {
- dm.determineInstall();
- dm.hookOpenEvent();
- dm.hookCloseEvent();
- dm.hookResubmitEvent();
- dm.hookProgressEvent();
- }
- /**
- * Registers the modal open event, which
- * fires when a trigger link is clicked.
- *
- * @return null
- */
- dm.hookOpenEvent = function() {
- $('a[href="#download-modal-trigger"]').on('click', function(e) {
- e.preventDefault();
- if ( ! supported ) // user is on unsupported device
- return false;
- if ( ! dm.clicked ) {
- dm.clicked = true;
- fireImpression('download_modal_open'); // Fire modal open impression
- }
- if ( dm.closed ) {
- fireImpression('download_modal_reopened');
- }
- dm.overlay.fadeIn(150);
- });
- }
- /**
- * Registers the modal close event, which fires
- * when a user clicks on the close button.
- *
- * @return null
- */
- dm.hookCloseEvent = function() {
- dm.modal.find('.close').on('click', function() {
- if ( dm.done ) {
- dm.closed = true;
- dm.overlay.trigger('close');
- } else {
- if ( dm.modal.find('.cancel:visible').length == 0 ) {
- dm.modal.find('.screen').hide();
- dm.modal.find('.cancel').show();
- $('.cancel').find('.modal-button').on('click', function() {
- if ( $(this).hasClass('accept') ) {
- dm.modal.find('.screen').hide();
- dm.modal.find('.screen').first().show();
- } else {
- dm.closed = true;
- fireImpression('download_modal_cancel'); // Fire close impression
- dm.overlay.trigger('close');
- }
- });
- } else {
- dm.closed = true;
- fireImpression('download_modal_cancel'); // Fire close impression
- dm.overlay.trigger('close');
- }
- }
- // reset installer
- dm.done = false;
- dm.offers = [];
- });
- dm.overlay.on('close', function() {
- dm.overlay.fadeOut(350);
- // reset modal
- setTimeout(function() {
- dm.modal.find('.screen').hide();
- dm.modal.find('.screen').first().show();
- }, 400);
- });
- }
- /**
- * Registers the modal resubmit event, which fires when the secondary
- * download button within the thank you screen is clicked.
- *
- * @return null
- */
- dm.hookResubmitEvent = function() {
- dm.modal.find('.resubmit').on('click', function(e) {
- e.preventDefault();
- dm.form[0].submit();
- fireImpression('download_modal_resubmitted');
- });
- }
- /**
- * Registers the screen progression event, which
- * controls what screen is shown within the modal.
- *
- * @return null
- */
- dm.hookProgressEvent = function() {
- dm.modal.find('.modal-button, .skip-all').on('click', function(e) {
- // get current screen
- var button = $(this);
- var current = button.closest('.screen');
- var last = current.hasClass('last-offer');
- if ( button.attr('href').indexOf(".exe") == -1 )
- e.preventDefault();
- // check if offer was accepted
- if ( current.hasClass("pitch") || current.hasClass('offer') ) {
- if ( button.hasClass('accept') ) {
- if ( current.hasClass('offer') )
- dm.offers.push( current.attr('id') ); // add offer
- current.hide();
- current.next().show(); // proceed to next screen
- }
- if ( button.hasClass('decline') || button.hasClass('skip-all') ) {
- last = true;
- current.hide();
- $('.loading').show(); // proceed to download screen
- }
- }
- if ( last ) {
- dm.trackOffers(); // track offers accepted
- dm.download(); // fire off download link
- }
- });
- }
- /**
- * Determines which offers have been accepted, and
- * then fires off impressions for the ones selected.
- *
- * @return null
- */
- dm.trackOffers = function() {
- var impressions = [];
- if ( $.inArray('rockettab', dm.offers) > -1 ) impressions.push("download_modal_rt");
- if ( $.inArray('geniusbox', dm.offers) > -1 ) impressions.push("download_modal_gb");
- if ( $.inArray('malware360', dm.offers) > -1 ) impressions.push("download_modal_mw360");
- if ( impressions.length > 0 ) {
- $.each(impressions, function(key, value) {
- setTimeout(function() {
- fireImpression(value); // Fire individual impressions
- }, 150 * key);
- });
- }
- }
- /**
- * Handles the download and conversion logic.
- *
- * @return null
- */
- dm.download = function() {
- fireImpression('download_modal_done'); // Fire done impression
- $('.screen').hide();
- $('.thankyou').show();
- // offer has been accepted
- if ( dm.offers.length > 0 ) {
- displayDirections("");
- // ensure that mw360 is downloaded in the case that it's selected
- if ( $.inArray('malware360', dm.offers) > -1 )
- dm.form.find('[name="install_mw360"]').attr('value', '1');
- dm.form[0].submit();
- fireImpression('download_modal_qi'); // Fire done (Setup Complete) impression
- setTimeout(function() {
- $('<iframe src="//www.googletagmanager.com/ns.html?id=GTM-NXCL2Q" height="0" width="0" style="display:none;visibility:hidden"></iframe>').appendTo($('body')); // AdWords Conversion Pixels
- }, 400);
- } else {
- $('.thankyou').find('.resubmit-wrapper').remove();
- setTimeout(function() {
- window.location = pitchDownloadUrl; // Go to "thank you" page
- }, 1500);
- }
- dm.done = true;
- }
- /**
- * Determines what should be installed (based off a precheck).
- *
- * @return null
- */
- dm.determineInstall = function() {
- var installGb = ( ! window['gb_installed'] ) ? 1 : 0;
- var installBsg = ( ! window['bsg_installed'] ) ? 1 : 0;
- // Update param values
- $('[name="install_gb"]').attr('value', installGb);
- $('[name="install_bsg"]').attr('value', installBsg);
- }
- }
- // Runs the class
- var modal = new downloadModal();
- modal.init();
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement