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
  1. /*
  2. * # Semantic UI
  3. * git://github.com/Semantic-Org/Semantic-UI.git#1.0
  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,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,A=x.namespace,D=x.error,F="."+A,S="module-"+A,T=e(this),C=e(x.context),M=T.find(H.close),O=this,E=T.data(S);w={initialize:function(){return w.verbose("Initializing dimmer",C),e.fn.dimmer===o?void w.error(D.dimmer):(y=C.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",T),k=y.dimmer("get dimmer"),b=T.siblings(H.modal),a=b.add(T),w.verbose("Attaching close events",M),M.on("click"+F,w.event.close),c.on("resize"+F,w.event.resize),void w.instantiate())},instantiate:function(){w.verbose("Storing instance of modal"),E=w,T.data(S,E)},destroy:function(){w.verbose("Destroying previous modal"),T.removeData(S).off(F),M.off(F),C.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(F).on("click"+F,n)):w.error(D.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&&T.transition("is supported")?(w.debug("Showing modal with css animations"),T.transition({debug:x.debug,animation:x.transition+" in",queue:!1,duration:x.duration,start:function(){w.cacheSizes(),w.set.position(),w.set.screenHeight(),w.set.type(),w.set.clickaway()},complete: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"),T.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&&T.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&&T.transition("is supported")?T.transition({debug:x.deb