PageSourceSearch

https://www.gastroenterologyadvisor.com/wp-content/plugins/hm-lega…/js/legal-notifier-modal.js?ver=1.0.7

js gastroenterologyadvisor.com collected 2026-10-04 11:52:06 UTC 4,056 bytes, 100 lines download raw bytes

1document.addEventListener( 'DOMContentLoaded', async function () {
2	try {
3		const cookieName = 'hm_lna'; // haymarket legal notifier accepted cookie
4		const filterClass = '-nht-filter';
5		// Check for essential libraries and data first.
6		if ( typeof Cookies === 'undefined' ) {
7			console.error( 'Legal Notifier: The js-cookie library is not loaded. Cannot check or set cookies.' );
8			return;
9		}
10		// if user has the cookie, abort
11		if ( Cookies.get( cookieName ) ) {
12			return;
13		}
14		if ( typeof legalNotifier === 'undefined' || ! legalNotifier.startDate || ! legalNotifier.popupText ) {
15			console.error( 'Legal Notifier: Localized data (legalNotifier) is missing or incomplete.' );
16			return;
17		}
18		// Check if today is within the valid date range before doing anything else.
19		const { cookieDuration, startDate } = legalNotifier;
20		const cookieDurationInt = parseInt( cookieDuration, 10 );
21		const today = new Date();
22		const startDateObj = new Date(startDate + 'T00:00:00');
23		const endDateObj = new Date( startDateObj );
24		endDateObj.setDate( endDateObj.getDate() + cookieDurationInt );
25		// Normalize dates to remove the time component for an accurate comparison.
26		today.setHours( 0, 0, 0, 0 );
27		startDateObj.setHours( 0, 0, 0, 0 );
28		endDateObj.setHours( 0, 0, 0, 0 );
29		// If not within the date range, abort.
30		if ( today < startDateObj || today > endDateObj ) {
31			return;
32		}
33		// exit if NHT by checking for body class
34		if ( document.body.classList.contains( filterClass ) ) {
35			return;
36		}
37		// exit if NHT by checking headers
38		// to improve performance, add defer when loading this script
39		try {
40			const response = await fetch( window.location.href, { method: 'HEAD' } );
41			if ( response.headers.get( 'X-WPENGINE-SEGMENT' ) === 'NHT' ) {
42				return;
43			}
44		} catch ( error ) {
45			console.error( 'Legal Notifier: Could not perform HEAD request to check for headers. Showing popup.', error );
46			// Do not abort if the header check fails. Continue to show the popup.
47		}
48		// Find and validate the modal template.
49		const template = document.getElementById( 'legal-notifier-modal-tpl' );
50		if ( ! template || ! template.content ) {
51			console.error( 'Legal Notifier: The modal template (#legal-notifier-modal-tpl) is not found on the page.' );
52			return;
53		}
54		const modalClone = template.content.cloneNode( true );
55		// Get references to essential elements within the template.
56		const contentDiv = modalClone.querySelector( '.legal-notifier-content' );
57		if ( ! contentDiv ) {
58			console.error( 'Legal Notifier: Incomplete template.' );
59			return;
60		}
61		// Populate the dynamic content.
62		contentDiv.innerHTML = legalNotifier.popupText;
63		document.body.appendChild( modalClone );
64		// Get the real DOM popover element
65		const LegalPopoverEl = document.getElementById( 'legal-notifier-popup' );
66		const acceptButtonEl = document.getElementById( 'legal-notifier-accept' );
67		
68		if ( ! LegalPopoverEl || ! acceptButtonEl ) {
69			console.error( 'Legal Notifier: Required modal elements missing.' );
70			return;
71		}
72		// Add the event listener for the "Accept" button.
73		acceptButtonEl.addEventListener( 'click', function () {
74			Cookies.set( cookieName, 'true', { expires: cookieDurationInt } );
75
76			LegalPopoverEl.dataset.accepted = 'true';
77
78			LegalPopoverEl.hidePopover(); // close popover
79			LegalPopoverEl.remove(); // remove popup from DOM
80		
81			document.body.classList.remove( 'legal-notifier-modal-open' );
82		} );
83		// Close any open Haymarket popovers first.
84		const popovers = document.querySelectorAll('.hm-popover');
85		popovers.forEach((popover) => {
86			if (
87				popover !== LegalPopoverEl &&
88				popover.matches(':popover-open')
89			) {
90				popover.hidePopover();
91			}
92		});
93		// Finally, display the modal and disable background scrolling.
94		LegalPopoverEl.showPopover();
95		document.body.classList.add( 'legal-notifier-modal-open' );
96	} catch ( error ) {
97		// This will catch any unexpected errors and log them to the console.
98		console.error( 'An unexpected error occurred in the Legal Notifier script:', error );
99	}
100} );

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.