Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Downloader Modal
  2. $(document).ready(function() {
  3.  
  4.     function downloadModal() {
  5.  
  6.         // Class alias
  7.         var dm = this;
  8.  
  9.         // Class attributes
  10.         dm.modal = $('.download-modal');
  11.         dm.overlay = dm.modal.parent();
  12.         dm.form = dm.modal.find('.download-form');
  13.         dm.offers = [];
  14.         dm.done = false;
  15.         dm.clicked = false;
  16.         dm.closed = false;
  17.  
  18.         /**
  19.          * Constructor method that handles the modal setup.
  20.          *
  21.          * @return null
  22.          */
  23.         dm.init = function() {
  24.             dm.determineInstall();
  25.             dm.hookOpenEvent();
  26.             dm.hookCloseEvent();
  27.             dm.hookResubmitEvent();
  28.             dm.hookProgressEvent();
  29.         }
  30.  
  31.         /**
  32.          * Registers the modal open event, which
  33.          * fires when a trigger link is clicked.
  34.          *
  35.          * @return null
  36.          */
  37.         dm.hookOpenEvent = function() {
  38.             $('a[href="#download-modal-trigger"]').on('click', function(e) {
  39.                 e.preventDefault();
  40.  
  41.                 if ( ! supported ) // user is on unsupported device
  42.                     return false;
  43.                
  44.                 if ( ! dm.clicked ) {
  45.                     dm.clicked = true;
  46.                     fireImpression('download_modal_open'); // Fire modal open impression
  47.                 }
  48.  
  49.                 if ( dm.closed ) {
  50.                     fireImpression('download_modal_reopened');
  51.                 }
  52.  
  53.                 dm.overlay.fadeIn(150);
  54.             });
  55.         }
  56.  
  57.         /**
  58.          * Registers the modal close event, which fires
  59.          * when a user clicks on the close button.
  60.          *
  61.          * @return null
  62.          */
  63.         dm.hookCloseEvent = function() {
  64.             dm.modal.find('.close').on('click', function() {
  65.                 if ( dm.done ) {
  66.                     dm.closed = true;
  67.                     dm.overlay.trigger('close');
  68.                 } else {
  69.                     if ( dm.modal.find('.cancel:visible').length == 0 ) {
  70.                         dm.modal.find('.screen').hide();
  71.                         dm.modal.find('.cancel').show();
  72.  
  73.                         $('.cancel').find('.modal-button').on('click', function() {
  74.                             if ( $(this).hasClass('accept') ) {
  75.                                 dm.modal.find('.screen').hide();
  76.                                 dm.modal.find('.screen').first().show();
  77.                             } else {
  78.                                 dm.closed = true;
  79.                                 fireImpression('download_modal_cancel'); // Fire close impression
  80.                                 dm.overlay.trigger('close');
  81.                             }
  82.                         });
  83.                     } else {
  84.                         dm.closed = true;
  85.                         fireImpression('download_modal_cancel'); // Fire close impression
  86.                         dm.overlay.trigger('close');
  87.                     }
  88.                 }
  89.  
  90.                 // reset installer
  91.                 dm.done = false;
  92.                 dm.offers = [];
  93.             });
  94.  
  95.             dm.overlay.on('close', function() {
  96.                 dm.overlay.fadeOut(350);
  97.                 // reset modal
  98.                 setTimeout(function() {
  99.                     dm.modal.find('.screen').hide();
  100.                     dm.modal.find('.screen').first().show();
  101.                 }, 400);
  102.             });  
  103.         }
  104.  
  105.         /**
  106.          * Registers the modal resubmit event, which fires when the secondary
  107.          * download button within the thank you screen is clicked.
  108.          *
  109.          * @return null
  110.          */
  111.         dm.hookResubmitEvent = function() {
  112.             dm.modal.find('.resubmit').on('click', function(e) {
  113.                 e.preventDefault();
  114.  
  115.                 dm.form[0].submit();
  116.                 fireImpression('download_modal_resubmitted');
  117.             });
  118.         }
  119.  
  120.         /**
  121.          * Registers the screen progression event, which
  122.          * controls what screen is shown within the modal.
  123.          *
  124.          * @return null
  125.          */
  126.         dm.hookProgressEvent = function() {
  127.             dm.modal.find('.modal-button, .skip-all').on('click', function(e) {
  128.                 // get current screen
  129.                 var button = $(this);
  130.                 var current = button.closest('.screen');
  131.                 var last = current.hasClass('last-offer');
  132.  
  133.                 if ( button.attr('href').indexOf(".exe") == -1 )
  134.                     e.preventDefault();
  135.  
  136.                 // check if offer was accepted
  137.                 if ( current.hasClass("pitch") || current.hasClass('offer') ) {
  138.  
  139.                     if ( button.hasClass('accept') ) {
  140.                         if ( current.hasClass('offer') )
  141.                             dm.offers.push( current.attr('id') ); // add offer
  142.                        
  143.                         current.hide();
  144.                         current.next().show(); // proceed to next screen
  145.                     }
  146.  
  147.                     if ( button.hasClass('decline') || button.hasClass('skip-all') ) {
  148.                         last = true;
  149.                         current.hide();
  150.                         $('.loading').show(); // proceed to download screen
  151.                     }
  152.                 }
  153.  
  154.                 if ( last ) {
  155.                     dm.trackOffers(); // track offers accepted
  156.                     dm.download(); // fire off download link
  157.                 }
  158.             });
  159.         }
  160.  
  161.         /**
  162.          * Determines which offers have been accepted, and
  163.          * then fires off impressions for the ones selected.
  164.          *
  165.          * @return null
  166.          */
  167.         dm.trackOffers = function() {
  168.             var impressions = [];
  169.  
  170.             if ( $.inArray('rockettab', dm.offers) > -1 )  impressions.push("download_modal_rt");
  171.             if ( $.inArray('geniusbox', dm.offers) > -1 )  impressions.push("download_modal_gb");
  172.             if ( $.inArray('malware360', dm.offers) > -1 ) impressions.push("download_modal_mw360");
  173.  
  174.             if ( impressions.length > 0 ) {
  175.                 $.each(impressions, function(key, value) {
  176.                     setTimeout(function() {
  177.                         fireImpression(value); // Fire individual impressions
  178.                     }, 150 * key);
  179.                 });
  180.             }
  181.         }
  182.  
  183.         /**
  184.          * Handles the download and conversion logic.
  185.          *
  186.          * @return null
  187.          */
  188.         dm.download = function() {
  189.             fireImpression('download_modal_done'); // Fire done impression
  190.  
  191.             $('.screen').hide();
  192.             $('.thankyou').show();
  193.  
  194.             // offer has been accepted
  195.             if ( dm.offers.length > 0 ) {
  196.                 displayDirections("");
  197.                    
  198.                 // ensure that mw360 is downloaded in the case that it's selected
  199.                 if ( $.inArray('malware360', dm.offers) > -1 )
  200.                     dm.form.find('[name="install_mw360"]').attr('value', '1');
  201.                 dm.form[0].submit();
  202.  
  203.                 fireImpression('download_modal_qi'); // Fire done (Setup Complete) impression
  204.  
  205.                 setTimeout(function() {
  206.                     $('<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
  207.                 }, 400);
  208.             } else {
  209.                 $('.thankyou').find('.resubmit-wrapper').remove();
  210.                 setTimeout(function() {
  211.                     window.location = pitchDownloadUrl;  // Go to "thank you" page
  212.                 }, 1500);
  213.             }
  214.  
  215.             dm.done = true;
  216.         }
  217.  
  218.         /**
  219.          * Determines what should be installed (based off a precheck).
  220.          *
  221.          * @return null
  222.          */
  223.         dm.determineInstall = function() {
  224.             var installGb  = ( ! window['gb_installed'] )  ? 1 : 0;
  225.             var installBsg = ( ! window['bsg_installed'] ) ? 1 : 0;
  226.  
  227.             // Update param values
  228.             $('[name="install_gb"]').attr('value', installGb);
  229.             $('[name="install_bsg"]').attr('value', installBsg);
  230.         }
  231.     }
  232.  
  233.     // Runs the class
  234.     var modal = new downloadModal();
  235.     modal.init();
  236. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement