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

10 years ago
10 years ago
10 years ago
10 years ago
  1. /*
  2. * # Semantic UI
  3. * https://github.com/Semantic-Org/Semantic-UI
  4. * http://www.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,r=e(this),a=e(i),c=e(n),l=e("body"),u=r.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 r.each(function(){var r,v,p,y,w,k,x,H,M,A=e.isPlainObject(t)?e.extend(!0,{},e.fn.modal.settings,t):e.extend({},e.fn.modal.settings),D=A.selector,S=A.className,z=A.namespace,C=A.error,F="."+z,T="module-"+z,O=e(this),q=e(A.context),E=O.find(D.close),j=this,I=O.data(T);M={initialize:function(){return M.verbose("Initializing dimmer",q),e.fn.dimmer===o?void M.error(C.dimmer):(x=M.get.uniqueID(),k="."+x,y=q.dimmer({debug:A.debug,dimmerName:"modals",closable:!1,useCSS:!0,duration:{show:.9*A.duration,hide:1.1*A.duration}}),A.detachable&&y.dimmer("add content",O),w=y.dimmer("get dimmer"),M.refreshModals(),M.verbose("Attaching close events",E),M.bind.events(),M.observeChanges(),void M.instantiate())},instantiate:function(){M.verbose("Storing instance of modal"),I=M,O.data(T,I)},destroy:function(){M.verbose("Destroying previous modal"),O.removeData(T).off(F),a.off(k),E.off(F),q.dimmer("destroy")},observeChanges:function(){"MutationObserver"in i&&(H=new MutationObserver(function(){M.debug("DOM tree modified, refreshing"),M.refresh()}),H.observe(j,{childList:!0,subtree:!0}),M.debug("Setting up mutation observer",H))},refresh:function(){M.remove.scrolling(),M.cacheSizes(),M.set.screenHeight(),M.set.type(),M.set.position()},refreshModals:function(){v=O.siblings(D.modal),r=v.add(O)},attachEvents:function(i,n){var o=e(i);n=e.isFunction(M[n])?M[n]:M.toggle,o.size()>0?(M.debug("Attaching modal events to element",i,n),o.off(F).on("click"+F,n)):M.error(C.notFound,i)},bind:{events:function(){E.on("click"+F,M.event.close),a.on("resize"+k,M.event.resize)}},get:{uniqueID:function(){return(Math.random().toString(16)+"000000000").substr(2,8)}},event:{close:function(){M.verbose("Closing element pressed"),e(this).is(D.approve)?e.proxy(A.onApprove,j)()!==!1?M.hide():M.verbose("Approve callback returned false cancelling hide"):e(this).is(D.deny)?e.proxy(A.onDeny,j)()!==!1?M.hide():M.verbose("Deny callback returned false cancelling hide"):M.hide()},click:function(i){0===e(i.target).closest(O).size()&&(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")&&b(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.showDimmer(),M.showModal(i)},hide:function(i){i=e.isFunction(i)?i:function(){},M.refreshModals(),M.othersActive()||M.hideDimmer(),M.hideModal(i)},showModal:function(i){i=e.isFunction(i)?i:function(){},M.is.active()?M.debug("Modal is already visible"):!A.allowMultiple&&v.filter(":visible").size()>0?(M.debug("Other modals visible, queueing show animation"),M.hideOthers(M.showModal)):(e.proxy(A.onShow,j)(),A.transition&&e.fn.transition!==o&&O.transition("is supported")?(M.debug("Showing modal with css animations"),M.cacheSizes(),M.set.position(),M.set.screenHeight(),M.set.type(),M.set.clickaway(),O.transition({debug:A.debug,animation:A.transition+" in",queue:!1,duration:A.duration,onComplete:function(){e.proxy(A.onVisible,j)(),M.add.keyboardShortcuts(),M.save.focus(),M.set.active(),M.set.autofocus(),i()}})):(M.debug("Showing modal with javascript"),O.fadeIn(A.duration,A.easing,function(){e.proxy(A.onVisible,j)(),M.add.keyboardShortcuts(),M.save.focus(),M.set.active(),i()})))},showDimmer:function(){y.dimmer("is active")?M.debug("Dimmer already visible"):(M.debug("Showing dimmer"),y.dimmer("show"))},hideDimmer:function(){return y.dimmer("is