swap out old duplicated code for new shared code

This commit is contained in:
Sam Thomson 2019-01-15 10:05:51 +07:00
parent 0d91513c89
commit eaec08f795
1 changed files with 3 additions and 53 deletions

View File

@ -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
}
}