bazarr/static/semantic/components/modal.min.js

1 line
12 KiB
JavaScript
Raw Normal View History

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