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