From e0f570083e46f2cba9ae12666d2173e3c5021193 Mon Sep 17 00:00:00 2001 From: Felix Hamann Date: Sat, 31 Mar 2018 02:11:29 +0200 Subject: [PATCH] fixed typo and added documentation --- templates/standalone/modal.julius | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/templates/standalone/modal.julius b/templates/standalone/modal.julius index e5ae95c3d..be6d1c038 100644 --- a/templates/standalone/modal.julius +++ b/templates/standalone/modal.julius @@ -47,11 +47,17 @@ }; function setup() { + // every modal can be openend via document-wide event, see openOnEvent document.addEventListener('modal-open', openOnEvent, false); + // if modal has trigger assigned to it open modal on click if (trigger) { trigger.classList.add('modal__trigger'); trigger.addEventListener('click', open, false); } + // if there is no content specified for the modal we assume that + // the content is supposed to be the page the trigger links to. + // so we check if the trigger has a href-attribute, fetch that page + // and replace the modal content with the response var replaceMe = modal.querySelector('.replace-me'); var replaceWith = trigger ? trigger.getAttribute('href') : ''; if (replaceMe) { @@ -68,17 +74,18 @@ replaceMe.innerText = ''; replaceMe.insertBefore(main, null); } else { - replaceMe.innerhTML = body; + replaceMe.innerHTML = body; } }); - } } + // tell further modals, that this one already got initialized modal.classList.add('js-modal-initialized'); } setup(); }; + // make sure document doesn't scroll when modal is active function toggleScroll(scrollable) { document.body.classList.toggle('no-scroll', !scrollable); }