Created
August 8, 2018 20:47
-
-
Save charliewilco/b5384bd7f4fc038ddece22983ceded5d to your computer and use it in GitHub Desktop.
Some old modal thing i had sitting on my desktop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Modal { | |
constructor () { | |
this.open() | |
this.close() | |
} | |
settings () { | |
return { | |
open: '.modalOpen', | |
close: '.modalClose', | |
closeBtn: '.close' | |
} | |
} | |
open () { | |
const s = this.settings() | |
const modals = document.querySelectorAll(s.open) | |
Array.prototype.forEach.call(modals, el => { | |
el.addEventListener('click', e => { | |
const mId = this.dataset.modalid | |
document.querySelector(s.close + '[data-modalId*="' + mId + '"]').classList.add('show') | |
}) | |
}) | |
} | |
close () { | |
const s = this.settings() | |
const clsBtns = document.querySelectorAll(s.closeBtn) | |
Array.prototype.forEach.call(clsBtns, el => { | |
el.addEventListener('click', e => { | |
this.parentNode.classList.remove('show') | |
}) | |
}) | |
} | |
} | |
export default Modal |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment