You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

10 lines
10 KiB

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