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

9 years ago
9 years ago
10 years ago
9 years ago
10 years ago
9 years ago
  1. /*!
  2. * # Semantic UI x.x - Modal
  3. * http://github.com/semantic-org/semantic-ui/
  4. *
  5. *
  6. * Copyright 2015 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=[],g=arguments[0],f="string"==typeof g,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,C,S,M,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);M={initialize:function(){M.verbose("Initializing dimmer",q),M.create.id(),M.create.dimmer(),M.refreshModals(),M.bind.events(),A.observeChanges&&M.observeChanges(),M.instantiate()},instantiate:function(){M.verbose("Storing instance of modal"),N=M,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 A.inverted&&(n.variation=n.variation!==t?n.variation+" inverted":"inverted"),e.fn.dimmer===t?void M.error(T.dimmer):(M.debug("Creating dimmer with settings",n),y=q.dimmer(n),A.detachable?(M.verbose("Modal is detachable, moving content into dimmer"),y.dimmer("add content",z)):M.set.undetached(),A.blurring&&y.addClass(F.blurring),void(w=y.dimmer("get dimmer")))},id:function(){C=(Math.random().toString(16)+"000000000").substr(2,8),k="."+C,M.verbose("Creating unique id for element",C)}},destroy:function(){M.verbose("Destroying previous modal"),z.removeData(x).off(O),r.off(k),E.off(O),q.dimmer("destroy")},observeChanges:function(){"MutationObserver"in i&&(S=new MutationObserver(function(e){M.debug("DOM tree modified, refreshing"),M.refresh()}),S.observe(j,{childList:!0,subtree:!0}),M.debug("Setting up mutation observer",S))},refresh:function(){M.remove.scrolling(),M.cacheSizes(),M.set.screenHeight(),M.set.type(),M.set.position()},refreshModals:function(){b=z.siblings(D.modal),s=b.add(z)},attachEvents:function(i,n){var t=e(i);n=e.isFunction(M[n])?M[n]:M.toggle,t.length>0?(M.debug("Attaching modal events to element",i,n),t.off(O).on("click"+O,n)):M.error(T.notFound,i)},bind:{events:function(){M.verbose("Attaching events"),z.on("click"+O,D.close,M.event.close),r.on("resize"+k,M.event.resize)}},get:{id:function(){return(Math.random().toString(16)+"000000000").substr(2,8)}},event:{close:function(){var i=e(this);M.verbose("Closing element activated"),i.is(D.approve)?A.onApprove.call(j,i)!==!1?M.hide():M.verbose("Approve callback returned false cancelling hide"):i.is(D.deny)?A.onDeny.call(j,i)!==!1?M.hide():M.verbose("Deny callback returned false cancelling hide"):M.hide()},click:function(i){var t=e(i.target),o=t.closest(D.modal).length>0,a=e.contains(n.documentElement,i.target);!o&&a&&(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")&&v(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.showModal(i)},hide:function(i){i=e.isFunction(i)?i:function(){},M.refreshModals(),M.hideModal(i)},showModal:function(i){i=e.isFunction(i)?i:function(){},M.is.animating()||!M.is.active()?(M.showDimmer(),M.cacheSizes(),M.set.position(),M.set.screenHeight(),M.set.type(),M.set.clickaway(),!A.allowMultiple&&b.filter("."+F.active).length>0?(M.debug("Other modals visible, queueing show animation"),M.hideOthers(M.showModal)):(A.onShow.call(j),A.transition&&e.fn.transition!==t&&z.transition("is supported")?(M.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(