biobulkbende.org/app/assets/js/modules/Modal.js
2020-11-02 13:40:06 +01:00

39 lines
721 B
JavaScript

import $ from 'jquery';
class Modal {
constructor(){
this.openModalButton = $(".open-modal");
this.modal = $(".modal");
this.closeModalButton = $(".modal__close");
this.events();
}
events(){
// clicking the open modal button
this.openModalButton.click(this.openModal.bind(this));
// clicking the x close modal button
this.closeModalButton.click(this.closeModal.bind(this));
// pushes any key
$(document).keyup(this.keyPressHandler.bind(this));
}
openModal() {
this.modal.addClass("modal--is-visible");
return false
}
closeModal() {
this.modal.removeClass("modal--is-visible");
}
keyPressHandler(e) {
if (e.keyCode == 27) {
this.closeModal();
}
}
}
export default Modal;