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
9.7 KiB

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