1/** 2 * @file 3 * Homepage banner related js. 4 */ 5(function ($, Drupal, cookies) { 6 // Get homepage mobile text. 7 var mobile_text_wrapper = $('.banner .block-homepagemobilebanner'); 8 if (mobile_text_wrapper.length) { 9 var first_visitor_mobile = mobile_text_wrapper.find('.mobile_first_visitor'); 10 var recent_visitor_mobile = mobile_text_wrapper.find('.mobile_recent_visitor'); 11 12 // Show banner mobile text based upon cookie value. 13 var displaytext = generateHomepageDisplay('mobile_return_user', first_visitor_mobile, recent_visitor_mobile); 14 15 // Show homepage mobile text. 16 displaytext.show(); 17 18 // Set a cookie for returning users. 19 cookies.set('mobile_return_user', 'Returning user', { 20 expires: 365, // Cookie expires in one year. 21 samesite: 'Strict', 22 secure: true 23 }); 24 } 25 26 // Get the banner images wrapper for displaying banners for first-time and returning users. 27 var banner_images_wrapper = $('.banner .homepage-banner-images, .banner .pex-homepage-banner-images'); 28 if (banner_images_wrapper.length) { 29 var returning_user_banners = banner_images_wrapper.find('.return-user'); 30 var first_time_user_banners = banner_images_wrapper.find('.first-time-user'); 31 var banner_images = generateHomepageDisplay('return_user', first_time_user_banners, returning_user_banners); 32 33 if (banner_images.length) { 34 // Determine how many banners are configured. 35 var count = banner_images.length; 36 37 // Find a random element from our pool of banners. 38 var randomBanner = banner_images[Math.floor(Math.random() * count)]; 39 40 // Get the ID of our random banner. 41 var randomBannerID = randomBanner.id; 42 43 // Now we know which element we want to work with, target it from the banner wrapper. 44 var displayBanner = banner_images_wrapper.find('#' + randomBannerID); 45 46 // Gather the banner image URL (using the desktop image URL here as fallback). 47 var imageUrl = displayBanner.attr('data-desktop-banner-image'); 48 49 // Set the tab and desktop background images. 50 if (!$('.banner .homepage-banner-images .banner-image, .banner .pex-homepage-banner-images .banner-image').hasClass('banner-displayed')) { 51 displayBanner.css({ 52 "background-image": "url(" + imageUrl + ")", 53 "display": "block" 54 }); 55 56 displayBanner.addClass('banner-displayed'); 57 } 58 59 // Finally set a cookie to target returning users. 60 61 cookies.set('return_user', 'Returning user', { 62 expires: 365, // Cookie expires in one year. 63 samesite: 'Strict', 64 secure: true 65 }); 66 } 67 } 68 69 /** 70 * Generates homepage banner first-time and recent visitor HTML. 71 * @param {cookie_name} - Cookie for recent visitor on site. 72 * @param {first_visitor} - HTML of first visitor div. 73 * @param {recent_visitor} - HTML of recent visitor div. 74 */ 75 function generateHomepageDisplay(cookie_name, first_visitor, recent_visitor) { 76 var output = ''; 77 78 if (cookies.get(cookie_name) && recent_visitor.length) { 79 // Use the returning user. 80 output = recent_visitor; 81 } else { 82 // Use the first-time user. 83 output = first_visitor; 84 } 85 return output; 86 } 87 88})(jQuery, Drupal, window.Cookies);
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.