HEX
Server: Apache
System: Linux www 5.10.0-10-amd64 #1 SMP Debian 5.10.84-1 (2021-12-08) x86_64
User: root (0)
PHP: 8.2.1
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals
Upload Files
File: /mnt/drbd/www/edenhouse/wp-content/plugins/essential-blocks/blocks/notice/src/frontend.js
document.addEventListener("DOMContentLoaded", function(event) {
	let notices = document.querySelectorAll(".eb-notice-wrapper");

	for (let i = 0; i < notices.length; i++) {
		let dismissButton = notices[i].querySelector(".eb-notice-dismiss");

		// Return if there is no dismiss button
		if (!dismissButton) {
			return;
		}

		notices[i].style.position = "relative";
		dismissButton.style.position = "absolute";
		dismissButton.style.right = "0px";
		dismissButton.style.top = "0px";

		// Hide notice if it's already closed
		let noticeId = notices[i].getAttribute("data-id");
		let showAgain = notices[i].getAttribute("data-show-again");
		let alreadyHidden = localStorage.getItem(
			`eb-notice-hidden-${noticeId}`
		);

		showAgain === "true" && showNoticeAgain(noticeId);
		showAgain === "false" &&
			alreadyHidden === "1" &&
			removeNotice(notices[i]);

		// Add click listener
		(function(i) {
			dismissButton.addEventListener("click", function() {
				onButtonClick(notices[i]);
			});
		})(i);
	}
});

function hidePermanently(noticeId) {
	localStorage.setItem(`eb-notice-hidden-${noticeId}`, "1");
}

function showNoticeAgain(noticeId) {
	localStorage.hasOwnProperty(`eb-notice-hidden-${noticeId}`) &&
		localStorage.removeItem(`eb-notice-hidden-${noticeId}`);
}

function removeNotice(notice) {
	notice.remove();
}

// Dismiss button click handler. Hide notice when clicked, hide permanently if
// 'Show After Dismiss' toggle is enabled
function onButtonClick(notice) {
	let noticeId = notice.getAttribute("data-id");
	let showAgain = notice.getAttribute("data-show-again");

	showAgain === "true" && showNoticeAgain(noticeId);
	showAgain === "false" && hidePermanently(noticeId);
	removeNotice(notice);
}