1/** 2 * @file 3 * A JavaScript file for the Hero component. 4 */ 5 6((Drupal) => { 7 Drupal.behaviors.hero = { 8 attach: context => { 9 const heroTitle = context.querySelector(".c--hero__title"); 10 if (heroTitle) { 11 const now = new Date(); 12 const hours = now.getHours(); 13 let greeting = ''; 14 if (hours >= 5 && hours < 12) { 15 greeting = 'Good Morning,'; 16 } else if (hours >= 12 && hours < 17) { 17 greeting = 'Good Afternoon,'; 18 } else { 19 greeting = 'Good Evening,'; 20 } 21 heroTitle.textContent = greeting; 22 heroTitle.appendChild(document.createElement('br')); // Add a line break 23 heroTitle.appendChild(document.createTextNode('Baltimore')); 24 } 25 const heroSection = context.querySelector('.c--hero'); 26 const imagesJson = heroSection.getAttribute('data-images'); 27 if (imagesJson) { 28 const images = JSON.parse(imagesJson); 29 const imageObjects = []; 30 // Preload images 31 images.forEach(imageUrl => { 32 const img = new Image(); 33 img.src = imageUrl; 34 imageObjects.push(img); 35 }); 36 37 let currentIndex = 0; 38 function changeBackgroundImage() { 39 heroSection.style.backgroundImage = `url(${images[currentIndex]})`; 40 currentIndex = (currentIndex + 1) % images.length; 41 } 42 changeBackgroundImage(); 43 setInterval(changeBackgroundImage, 5000); 44 } else { 45 console.error('data-images attribute is null or empty.'); 46 } 47 }, 48 }; 49})(Drupal);
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.