This repository has been archived on 2024-01-26. You can view files and clone it, but cannot push or open issues or pull requests.
calcifer/web/semantic/dist/components/modal.min.js

11 lines
10 KiB
JavaScript
Raw Normal View History

2015-03-29 19:33:23 +02:00
/*!
* # Semantic UI 1.11.4 - Modal
* http://github.com/semantic-org/semantic-ui/
*
*
* Copyright 2014 Contributors
* Released under the MIT license
* http://opensource.org/licenses/MIT
*
*/
!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=[],f=arguments[0],g="string"==typeof f,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,S,M,A,C=e.isPlainObject(o)?e.extend(!0,{},e.fn.modal.settings,o):e.extend({},e.fn.modal.settings),D=C.selector,F=C.className,H=C.namespace,T=C.error,O="."+H,x="module-"+H,z=e(this),q=e(C.context),E=z.find(D.close),j=this,N=z.data(x);A={initialize:function(){A.verbose("Initializing dimmer",q),A.create.id(),A.create.dimmer(),A.refreshModals(),A.verbose("Attaching close events",E),A.bind.events(),A.observeChanges(),A.instantiate()},instantiate:function(){A.verbose("Storing instance of modal"),N=A,z.data(x,N)},create:{dimmer:function(){var i={debug:C.debug,dimmerName:"modals",duration:{show:C.duration,hide:C.duration}},n=e.extend(!0,i,C.dimmerSettings);return e.fn.dimmer===t?void A.error(T.dimmer):(A.debug("Creating dimmer with settings",n),y=q.dimmer(n),C.detachable&&(A.verbose("Modal is detachable, moving content into dimmer"),y.dimmer("add content",z)),void(w=y.dimmer("get dimmer")))},id:function(){S=(Math.random().toString(16)+"000000000").substr(2,8),k="."+S,A.verbose("Creating unique id for element",S)}},destroy:function(){A.verbose("Destroying previous modal"),z.removeData(x).off(O),r.off(k),E.off(O),q.dimmer("destroy")},observeChanges:function(){"MutationObserver"in i&&(M=new MutationObserver(function(){A.debug("DOM tree modified, refreshing"),A.refresh()}),M.observe(j,{childList:!0,subtree:!0}),A.debug("Setting up mutation observer",M))},refresh:function(){A.remove.scrolling(),A.cacheSizes(),A.set.screenHeight(),A.set.type(),A.set.position()},refreshModals:function(){b=z.siblings(D.modal),s=b.add(z)},attachEvents:function(i,n){var t=e(i);n=e.isFunction(A[n])?A[n]:A.toggle,t.length>0?(A.debug("Attaching modal events to element",i,n),t.off(O).on("click"+O,n)):A.error(T.notFound,i)},bind:{events:function(){E.on("click"+O,A.event.close),r.on("resize"+k,A.event.resize)}},get:{id:function(){return(Math.random().toString(16)+"000000000").substr(2,8)}},event:{close:function(){A.verbose("Closing element pressed"),e(this).is(D.approve)?C.onApprove.call(j)!==!1?A.hide():A.verbose("Approve callback returned false cancelling hide"):e(this).is(D.deny)?C.onDeny.call(j)!==!1?A.hide():A.verbose("Deny callback returned false cancelling hide"):A.hide()},click:function(i){0===e(i.target).closest(z).length&&(A.debug("Dimmer clicked, hiding all modals"),A.is.active()&&(A.remove.clickaway(),C.allowMultiple?A.hide():A.hideAll()))},debounce:function(e,i){clearTimeout(A.timer),A.timer=setTimeout(e,i)},keyboard:function(e){var i=e.which,n=27;i==n&&(C.closable?(A.debug("Escape key pressed hiding modal"),A.hide()):A.debug("Escape key pressed, but closable is set to false"),e.preventDefault())},resize:function(){y.dimmer("is active")&&v(A.refresh)}},toggle:function(){A.is.active()||A.is.animating()?A.hide():A.show()},show:function(i){i=e.isFunction(i)?i:function(){},A.refreshModals(),A.showModal(i)},hide:function(i){i=e.isFunction(i)?i:function(){},A.refreshModals(),A.hideModal(i)},showModal:function(i){i=e.isFunction(i)?i:function(){},A.is.animating()||!A.is.active()?(A.showDimmer(),A.cacheSizes(),A.set.position(),A.set.screenHeight(),A.set.type(),A.set.clickaway(),!C.allowMultiple&&b.filter("."+F.active).length>0?(A.debug("Other modals visible, queueing show animation"),A.hideOthers(A.showModal)):(C.onShow.call(j),C.transition&&e.fn.transition!==t&&z.transition("is supported")?(A.debug("Showing modal with css animations"),z.transition({debug:C.debug,animation:C.transition+" in",queue:C.queue,duration:C.duration,useFailSafe:!0,onComplete:function(){C.onVisible.apply(j),A.add.keyboardShortcuts(),A.save.focus(),A.set.active(),A.set.autofocus(),i()}})):(A.debug("Showing modal with javascript"),z.fadeIn(C.duration,C.easing,function(){C.onVisible.apply(j),A.add.keyb