New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

pure-modal

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pure-modal - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

4

dist/pure-modal.common.js
/**
* Pure Modal v1.0.2
* Pure Modal v1.0.3
* (c) 2019 Roman Slonov
* Released under the MIT License.
*/
"use strict";function createCommonjsModule(t,i){return t(i={exports:{}},i.exports),i.exports}Object.defineProperty(exports,"__esModule",{value:!0});var modal=createCommonjsModule(function(t){var i="modal-backdrop",s="is-open",e="in",o="out",n="modal-dialog",a=27,r=9,l={transition:!0},c=function(t){return window.console.error("PureModal: "+t)},d=function t(i,s){this.id=i,this.config=Object.assign({},l,s),this.modal=t.findModal(this.id),this.dialog=this.modal.querySelector("."+n),this.backdrop=null,this.isOpen=!1,this.isInit=!1,this.isTransitioning=!1,this.triggers=t.findTriggers(this.id),this.closeEls=null,this.focusableEls=null,this.focusedElBeforeOpen=null,this.firstFocusableEl=null,this.lastFocusableEl=null,this.open=this.open.bind(this),this.close=this.close.bind(this),this.onDismiss=this.onDismiss.bind(this),this.handleKeyDown=this.handleKeyDown.bind(this)};d.prototype.init=function(){var t=this;this.isInit?c("Event listeners already added."):(this.triggers.forEach(function(i){return i.addEventListener("click",t.open)}),this.isInit=!0)},d.prototype.destroy=function(){var t=this;this.isInit?(this.triggers.forEach(function(i){return i.removeEventListener("click",t.open)}),this.isInit=!1):c("Event listeners already removed.")},d.prototype.open=function(t){var i=this;this.isTransitioning||(t.preventDefault(),"function"==typeof this.config.beforeOpen&&this.config.beforeOpen(),this.focusedElBeforeOpen=document.activeElement,this.focusableEls=[].concat(this.dialog.querySelectorAll('a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), [tabindex="0"]')),this.firstFocusableEl=this.focusableEls[0],this.lastFocusableEl=this.focusableEls[this.focusableEls.length-1],this.showBackdrop(),this.modal.style.display="block",this.config.transition?(this.isTransitioning=!0,this.modal.classList.add(s),this.modal.classList.add(e),this.openWithTransition()):this.firstFocusableEl.focus(),document.addEventListener("mousedown",this.onDismiss),document.addEventListener("keydown",this.handleKeyDown),this.closeEls=[].concat(this.modal.querySelectorAll('[data-dismiss="modal"]')),this.closeEls.forEach(function(t){return t.addEventListener("click",i.close)}),this.isOpen=!0,"function"==typeof this.config.onOpen&&this.config.onOpen())},d.prototype.openWithTransition=function(){var t=this,i=function(){t.dialog.removeEventListener("animationend",i),t.firstFocusableEl.focus(),"function"==typeof t.config.onOpen&&t.config.onOpen(),t.isTransitioning=!1};this.dialog.addEventListener("animationend",i)},d.prototype.close=function(){var t=this;this.isTransitioning||("function"==typeof this.config.beforeClose&&this.config.beforeClose(),this.config.transition?(this.isTransitioning=!0,this.modal.classList.remove(e),this.modal.classList.remove(s),this.modal.classList.add(o),this.closeWithTransition(),this.closeBackdrop()):(this.modal.style.display="none",this.modal.classList.remove(s),this.closeBackdrop(),"function"==typeof this.config.onClose&&this.config.onClose()),document.removeEventListener("mousedown",this.onDismiss),document.removeEventListener("keydown",this.handleKeyDown),this.closeEls.forEach(function(i){return i.removeEventListener("click",t.close)}),this.isOpen=!1,this.focusedElBeforeOpen.focus())},d.prototype.closeWithTransition=function(){var t=this,i=function(){t.dialog.removeEventListener("animationend",i),t.modal.style.display="none",t.modal.classList.remove(o),"function"==typeof t.config.onClose&&t.config.onClose(),t.isTransitioning=!1};this.dialog.addEventListener("animationend",i)},d.prototype.onDismiss=function(t){!this.dialog.contains(t.target)&&this.isOpen&&this.close()},d.prototype.showBackdrop=function(){this.backdrop=document.createElement("div"),this.backdrop.tabIndex=-1,this.backdrop.classList.add(i),this.config.transition&&this.backdrop.classList.add(e),document.body.appendChild(this.backdrop),this.backdrop.offsetHeight,this.backdrop.classList.add(s)},d.prototype.closeBackdrop=function(){this.config.transition?(this.backdrop.classList.remove(e),this.backdrop.classList.remove(s),this.backdrop.classList.add(o),this.closeBackdropWithTransition()):this.backdrop.remove()},d.prototype.closeBackdropWithTransition=function(){var t=this,i=function(){t.backdrop.removeEventListener("transitionend",i),t.backdrop.remove()};this.backdrop.addEventListener("transitionend",i)},d.prototype.handleKeyDown=function(t){var i=this;switch(t.keyCode){case r:if(1===this.focusableEls.length){t.preventDefault();break}t.shiftKey?document.activeElement===i.firstFocusableEl&&(t.preventDefault(),i.lastFocusableEl.focus()):document.activeElement===i.lastFocusableEl&&(t.preventDefault(),i.firstFocusableEl.focus());break;case a:this.close()}},d.findTriggers=function(t){return[].concat(document.querySelectorAll('[data-toggle="modal"][data-target="'+t+'"]'))},d.findModal=function(t){return document.getElementById(t)},t.exports=d});exports.default=modal;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var ClassName={BACKDROP:"modal-backdrop",OPEN:"is-open",IN:"in",OUT:"out",DIALOG:"modal-dialog"},KeyCodes={ESC:27,TAB:9},DefaultConfig={transition:!0},throwError=function(s){return window.console.error("PureModal: "+s)},reflow=function(s){return s.offsetHeight},PureModal=function s(t,e){this.id=t,this.config=Object.assign({},DefaultConfig,e),this.modal=s.findModal(this.id),this.dialog=this.modal.querySelector("."+ClassName.DIALOG),this.backdrop=null,this.isOpen=!1,this.isInit=!1,this.isTransitioning=!1,this.triggers=s.findTriggers(this.id),this.closeEls=null,this.focusableEls=null,this.focusedElBeforeOpen=null,this.firstFocusableEl=null,this.lastFocusableEl=null,this.open=this.open.bind(this),this.close=this.close.bind(this),this.onDismiss=this.onDismiss.bind(this),this.handleKeyDown=this.handleKeyDown.bind(this)};PureModal.prototype.init=function(){var s=this;this.isInit?throwError("Event listeners already added."):(this.triggers.forEach(function(t){return t.addEventListener("click",s.open)}),this.isInit=!0)},PureModal.prototype.destroy=function(){var s=this;this.isInit?(this.triggers.forEach(function(t){return t.removeEventListener("click",s.open)}),this.isInit=!1):throwError("Event listeners already removed.")},PureModal.prototype.open=function(s){var t=this;this.isTransitioning||(s.preventDefault(),"function"==typeof this.config.beforeOpen&&this.config.beforeOpen(),this.focusedElBeforeOpen=document.activeElement,this.focusableEls=Array.from(this.dialog.querySelectorAll('a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), [tabindex="0"]')),this.firstFocusableEl=this.focusableEls[0],this.lastFocusableEl=this.focusableEls[this.focusableEls.length-1],this.showBackdrop(),this.modal.style.display="block",this.config.transition?(this.isTransitioning=!0,this.modal.classList.add(ClassName.OPEN),this.modal.classList.add(ClassName.IN),this.openWithTransition()):this.firstFocusableEl.focus(),document.addEventListener("mousedown",this.onDismiss),document.addEventListener("keydown",this.handleKeyDown),this.closeEls=Array.from(this.modal.querySelectorAll('[data-dismiss="modal"]')),this.closeEls.forEach(function(s){return s.addEventListener("click",t.close)}),this.isOpen=!0,"function"==typeof this.config.onOpen&&this.config.onOpen())},PureModal.prototype.openWithTransition=function(){var s=this,t=function(){s.dialog.removeEventListener("animationend",t),s.firstFocusableEl.focus(),"function"==typeof s.config.onOpen&&s.config.onOpen(),s.isTransitioning=!1};this.dialog.addEventListener("animationend",t)},PureModal.prototype.close=function(){var s=this;this.isTransitioning||("function"==typeof this.config.beforeClose&&this.config.beforeClose(),this.config.transition?(this.isTransitioning=!0,this.modal.classList.remove(ClassName.IN),this.modal.classList.remove(ClassName.OPEN),this.modal.classList.add(ClassName.OUT),this.closeWithTransition(),this.closeBackdrop()):(this.modal.style.display="none",this.modal.classList.remove(ClassName.OPEN),this.closeBackdrop(),"function"==typeof this.config.onClose&&this.config.onClose()),document.removeEventListener("mousedown",this.onDismiss),document.removeEventListener("keydown",this.handleKeyDown),this.closeEls.forEach(function(t){return t.removeEventListener("click",s.close)}),this.isOpen=!1,this.focusedElBeforeOpen.focus())},PureModal.prototype.closeWithTransition=function(){var s=this,t=function(){s.dialog.removeEventListener("animationend",t),s.modal.style.display="none",s.modal.classList.remove(ClassName.OUT),"function"==typeof s.config.onClose&&s.config.onClose(),s.isTransitioning=!1};this.dialog.addEventListener("animationend",t)},PureModal.prototype.onDismiss=function(s){!this.dialog.contains(s.target)&&this.isOpen&&this.close()},PureModal.prototype.showBackdrop=function(){this.backdrop=document.createElement("div"),this.backdrop.tabIndex=-1,this.backdrop.classList.add(ClassName.BACKDROP),this.config.transition&&this.backdrop.classList.add(ClassName.IN),document.body.appendChild(this.backdrop),reflow(this.backdrop),this.backdrop.classList.add(ClassName.OPEN)},PureModal.prototype.closeBackdrop=function(){this.config.transition?(this.backdrop.classList.remove(ClassName.IN),this.backdrop.classList.remove(ClassName.OPEN),this.backdrop.classList.add(ClassName.OUT),this.closeBackdropWithTransition()):this.backdrop.remove()},PureModal.prototype.closeBackdropWithTransition=function(){var s=this,t=function(){s.backdrop.removeEventListener("transitionend",t),s.backdrop.remove()};this.backdrop.addEventListener("transitionend",t)},PureModal.prototype.handleKeyDown=function(s){var t=this;switch(s.keyCode){case KeyCodes.TAB:if(1===this.focusableEls.length){s.preventDefault();break}s.shiftKey?document.activeElement===t.firstFocusableEl&&(s.preventDefault(),t.lastFocusableEl.focus()):document.activeElement===t.lastFocusableEl&&(s.preventDefault(),t.firstFocusableEl.focus());break;case KeyCodes.ESC:this.close()}},PureModal.findTriggers=function(s){return Array.from(document.querySelectorAll('[data-toggle="modal"][data-target="'+s+'"]'))},PureModal.findModal=function(s){return document.getElementById(s)},exports.default=PureModal;
/**
* Pure Modal v1.0.2
* Pure Modal v1.0.3
* (c) 2019 Roman Slonov
* Released under the MIT License.
*/
var t;export default(function(t){var i="modal-backdrop",s="is-open",e="in",o="out",n="modal-dialog",a=27,l=9,r={transition:!0},c=function(t){return window.console.error("PureModal: "+t)},d=function t(i,s){this.id=i,this.config=Object.assign({},r,s),this.modal=t.findModal(this.id),this.dialog=this.modal.querySelector("."+n),this.backdrop=null,this.isOpen=!1,this.isInit=!1,this.isTransitioning=!1,this.triggers=t.findTriggers(this.id),this.closeEls=null,this.focusableEls=null,this.focusedElBeforeOpen=null,this.firstFocusableEl=null,this.lastFocusableEl=null,this.open=this.open.bind(this),this.close=this.close.bind(this),this.onDismiss=this.onDismiss.bind(this),this.handleKeyDown=this.handleKeyDown.bind(this)};d.prototype.init=function(){var t=this;this.isInit?c("Event listeners already added."):(this.triggers.forEach(function(i){return i.addEventListener("click",t.open)}),this.isInit=!0)},d.prototype.destroy=function(){var t=this;this.isInit?(this.triggers.forEach(function(i){return i.removeEventListener("click",t.open)}),this.isInit=!1):c("Event listeners already removed.")},d.prototype.open=function(t){var i=this;this.isTransitioning||(t.preventDefault(),"function"==typeof this.config.beforeOpen&&this.config.beforeOpen(),this.focusedElBeforeOpen=document.activeElement,this.focusableEls=[].concat(this.dialog.querySelectorAll('a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), [tabindex="0"]')),this.firstFocusableEl=this.focusableEls[0],this.lastFocusableEl=this.focusableEls[this.focusableEls.length-1],this.showBackdrop(),this.modal.style.display="block",this.config.transition?(this.isTransitioning=!0,this.modal.classList.add(s),this.modal.classList.add(e),this.openWithTransition()):this.firstFocusableEl.focus(),document.addEventListener("mousedown",this.onDismiss),document.addEventListener("keydown",this.handleKeyDown),this.closeEls=[].concat(this.modal.querySelectorAll('[data-dismiss="modal"]')),this.closeEls.forEach(function(t){return t.addEventListener("click",i.close)}),this.isOpen=!0,"function"==typeof this.config.onOpen&&this.config.onOpen())},d.prototype.openWithTransition=function(){var t=this,i=function(){t.dialog.removeEventListener("animationend",i),t.firstFocusableEl.focus(),"function"==typeof t.config.onOpen&&t.config.onOpen(),t.isTransitioning=!1};this.dialog.addEventListener("animationend",i)},d.prototype.close=function(){var t=this;this.isTransitioning||("function"==typeof this.config.beforeClose&&this.config.beforeClose(),this.config.transition?(this.isTransitioning=!0,this.modal.classList.remove(e),this.modal.classList.remove(s),this.modal.classList.add(o),this.closeWithTransition(),this.closeBackdrop()):(this.modal.style.display="none",this.modal.classList.remove(s),this.closeBackdrop(),"function"==typeof this.config.onClose&&this.config.onClose()),document.removeEventListener("mousedown",this.onDismiss),document.removeEventListener("keydown",this.handleKeyDown),this.closeEls.forEach(function(i){return i.removeEventListener("click",t.close)}),this.isOpen=!1,this.focusedElBeforeOpen.focus())},d.prototype.closeWithTransition=function(){var t=this,i=function(){t.dialog.removeEventListener("animationend",i),t.modal.style.display="none",t.modal.classList.remove(o),"function"==typeof t.config.onClose&&t.config.onClose(),t.isTransitioning=!1};this.dialog.addEventListener("animationend",i)},d.prototype.onDismiss=function(t){!this.dialog.contains(t.target)&&this.isOpen&&this.close()},d.prototype.showBackdrop=function(){this.backdrop=document.createElement("div"),this.backdrop.tabIndex=-1,this.backdrop.classList.add(i),this.config.transition&&this.backdrop.classList.add(e),document.body.appendChild(this.backdrop),this.backdrop.offsetHeight,this.backdrop.classList.add(s)},d.prototype.closeBackdrop=function(){this.config.transition?(this.backdrop.classList.remove(e),this.backdrop.classList.remove(s),this.backdrop.classList.add(o),this.closeBackdropWithTransition()):this.backdrop.remove()},d.prototype.closeBackdropWithTransition=function(){var t=this,i=function(){t.backdrop.removeEventListener("transitionend",i),t.backdrop.remove()};this.backdrop.addEventListener("transitionend",i)},d.prototype.handleKeyDown=function(t){var i=this;switch(t.keyCode){case l:if(1===this.focusableEls.length){t.preventDefault();break}t.shiftKey?document.activeElement===i.firstFocusableEl&&(t.preventDefault(),i.lastFocusableEl.focus()):document.activeElement===i.lastFocusableEl&&(t.preventDefault(),i.firstFocusableEl.focus());break;case a:this.close()}},d.findTriggers=function(t){return[].concat(document.querySelectorAll('[data-toggle="modal"][data-target="'+t+'"]'))},d.findModal=function(t){return document.getElementById(t)},t.exports=d}(t={exports:{}},t.exports),t.exports);
var t="modal-backdrop",i="is-open",s="in",e="out",o="modal-dialog",n=27,a=9,r={transition:!0},l=function(t){return window.console.error("PureModal: "+t)},c=function t(i,s){this.id=i,this.config=Object.assign({},r,s),this.modal=t.findModal(this.id),this.dialog=this.modal.querySelector("."+o),this.backdrop=null,this.isOpen=!1,this.isInit=!1,this.isTransitioning=!1,this.triggers=t.findTriggers(this.id),this.closeEls=null,this.focusableEls=null,this.focusedElBeforeOpen=null,this.firstFocusableEl=null,this.lastFocusableEl=null,this.open=this.open.bind(this),this.close=this.close.bind(this),this.onDismiss=this.onDismiss.bind(this),this.handleKeyDown=this.handleKeyDown.bind(this)};c.prototype.init=function(){var t=this;this.isInit?l("Event listeners already added."):(this.triggers.forEach(function(i){return i.addEventListener("click",t.open)}),this.isInit=!0)},c.prototype.destroy=function(){var t=this;this.isInit?(this.triggers.forEach(function(i){return i.removeEventListener("click",t.open)}),this.isInit=!1):l("Event listeners already removed.")},c.prototype.open=function(t){var e=this;this.isTransitioning||(t.preventDefault(),"function"==typeof this.config.beforeOpen&&this.config.beforeOpen(),this.focusedElBeforeOpen=document.activeElement,this.focusableEls=Array.from(this.dialog.querySelectorAll('a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), [tabindex="0"]')),this.firstFocusableEl=this.focusableEls[0],this.lastFocusableEl=this.focusableEls[this.focusableEls.length-1],this.showBackdrop(),this.modal.style.display="block",this.config.transition?(this.isTransitioning=!0,this.modal.classList.add(i),this.modal.classList.add(s),this.openWithTransition()):this.firstFocusableEl.focus(),document.addEventListener("mousedown",this.onDismiss),document.addEventListener("keydown",this.handleKeyDown),this.closeEls=Array.from(this.modal.querySelectorAll('[data-dismiss="modal"]')),this.closeEls.forEach(function(t){return t.addEventListener("click",e.close)}),this.isOpen=!0,"function"==typeof this.config.onOpen&&this.config.onOpen())},c.prototype.openWithTransition=function(){var t=this,i=function(){t.dialog.removeEventListener("animationend",i),t.firstFocusableEl.focus(),"function"==typeof t.config.onOpen&&t.config.onOpen(),t.isTransitioning=!1};this.dialog.addEventListener("animationend",i)},c.prototype.close=function(){var t=this;this.isTransitioning||("function"==typeof this.config.beforeClose&&this.config.beforeClose(),this.config.transition?(this.isTransitioning=!0,this.modal.classList.remove(s),this.modal.classList.remove(i),this.modal.classList.add(e),this.closeWithTransition(),this.closeBackdrop()):(this.modal.style.display="none",this.modal.classList.remove(i),this.closeBackdrop(),"function"==typeof this.config.onClose&&this.config.onClose()),document.removeEventListener("mousedown",this.onDismiss),document.removeEventListener("keydown",this.handleKeyDown),this.closeEls.forEach(function(i){return i.removeEventListener("click",t.close)}),this.isOpen=!1,this.focusedElBeforeOpen.focus())},c.prototype.closeWithTransition=function(){var t=this,i=function(){t.dialog.removeEventListener("animationend",i),t.modal.style.display="none",t.modal.classList.remove(e),"function"==typeof t.config.onClose&&t.config.onClose(),t.isTransitioning=!1};this.dialog.addEventListener("animationend",i)},c.prototype.onDismiss=function(t){!this.dialog.contains(t.target)&&this.isOpen&&this.close()},c.prototype.showBackdrop=function(){this.backdrop=document.createElement("div"),this.backdrop.tabIndex=-1,this.backdrop.classList.add(t),this.config.transition&&this.backdrop.classList.add(s),document.body.appendChild(this.backdrop),this.backdrop.offsetHeight,this.backdrop.classList.add(i)},c.prototype.closeBackdrop=function(){this.config.transition?(this.backdrop.classList.remove(s),this.backdrop.classList.remove(i),this.backdrop.classList.add(e),this.closeBackdropWithTransition()):this.backdrop.remove()},c.prototype.closeBackdropWithTransition=function(){var t=this,i=function(){t.backdrop.removeEventListener("transitionend",i),t.backdrop.remove()};this.backdrop.addEventListener("transitionend",i)},c.prototype.handleKeyDown=function(t){var i=this;switch(t.keyCode){case a:if(1===this.focusableEls.length){t.preventDefault();break}t.shiftKey?document.activeElement===i.firstFocusableEl&&(t.preventDefault(),i.lastFocusableEl.focus()):document.activeElement===i.lastFocusableEl&&(t.preventDefault(),i.firstFocusableEl.focus());break;case n:this.close()}},c.findTriggers=function(t){return Array.from(document.querySelectorAll('[data-toggle="modal"][data-target="'+t+'"]'))},c.findModal=function(t){return document.getElementById(t)};export default c;
/**
* Pure Modal v1.0.2
* Pure Modal v1.0.3
* (c) 2019 Roman Slonov
* Released under the MIT License.
*/
!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?i(exports):"function"==typeof define&&define.amd?define(["exports"],i):i((t=t||self).PureModal={})}(this,function(t){"use strict";var i,s=(function(t){var i="modal-backdrop",s="is-open",e="in",o="out",n="modal-dialog",a=27,r=9,c={transition:!0},l=function(t){return window.console.error("PureModal: "+t)},d=function t(i,s){this.id=i,this.config=Object.assign({},c,s),this.modal=t.findModal(this.id),this.dialog=this.modal.querySelector("."+n),this.backdrop=null,this.isOpen=!1,this.isInit=!1,this.isTransitioning=!1,this.triggers=t.findTriggers(this.id),this.closeEls=null,this.focusableEls=null,this.focusedElBeforeOpen=null,this.firstFocusableEl=null,this.lastFocusableEl=null,this.open=this.open.bind(this),this.close=this.close.bind(this),this.onDismiss=this.onDismiss.bind(this),this.handleKeyDown=this.handleKeyDown.bind(this)};d.prototype.init=function(){var t=this;this.isInit?l("Event listeners already added."):(this.triggers.forEach(function(i){return i.addEventListener("click",t.open)}),this.isInit=!0)},d.prototype.destroy=function(){var t=this;this.isInit?(this.triggers.forEach(function(i){return i.removeEventListener("click",t.open)}),this.isInit=!1):l("Event listeners already removed.")},d.prototype.open=function(t){var i=this;this.isTransitioning||(t.preventDefault(),"function"==typeof this.config.beforeOpen&&this.config.beforeOpen(),this.focusedElBeforeOpen=document.activeElement,this.focusableEls=[].concat(this.dialog.querySelectorAll('a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), [tabindex="0"]')),this.firstFocusableEl=this.focusableEls[0],this.lastFocusableEl=this.focusableEls[this.focusableEls.length-1],this.showBackdrop(),this.modal.style.display="block",this.config.transition?(this.isTransitioning=!0,this.modal.classList.add(s),this.modal.classList.add(e),this.openWithTransition()):this.firstFocusableEl.focus(),document.addEventListener("mousedown",this.onDismiss),document.addEventListener("keydown",this.handleKeyDown),this.closeEls=[].concat(this.modal.querySelectorAll('[data-dismiss="modal"]')),this.closeEls.forEach(function(t){return t.addEventListener("click",i.close)}),this.isOpen=!0,"function"==typeof this.config.onOpen&&this.config.onOpen())},d.prototype.openWithTransition=function(){var t=this,i=function(){t.dialog.removeEventListener("animationend",i),t.firstFocusableEl.focus(),"function"==typeof t.config.onOpen&&t.config.onOpen(),t.isTransitioning=!1};this.dialog.addEventListener("animationend",i)},d.prototype.close=function(){var t=this;this.isTransitioning||("function"==typeof this.config.beforeClose&&this.config.beforeClose(),this.config.transition?(this.isTransitioning=!0,this.modal.classList.remove(e),this.modal.classList.remove(s),this.modal.classList.add(o),this.closeWithTransition(),this.closeBackdrop()):(this.modal.style.display="none",this.modal.classList.remove(s),this.closeBackdrop(),"function"==typeof this.config.onClose&&this.config.onClose()),document.removeEventListener("mousedown",this.onDismiss),document.removeEventListener("keydown",this.handleKeyDown),this.closeEls.forEach(function(i){return i.removeEventListener("click",t.close)}),this.isOpen=!1,this.focusedElBeforeOpen.focus())},d.prototype.closeWithTransition=function(){var t=this,i=function(){t.dialog.removeEventListener("animationend",i),t.modal.style.display="none",t.modal.classList.remove(o),"function"==typeof t.config.onClose&&t.config.onClose(),t.isTransitioning=!1};this.dialog.addEventListener("animationend",i)},d.prototype.onDismiss=function(t){!this.dialog.contains(t.target)&&this.isOpen&&this.close()},d.prototype.showBackdrop=function(){this.backdrop=document.createElement("div"),this.backdrop.tabIndex=-1,this.backdrop.classList.add(i),this.config.transition&&this.backdrop.classList.add(e),document.body.appendChild(this.backdrop),this.backdrop.offsetHeight,this.backdrop.classList.add(s)},d.prototype.closeBackdrop=function(){this.config.transition?(this.backdrop.classList.remove(e),this.backdrop.classList.remove(s),this.backdrop.classList.add(o),this.closeBackdropWithTransition()):this.backdrop.remove()},d.prototype.closeBackdropWithTransition=function(){var t=this,i=function(){t.backdrop.removeEventListener("transitionend",i),t.backdrop.remove()};this.backdrop.addEventListener("transitionend",i)},d.prototype.handleKeyDown=function(t){var i=this;switch(t.keyCode){case r:if(1===this.focusableEls.length){t.preventDefault();break}t.shiftKey?document.activeElement===i.firstFocusableEl&&(t.preventDefault(),i.lastFocusableEl.focus()):document.activeElement===i.lastFocusableEl&&(t.preventDefault(),i.firstFocusableEl.focus());break;case a:this.close()}},d.findTriggers=function(t){return[].concat(document.querySelectorAll('[data-toggle="modal"][data-target="'+t+'"]'))},d.findModal=function(t){return document.getElementById(t)},t.exports=d}(i={exports:{}},i.exports),i.exports);t.default=s,Object.defineProperty(t,"__esModule",{value:!0})});
var PureModal=function(){"use strict";var t="modal-backdrop",i="is-open",s="in",e="out",o="modal-dialog",n=27,a=9,r={transition:!0},l=function(t){return window.console.error("PureModal: "+t)},c=function t(i,s){this.id=i,this.config=Object.assign({},r,s),this.modal=t.findModal(this.id),this.dialog=this.modal.querySelector("."+o),this.backdrop=null,this.isOpen=!1,this.isInit=!1,this.isTransitioning=!1,this.triggers=t.findTriggers(this.id),this.closeEls=null,this.focusableEls=null,this.focusedElBeforeOpen=null,this.firstFocusableEl=null,this.lastFocusableEl=null,this.open=this.open.bind(this),this.close=this.close.bind(this),this.onDismiss=this.onDismiss.bind(this),this.handleKeyDown=this.handleKeyDown.bind(this)};return c.prototype.init=function(){var t=this;this.isInit?l("Event listeners already added."):(this.triggers.forEach(function(i){return i.addEventListener("click",t.open)}),this.isInit=!0)},c.prototype.destroy=function(){var t=this;this.isInit?(this.triggers.forEach(function(i){return i.removeEventListener("click",t.open)}),this.isInit=!1):l("Event listeners already removed.")},c.prototype.open=function(t){var e=this;this.isTransitioning||(t.preventDefault(),"function"==typeof this.config.beforeOpen&&this.config.beforeOpen(),this.focusedElBeforeOpen=document.activeElement,this.focusableEls=Array.from(this.dialog.querySelectorAll('a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), [tabindex="0"]')),this.firstFocusableEl=this.focusableEls[0],this.lastFocusableEl=this.focusableEls[this.focusableEls.length-1],this.showBackdrop(),this.modal.style.display="block",this.config.transition?(this.isTransitioning=!0,this.modal.classList.add(i),this.modal.classList.add(s),this.openWithTransition()):this.firstFocusableEl.focus(),document.addEventListener("mousedown",this.onDismiss),document.addEventListener("keydown",this.handleKeyDown),this.closeEls=Array.from(this.modal.querySelectorAll('[data-dismiss="modal"]')),this.closeEls.forEach(function(t){return t.addEventListener("click",e.close)}),this.isOpen=!0,"function"==typeof this.config.onOpen&&this.config.onOpen())},c.prototype.openWithTransition=function(){var t=this,i=function(){t.dialog.removeEventListener("animationend",i),t.firstFocusableEl.focus(),"function"==typeof t.config.onOpen&&t.config.onOpen(),t.isTransitioning=!1};this.dialog.addEventListener("animationend",i)},c.prototype.close=function(){var t=this;this.isTransitioning||("function"==typeof this.config.beforeClose&&this.config.beforeClose(),this.config.transition?(this.isTransitioning=!0,this.modal.classList.remove(s),this.modal.classList.remove(i),this.modal.classList.add(e),this.closeWithTransition(),this.closeBackdrop()):(this.modal.style.display="none",this.modal.classList.remove(i),this.closeBackdrop(),"function"==typeof this.config.onClose&&this.config.onClose()),document.removeEventListener("mousedown",this.onDismiss),document.removeEventListener("keydown",this.handleKeyDown),this.closeEls.forEach(function(i){return i.removeEventListener("click",t.close)}),this.isOpen=!1,this.focusedElBeforeOpen.focus())},c.prototype.closeWithTransition=function(){var t=this,i=function(){t.dialog.removeEventListener("animationend",i),t.modal.style.display="none",t.modal.classList.remove(e),"function"==typeof t.config.onClose&&t.config.onClose(),t.isTransitioning=!1};this.dialog.addEventListener("animationend",i)},c.prototype.onDismiss=function(t){!this.dialog.contains(t.target)&&this.isOpen&&this.close()},c.prototype.showBackdrop=function(){this.backdrop=document.createElement("div"),this.backdrop.tabIndex=-1,this.backdrop.classList.add(t),this.config.transition&&this.backdrop.classList.add(s),document.body.appendChild(this.backdrop),this.backdrop.offsetHeight,this.backdrop.classList.add(i)},c.prototype.closeBackdrop=function(){this.config.transition?(this.backdrop.classList.remove(s),this.backdrop.classList.remove(i),this.backdrop.classList.add(e),this.closeBackdropWithTransition()):this.backdrop.remove()},c.prototype.closeBackdropWithTransition=function(){var t=this,i=function(){t.backdrop.removeEventListener("transitionend",i),t.backdrop.remove()};this.backdrop.addEventListener("transitionend",i)},c.prototype.handleKeyDown=function(t){var i=this;switch(t.keyCode){case a:if(1===this.focusableEls.length){t.preventDefault();break}t.shiftKey?document.activeElement===i.firstFocusableEl&&(t.preventDefault(),i.lastFocusableEl.focus()):document.activeElement===i.lastFocusableEl&&(t.preventDefault(),i.firstFocusableEl.focus());break;case n:this.close()}},c.findTriggers=function(t){return Array.from(document.querySelectorAll('[data-toggle="modal"][data-target="'+t+'"]'))},c.findModal=function(t){return document.getElementById(t)},c}();

