1 |
2
|
Manuela
|
!function(t){"undefined"!=typeof module&&"object"==typeof exports?"undefined"!=typeof window?module.exports=t():module.exports=t:window.Modal=t()}(function(){var t=function(t,e){e=e||{},this.isIE=null!=new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})").exec(navigator.userAgent)?parseFloat(RegExp.$1):!1,this.modal="object"==typeof t?t:document.querySelector(t),this.options={},this.options.backdrop="false"===e.backdrop?!1:!0,this.options.keyboard="false"===e.keyboard?!1:!0,this.options.content=e.content,this.duration=e.duration||300,this.options.duration=this.isIE&&this.isIE<10?0:this.duration,this.scrollbarWidth=0,this.dialog=this.modal.querySelector(".modal-dialog"),this.timer=0,this.init()},e=function(){var t=document.documentElement.getBoundingClientRect(),e=window.innerWidth||t.right-Math.abs(t.left);return e};t.prototype={init:function(){this.actions(),this.trigger(),this.options.content&&void 0!==this.options.content&&this.content(this.options.content)},actions:function(){var t=this;this.open=function(){this._open()},this.close=function(){this._close()},this._open=function(){var e=document.querySelector(".modal.in");e&&(clearTimeout(e.getAttribute("data-timer")),this.removeClass(e,"in"),setTimeout(function(){e.setAttribute("aria-hidden",!0),e.style.display=""},t.options.duration/2)),this.options.backdrop?this.createOverlay():this.overlay=null,this.overlay&&setTimeout(function(){t.addClass(t.overlay,"in")},0),clearTimeout(t.modal.getAttribute("data-timer")),this.timer=setTimeout(function(){t.modal.style.display="block",t.checkScrollbar(),t.adjustDialog(),t.setScrollbar(),t.resize(),t.dismiss(),t.keydown(),t.addClass(document.body,"modal-open"),t.addClass(t.modal,"in"),t.modal.setAttribute("aria-hidden",!1)},t.options.duration/2),this.modal.setAttribute("data-timer",t.timer)},this._close=function(){this.overlay&&this.removeClass(this.overlay,"in"),this.removeClass(this.modal,"in"),this.modal.setAttribute("aria-hidden",!0),clearTimeout(t.modal.getAttribute("data-timer")),this.timer=setTimeout(function(){t.removeClass(document.body,"modal-open"),t.resize(),t.resetAdjustments(),t.resetScrollbar(),t.dismiss(),t.keydown(),t.modal.style.display=""},t.options.duration/2),this.modal.setAttribute("data-timer",t.timer),setTimeout(function(){document.querySelector(".modal.in")||t.removeOverlay()},t.options.duration)},this.content=function(t){return this.modal.querySelector(".modal-content").innerHTML=t},this.createOverlay=function(){var t=document.createElement("div"),e=document.querySelector(".modal-backdrop");t.setAttribute("class","modal-backdrop fade"),e?this.overlay=e:(this.overlay=t,document.body.appendChild(t))},this.removeOverlay=function(){var t=document.querySelector(".modal-backdrop");null!==t&&void 0!==t&&document.body.removeChild(t)},this.keydown=function(){function e(e){t.options.keyboard&&27==e.which&&t.close()}/in/.test(this.modal.className)?document.removeEventListener("keydown",e,!1):document.addEventListener("keydown",e,!1)},this.trigger=function(){var e=document.querySelectorAll('[data-toggle="modal"]'),i=e.length,o=0;for(o;i>o;o++)e[o].addEventListener("click",function(e){var i=e.target,o=i.getAttribute("data-target")&&i.getAttribute("data-target").replace("#","")||i.getAttribute("href")&&i.getAttribute("href").replace("#","");document.getElementById(o)===t.modal&&t.open()})},this._resize=function(){var t=this.overlay||document.querySelector(".modal-backdrop"),e={w:document.documentElement.clientWidth+"px",h:document.documentElement.clientHeight+"px"};null!==t&&/in/.test(t.className)&&(t.style.height=e.h,t.style.width=e.w)},this.oneResize=function(){function e(){t._resize(),t.handleUpdate(),window.removeEventListener("resize",e,!1)}window.addEventListener("resize",e,!1)},this.resize=function(){/in/.test(this.modal.className)?window.removeEventListener("resize",this.oneResize,!1):window.addEventListener("resize",this.oneResize,!1)},this.dismiss=function(){function e(e){("modal"===e.target.parentNode.getAttribute("data-dismiss")||"modal"===e.target.getAttribute("data-dismiss")||e.target===t.modal)&&(e.preventDefault(),t.close())}/in/.test(this.modal.className)?this.modal.removeEventListener("click",e,!1):this.modal.addEventListener("click",e,!1)},this.handleUpdate=function(){this.adjustDialog()},this.adjustDialog=function(){this.modal.style.paddingLeft=!this.bodyIsOverflowing&&this.modalIsOverflowing?this.scrollbarWidth+"px":"",this.modal.style.paddingRight=this.bodyIsOverflowing&&!this.modalIsOverflowing?this.scrollbarWidth+"px":""},this.resetAdjustments=function(){this.modal.style.paddingLeft="",this.modal.style.paddingRight=""},this.checkScrollbar=function(){this.bodyIsOverflowing=document.body.clientWidth<e(),this.modalIsOverflowing=this.modal.scrollHeight>document.documentElement.clientHeight,this.scrollbarWidth=this.measureScrollbar()},this.setScrollbar=function(){var t=window.getComputedStyle(document.body),e=parseInt(t.paddingRight,10);this.bodyIsOverflowing&&(document.body.style.paddingRight=e+this.scrollbarWidth+"px")},this.resetScrollbar=function(){document.body.style.paddingRight=""},this.measureScrollbar=function(){var t=document.createElement("div");t.className="modal-scrollbar-measure",document.body.appendChild(t);var e=t.offsetWidth-t.clientWidth;return document.body.removeChild(t),e},this.addClass=function(t,e){t.classList?t.classList.add(e):t.className+=" "+e},this.removeClass=function(t,e){t.classList?t.classList.remove(e):t.className=t.className.replace(e,"").replace(/^\s+|\s+$/g,"")}}};var i=document.querySelectorAll(".modal"),o=i.length,s=0;for(s;o>s;s++){var n=i[s],a={};a.keyboard=n.getAttribute("data-keyboard"),a.backdrop=n.getAttribute("data-backdrop"),a.duration=n.getAttribute("data-duration"),new t(n,a)}return t});
|