Skip to content

Instantly share code, notes, and snippets.

@charliewilco
Created August 8, 2018 20:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save charliewilco/b5384bd7f4fc038ddece22983ceded5d to your computer and use it in GitHub Desktop.
Save charliewilco/b5384bd7f4fc038ddece22983ceded5d to your computer and use it in GitHub Desktop.
Some old modal thing i had sitting on my desktop
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