1// Download popup 2(function($) { 3 'use strict'; 4 5 var make = { 6 /** 7 * 8 */ 9 init: function() { 10 var self = this; 11 12 this.cache = { 13 $window: $(window), 14 $document: $(document), 15 $header: $('.overview-background-container'), 16 $popupButton: $('#download-popup-button-open'), 17 $popupContainer: $('#download-popup-wrapper') 18 }; 19 20 // self.headerImage(); 21 22 this.cache.$document.ready(function() { 23 self.downloadPopup(); 24 } ); 25 }, 26 27 /** 28 * Pick a class to use on the overview-background-container div to display a background image. 29 * 30 * If the browser accepts cookies, it will store the image numbers that have already been displayed so that 31 * there won't be any repeats until all available images have been displayed. 32 */ 33 headerImage: function() { 34 var imageCount = 2, 35 // http://stackoverflow.com/a/10050831 36 origNumbers = Array.apply(null, Array(imageCount)).map(function(_, i){return i+1;}), 37 numbers = $.extend([], origNumbers), 38 seenNumbers = [], 39 // http://stackoverflow.com/a/25984542 40 shuffle = function(a,b,c,d) { 41 c=a.length;while(c)b=Math.random()*c--|0,d=a[c],a[c]=a[b],a[b]=d 42 }, 43 chosenNum, cookie; 44 45 // Get stored list of seen image numbers 46 if ('undefined' !== typeof Cookies) { 47 cookie = Cookies.getJSON('make-headers'); 48 49 if ('undefined' !== typeof cookie) { 50 seenNumbers = $.extend([], cookie); 51 52 $.each(seenNumbers, function(i, num) { 53 var index = numbers.indexOf(num); 54 if (index > -1) { 55 numbers.splice(index, 1); 56 } 57 }); 58 } 59 60 if (numbers.length < 1) { 61 numbers = $.extend([], origNumbers); 62 } 63 } 64 65 // Choose a number from the list of available 66 shuffle(numbers); 67 chosenNum = numbers.shift(); 68 69 // Update the stored list of seen numbers 70 if ('undefined' !== typeof Cookies) { 71 seenNumbers.push(chosenNum); 72 73 if (seenNumbers.length >= origNumbers.length) { 74 Cookies.remove('make-headers', { 75 path: '/wordpress-themes/make' 76 }); 77 } else { 78 Cookies.set('make-headers', seenNumbers, { 79 expires: 1, 80 path: '/wordpress-themes/make' 81 }); 82 } 83 } 84 85 // Set the image number class 86 make.cache.$header.addClass('image-' + chosenNum); 87 }, 88 89 /** 90 * 91 */ 92 downloadPopup: function() { 93 var $button = make.cache.$popupButton, 94 $popup = make.cache.$popupContainer, 95 $form = $('#download-popup-form'), 96 $download = $('.download-popup__link'), 97 $close = $('#download-popup-button-close'), 98 $email = $('#download-popup-email-field'), 99 $url = $('#download-popup-url-field'), 100 $submit = $form.find('.download-popup__submit'), 101 $spinner = $popup.find('.download-popup__spinner'), 102 $step1 = $popup.find('.download-popup__step--one'), 103 $step2 = $popup.find('.download-popup__step--two'); 104 105 // Initialize popup and components 106 if ($button.length > 0 && $popup.length > 0) { 107 // Initialize the "Get Make" button 108 $button.on('click', function(evt) { 109 evt.preventDefault(); 110 $popup.addClass('download-popup-wrapper--active'); 111 $email.focus(); 112 }); 113 114 // Initialize the "Close" button in modal 115 $close.on('click', function(evt) { 116 evt.preventDefault(); 117 $popup.removeClass('download-popup-wrapper--active'); 118 }); 119 120 // Initialize download link 121 $download.on('click', function() { 122 $popup.removeClass('download-popup-wrapper--active'); 123 }); 124 } 125 126 if ( window.emailOctopus ) { 127 var emailOctopusAjaxSuccess = window.emailOctopus.ajaxSuccess; 128 129 window.emailOctopus.ajaxSuccess = function() { 130 $popup.removeClass('download-popup-wrapper--active'); 131 132 return emailOctopusAjaxSuccess.apply( this, arguments ); 133 } 134 } 135 }, 136 137 /** 138 * @link https://css-tricks.com/snippets/javascript/get-url-variables/ 139 */ 140 getQueryVariable: function(variable) { 141 var query = window.location.search.substring(1), 142 vars = query.split('&'); 143 for (var i = 0; i < vars.length; i++) { 144 var pair = vars[i].split('='); 145 if (pair[0] == variable) { 146 return pair[1]; 147 } 148 } 149 return false;
150 } 151 }; 152 153 make.init(); 154})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.