1// class ScrollTrigger { 2// constructor({pageId, offset}) { 3// this.pageId = pageId; 4// this.offset = offset; 5// this.pageElement = document.getElementById(pageId); 6// if (!this.pageElement) { 7// throw new Error(`Element with ID "${pageId}" not found.`); 8// } 9// this.handleScroll = this.handleScroll.bind(this); 10// this.init(); 11// } 12 13// init() { 14// // Fire immediately if the document is ready 15// document.addEventListener('DOMContentLoaded', () => { 16// this.checkIfInView(); 17// window.addEventListener('scroll', this.handleScroll); 18 19 20// // Listen for 'malgamReady' and fire handleScroll 21// document.addEventListener('malgamReady', this.handleScroll); 22// }); 23// } 24 25// checkIfInView() { 26// const rect = this.pageElement.getBoundingClientRect(); 27// if (rect.top >= -this.offset && rect.bottom <= window.innerHeight + this.offset) { 28// googletag.cmd.push(() => { 29// googletag.display(this.pageId); // Use an arrow function to preserve `this` 30// }); 31// this.cleanup(); // Stop listening after trigger 32// } 33// } 34 35// handleScroll() { 36// this.checkIfInView(); 37// } 38 39// cleanup() { 40// window.removeEventListener('scroll', this.handleScroll); 41// } 42// } 43 44class ScrollTrigger { 45 constructor({pageId, offset}) { 46 this.pageId = pageId; 47 this.offset = offset; 48 this.triggered = false; // â add this 49 this.pageElement = document.getElementById(pageId); 50 if (!this.pageElement) { 51 throw new Error(`Element with ID "${pageId}" not found.`); 52 } 53 this.handleScroll = this.handleScroll.bind(this); 54 this.init(); 55 } 56 57 init() { 58 document.addEventListener('DOMContentLoaded', () => { 59 this.checkIfInView(); 60 window.addEventListener('scroll', this.handleScroll); 61 document.addEventListener('malgamReady', this.handleScroll); 62 }); 63 } 64 65 checkIfInView() { 66 if (this.triggered) return; // â guard against double-fire 67 const rect = this.pageElement.getBoundingClientRect(); 68 if (rect.top >= -this.offset && rect.bottom <= window.innerHeight + this.offset) { 69 this.triggered = true; // â set before the async googletag call 70 googletag.cmd.push(() => { 71 googletag.display(this.pageId); 72 }); 73 this.cleanup(); 74 } 75 } 76 77 handleScroll() { 78 this.checkIfInView(); 79 } 80 81 cleanup() { 82 window.removeEventListener('scroll', this.handleScroll); 83 document.removeEventListener('malgamReady', this.handleScroll); // â also remove this 84 } 85}
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.