Library/assets/semantic-ui/components/modal.min.js

1 line
12 KiB
JavaScript
Raw Normal View History

2017-11-08 10:25:13 +00:00
!function(e,i,n,t){"use strict";i=void 0!==i&&i.Math==Math?i:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")(),e.fn.modal=function(t){var o,a=e(this),r=e(i),s=e(n),c=e("body"),l=a.selector||"",d=(new Date).getTime(),u=[],m=arguments[0],f="string"==typeof m,g=[].slice.call(arguments,1),h=i.requestAnimationFrame||i.mozRequestAnimationFrame||i.webkitRequestAnimationFrame||i.msRequestAnimationFrame||function(e){setTimeout(e,0)};return a.each(function(){var a,v,b,p,y,k,w,C,S,M=e.isPlainObject(t)?e.extend(!0,{},e.fn.modal.settings,t):e.extend({},e.fn.modal.settings),H=M.selector,F=M.className,T=M.namespace,A=M.error,D="."+T,x="module-"+T,O=e(this),z=e(M.context),q=O.find(H.close),E=this,j=O.data(x),N=!1;S={initialize:function(){S.verbose("Initializing dimmer",z),S.create.id(),S.create.dimmer(),S.refreshModals(),S.bind.events(),M.observeChanges&&S.observeChanges(),S.instantiate()},instantiate:function(){S.verbose("Storing instance of modal"),j=S,O.data(x,j)},create:{dimmer:function(){var i={debug:M.debug,dimmerName:"modals"},n=e.extend(!0,i,M.dimmerSettings);if(void 0===e.fn.dimmer)return void S.error(A.dimmer);S.debug("Creating dimmer"),p=z.dimmer(n),M.detachable?(S.verbose("Modal is detachable, moving content into dimmer"),p.dimmer("add content",O)):S.set.undetached(),y=p.dimmer("get dimmer")},id:function(){w=(Math.random().toString(16)+"000000000").substr(2,8),k="."+w,S.verbose("Creating unique id for element",w)}},destroy:function(){S.verbose("Destroying previous modal"),O.removeData(x).off(D),r.off(k),y.off(k),q.off(D),z.dimmer("destroy")},observeChanges:function(){"MutationObserver"in i&&(C=new MutationObserver(function(e){S.debug("DOM tree modified, refreshing"),S.refresh()}),C.observe(E,{childList:!0,subtree:!0}),S.debug("Setting up mutation observer",C))},refresh:function(){S.remove.scrolling(),S.cacheSizes(),S.set.screenHeight(),S.set.type(),S.set.position()},refreshModals:function(){v=O.siblings(H.modal),a=v.add(O)},attachEvents:function(i,n){var t=e(i);n=e.isFunction(S[n])?S[n]:S.toggle,t.length>0?(S.debug("Attaching modal events to element",i,n),t.off(D).on("click"+D,n)):S.error(A.notFound,i)},bind:{events:function(){S.verbose("Attaching events"),O.on("click"+D,H.close,S.event.close).on("click"+D,H.approve,S.event.approve).on("click"+D,H.deny,S.event.deny),r.on("resize"+k,S.event.resize)}},get:{id:function(){return(Math.random().toString(16)+"000000000").substr(2,8)}},event:{approve:function(){if(N||!1===M.onApprove.call(E,e(this)))return void S.verbose("Approve callback returned false cancelling hide");N=!0,S.hide(function(){N=!1})},deny:function(){if(N||!1===M.onDeny.call(E,e(this)))return void S.verbose("Deny callback returned false cancelling hide");N=!0,S.hide(function(){N=!1})},close:function(){S.hide()},click:function(i){var t=e(i.target),o=t.closest(H.modal).length>0,a=e.contains(n.documentElement,i.target);!o&&a&&(S.debug("Dimmer clicked, hiding all modals"),S.is.active()&&(S.remove.clickaway(),M.allowMultiple?S.hide():S.hideAll()))},debounce:function(e,i){clearTimeout(S.timer),S.timer=setTimeout(e,i)},keyboard:function(e){27==e.which&&(M.closable?(S.debug("Escape key pressed hiding modal"),S.hide()):S.debug("Escape key pressed, but closable is set to false"),e.preventDefault())},resize:function(){p.dimmer("is active")&&(S.is.animating()||S.is.active())&&h(S.refresh)}},toggle:function(){S.is.active()||S.is.animating()?S.hide():S.show()},show:function(i){i=e.isFunction(i)?i:function(){},S.refreshModals(),S.set.dimmerSettings(),S.showModal(i)},hide:function(i){i=e.isFunction(i)?i:function(){},S.refreshModals(),S.hideModal(i)},showModal:function(i){i=e.isFunction(i)?i:function(){},S.is.animating()||!S.is.active()?(S.showDimmer(),S.cacheSizes(),S.set.position(),S.set.screenHeight(),S.set.type(),S.set.clickaway(),!M.allowMultiple&&S.others.active()?S.hideOthers(S.showModal):(M.allowMultiple&&M.detachable&&O.detach().appendTo(y),M.onShow.call(E),M.transition&&void 0!==e.fn.transition&&O.transition("is supported")?(S.debug("Showing modal with css animations"),O.transition({debug:M.debug,an