From 626e52c243ee1e82988d4650cbb22d3d8c304ed6 Mon Sep 17 00:00:00 2001 From: Johann-S Date: Thu, 18 Dec 2014 10:24:37 +0200 Subject: [PATCH] Create modalOpen and modalClose events. --- js/modals.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/js/modals.js b/js/modals.js index ffecbad..21bc112 100644 --- a/js/modals.js +++ b/js/modals.js @@ -9,6 +9,14 @@ !(function () { 'use strict'; + var eventModalOpen = new CustomEvent('modalOpen', { + bubbles: true, + cancelable: true + }); + var eventModalClose = new CustomEvent('modalClose', { + bubbles: true, + cancelable: true + }); var findModals = function (target) { var i; var modals = document.querySelectorAll('a'); @@ -31,11 +39,14 @@ window.addEventListener('touchend', function (event) { var modal = getModal(event); - if (modal) { - if (modal && modal.classList.contains('modal')) { - modal.classList.toggle('active'); + if (modal && modal.classList.contains('modal')) { + var eventToDispatch = eventModalOpen; + if (modal.classList.contains('active')) { + eventToDispatch = eventModalClose; } - event.preventDefault(); // prevents rewriting url (apps can still use hash values in url) + modal.dispatchEvent(eventToDispatch); + modal.classList.toggle('active'); } + event.preventDefault(); // prevents rewriting url (apps can still use hash values in url) }); }());