Does anyone see anything wrong with the following code? This is in an extend.php
file. It is successfully being added. I can view my page source and the JavaScript it in fact in the footer area. There are no log errors and no console errors or warnings. But, it is not doing anything. This code is supposed to open a modal when someone clicks a link in a post. And, the code does work outside of Flarum, like at codepen.
$document->foot[] = <<<HTML
<script>
flarum.core.compat.extend.extend(flarum.core.compat['components/CommentPost'].prototype, 'config', function(output, isInitialized, context) {
if (context.customExtLastContentHtml !== context.contentHtml) {
(function () {
var links =
document.querySelectorAll('.Post-body a'),
warning = document.createElement('div'),
warningText = "Test",
popup,
url;
links.forEach(function (elem) {
elem.addEventListener('click', function (e) {
e.preventDefault();
url = this.getAttribute('href');
popup = `
<div class="warning-wrapper__inner">
<p>${warningText}</p>
<a href="javascript:;" onclick="hideModal(this)">Never mind</a>
</div>`;
warning.classList.add('warning-wrapper');
warning.innerHTML = popup;
document.body.prepend(warning);
});
});
})();
const hideModal = function (e) {
var modal = e.parentElement.parentElement;
modal.style.opacity = 0;
setTimeout(function () {
modal.remove();
modal.removeAttribute('style');
}, 500);
};
}
context.customExtLastContentHtml = context.contentHtml;
});
</script>
HTML;