From eaec08f7955f83c93625f9390df7b03e384bb89d Mon Sep 17 00:00:00 2001 From: Sam Thomson Date: Tue, 15 Jan 2019 10:05:51 +0700 Subject: [PATCH] swap out old duplicated code for new shared code --- themes/navy/source/js/main.js | 56 ++--------------------------------- 1 file changed, 3 insertions(+), 53 deletions(-) diff --git a/themes/navy/source/js/main.js b/themes/navy/source/js/main.js index c64457c..6639667 100644 --- a/themes/navy/source/js/main.js +++ b/themes/navy/source/js/main.js @@ -63,43 +63,8 @@ $(document).ready(function () { /* Popups */ -let community = document.querySelectorAll(".item--dropdown-community")[0] -let projects = document.querySelectorAll(".item--dropdown-projects")[0] - -let popups = document.querySelectorAll(".popup-wrap") -let overlays = document.querySelectorAll(".popup-overlay") -let closeButtons = document.querySelectorAll(".popup__button--close") - -let activePopup = null; -let activeOverlay = null; - -community.addEventListener('click', function(event){ - showPopup(popups[0]) - event.preventDefault() -}) - -projects.addEventListener('click', function(event){ - showPopup(popups[1]) - event.preventDefault() -}) - -closeButtons.forEach((button) => { - button.addEventListener('click', closeActivePopup) -}) - -overlays.forEach((overlay) => { - overlay.addEventListener('click', closeActivePopup) -}) - -function showPopup(whichPopup) { - activePopup = whichPopup - addClassToElement(whichPopup, "popup--shown"); -} - -function closeActivePopup() { - removeClassFromElement(activePopup, "popup--shown"); - activePopup = null; -} +var addClassToElement = require('./shared-js/js/utils').addClassToElement; +var removeClassFromElement = require('./shared-js/js/utils').removeClassFromElement; /* Code highlighting */ @@ -153,19 +118,4 @@ function showNav() { function closeNav() { removeClassFromElement(nav, "mobile-nav--shown"); -} - -/*--- Utils ---*/ -function addClassToElement(element, className) { - (element.classList) ? element.classList.add(className) : element.className += ' ' + className - return element -} - -function removeClassFromElement(element, className) { - if(element.classList) { - element.classList.remove(className) - } else { - element.className = element.className.replace(new RegExp('(^|\\b)' + className.split(' ').join('|') + '(\\b|$)', 'gi'), ' ') - } - return element -} +} \ No newline at end of file