@@ -55,3 +55,3 @@ const ClassName = {

this.triggers.forEach(trigger => trigger.addEventListener('click', this.open));
this.triggers.forEach(trigger => trigger.addEventListener('click', this.open));

@@ -67,3 +67,3 @@ this.isInit = true;

this.triggers.forEach(trigger => trigger.removeEventListener('click', this.open));
this.triggers.forEach(trigger => trigger.removeEventListener('click', this.open));

@@ -84,3 +84,5 @@ this.isInit = false;

this.focusedElBeforeOpen = document.activeElement;
this.focusableEls = [...this.dialog.querySelectorAll('a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), [tabindex="0"]')];
this.focusableEls = Array.from(
this.dialog.querySelectorAll('a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), [tabindex="0"]')
);
this.firstFocusableEl = this.focusableEls[0];

@@ -107,3 +109,5 @@ this.lastFocusableEl = this.focusableEls[this.focusableEls.length - 1];

this.closeEls = [...this.modal.querySelectorAll('[data-dismiss="modal"]')];
this.closeEls = Array.from(
this.modal.querySelectorAll('[data-dismiss="modal"]')
);
this.closeEls.forEach(button => button.addEventListener('click', this.close));

@@ -265,3 +269,5 @@

static findTriggers(id) {
return [...document.querySelectorAll(`[data-toggle="modal"][data-target="${id}"]`)];
return Array.from(
document.querySelectorAll(`[data-toggle="modal"][data-target="${id}"]`)
);
}

@@ -274,6 +280,2 @@

if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
module.exports = PureModal;
} else {
window.PureModal = PureModal;
}
export default PureModal;
{
"name": "pure-modal",
"version": "1.0.2",
"version": "1.0.3",
"description": "A lightweight, accessible, vanilla JavaScript modal component",

@@ -5,0 +5,0 @@ "main": "dist/pure-modal.common.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc