Last active
June 21, 2018 08:43
-
-
Save mmintel/6da3ed56129933c064d9631b97dfe666 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import View from './view'; | |
| export default class ModalView extends View { | |
| constructor(controller, options) { | |
| super(controller); | |
| this.node = options.node; | |
| this.overlay = options.overlay; | |
| this.triggers = options.triggers; | |
| this.init(); | |
| } | |
| init() { | |
| super.init(); | |
| this.addEventListeners(); | |
| } | |
| update = (data) => { | |
| if (data.isOpen) { | |
| this.open(); | |
| } else { | |
| this.close(); | |
| } | |
| } | |
| open() { | |
| this.node.classList.add('is-open'); | |
| this.overlay.classList.add('is-open'); | |
| } | |
| close() { | |
| this.node.classList.remove('is-open'); | |
| this.overlay.classList.remove('is-open'); | |
| this.node.classList.add('is-closed'); | |
| this.overlay.classList.add('is-closed'); | |
| } | |
| handleOverlayClick = (e) => { | |
| if (e.target !== e.currentTarget) return; | |
| this.controller.close(); | |
| } | |
| addEventListeners = () => { | |
| this.triggers.open.forEach(node => node.addEventListener('click', this.controller.open)); | |
| this.triggers.close.forEach(node => node.addEventListener('click', this.controller.close)); | |
| document.addEventListener('keydown', this.handleKeypress); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment