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.4 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),c=e(i),r=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),p=i.requestAnimationFrame||i.mozRequestAnimationFrame||i.webkitRequestAnimationFrame||i.msRequestAnimationFrame||function(e){setTimeout(e,0)};return a.each(function(){var a,b,v,y,k,w,x=e.isPlainObject(t)?e.extend(!0,{},e.fn.modal.settings,t):e.extend({},e.fn.modal.settings),H=x.selector,z=x.className,S=x.namespace,A=x.error,D="."+S,F="module-"+S,C=e(this),T=e(x.context),M=C.find(H.close),O=this,E=C.data(F);w={initialize:function(){return w.verbose("Initializing dimmer",T),e.fn.dimmer===o?void w.error(A.dimmer):(y=T.dimmer({debug:x.debug,dimmerName:"modals",closable:!1,useCSS:!0,duration:{show:.9*x.duration,hide:1.1*x.duration}}),x.detachable&&y.dimmer("add content",C),k=y.dimmer("get dimmer"),b=C.siblings(H.modal),a=b.add(C),w.verbose("Attaching close events",M),M.on("click"+D,w.event.close),c.on("resize"+D,w.event.resize),void w.instantiate())},instantiate:function(){w.verbose("Storing instance of modal"),E=w,C.data(F,E)},destroy:function(){w.verbose("Destroying previous modal"),C.removeData(F).off(D),M.off(D),T.dimmer("destroy")},refresh:function(){w.remove.scrolling(),w.cacheSizes(),w.set.screenHeight(),w.set.type(),w.set.position()},attachEvents:function(i,n){var o=e(i);n=e.isFunction(w[n])?w[n]:w.toggle,o.size()>0?(w.debug("Attaching modal events to element",i,n),o.off(D).on("click"+D,n)):w.error(A.notFound,i)},event:{close:function(){w.verbose("Closing element pressed"),e(this).is(H.approve)?e.proxy(x.onApprove,O)()!==!1?w.hide():w.verbose("Approve callback returned false cancelling hide"):e(this).is(H.deny)?e.proxy(x.onDeny,O)()!==!1?w.hide():w.verbose("Deny callback returned false cancelling hide"):w.hide()},click:function(i){0===e(i.target).closest(H.modal).size()&&(w.debug("Dimmer clicked, hiding all modals"),x.allowMultiple?w.hide():w.hideAll(),i.stopImmediatePropagation())},debounce:function(e,i){clearTimeout(w.timer),w.timer=setTimeout(e,i)},keyboard:function(e){var i=e.which,n=27;i==n&&(x.closable?(w.debug("Escape key pressed hiding modal"),w.hide()):w.debug("Escape key pressed, but closable is set to false"),e.preventDefault())},resize:function(){y.dimmer("is active")&&p(w.refresh)}},toggle:function(){w.is.active()||w.is.animating()?w.hide():w.show()},show:function(i){i=e.isFunction(i)?i:function(){},w.showDimmer(),w.showModal(i)},showModal:function(i){i=e.isFunction(i)?i:function(){},w.is.active()?w.debug("Modal is already visible"):b.filter(":visible").size()>0&&!x.allowMultiple?(w.debug("Other modals visible, queueing show animation"),w.hideOthers(w.showModal)):(e.proxy(x.onShow,O)(),x.transition&&e.fn.transition!==o&&C.transition("is supported")?(w.debug("Showing modal with css animations"),C.transition({debug:x.debug,animation:x.transition+" in",queue:!1,duration:x.duration,onStart:function(){w.cacheSizes(),w.set.position(),w.set.screenHeight(),w.set.type(),w.set.clickaway()},onComplete:function(){e.proxy(x.onVisible,O)(),w.add.keyboardShortcuts(),w.save.focus(),w.set.active(),w.set.autofocus(),i()}})):(w.debug("Showing modal with javascript"),C.fadeIn(x.duration,x.easing,function(){e.proxy(x.onVisible,O)(),w.add.keyboardShortcuts(),w.save.focus(),w.set.active(),i()})))},showDimmer:function(){y.dimmer("is active")?w.debug("Dimmer already visible"):(w.debug("Showing dimmer"),y.dimmer("show"))},hide:function(i){i=e.isFunction(i)?i:function(){},a.filter(":visible").size()<=1&&w.hideDimmer(),w.hideModal(i)},hideDimmer:function(){return y.dimmer("is active")||y.dimmer("is animating")?(w.debug("Hiding dimmer"),w.remove.clickaway(),void y.dimmer("hide",function(){x.transition&&e.fn.transition!==o&&C.transition("is supported")&&w.remove.screenHeight(),w.remove.active()})):void w.debug("Dimmer is not visible cannot hide")},hideModal:function(i){i=e.isFunction(i)?i:function(){},w.debug("Hiding modal"),e.proxy(x.onHide,O)(),x.transition&&e.fn.transition!==o&&C.transition("is supported")?C.transition({debug:x