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.
11 lines
10 KiB
11 lines
10 KiB
/*!
|
|
* # Semantic UI 2.0.0 - 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,C,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);C={initialize:function(){C.verbose("Initializing dimmer",q),C.create.id(),C.create.dimmer(),C.refreshModals(),C.verbose("Attaching close events",E),C.bind.events(),C.observeChanges(),C.instantiate()},instantiate:function(){C.verbose("Storing instance of modal"),N=C,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 e.fn.dimmer===t?void C.error(T.dimmer):(C.debug("Creating dimmer with settings",n),y=q.dimmer(n),A.detachable?(C.verbose("Modal is detachable, moving content into dimmer"),y.dimmer("add content",z)):C.set.undetached(),void(w=y.dimmer("get dimmer")))},id:function(){S=(Math.random().toString(16)+"000000000").substr(2,8),k="."+S,C.verbose("Creating unique id for element",S)}},destroy:function(){C.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(){C.debug("DOM tree modified, refreshing"),C.refresh()}),M.observe(j,{childList:!0,subtree:!0}),C.debug("Setting up mutation observer",M))},refresh:function(){C.remove.scrolling(),C.cacheSizes(),C.set.screenHeight(),C.set.type(),C.set.position()},refreshModals:function(){b=z.siblings(D.modal),s=b.add(z)},attachEvents:function(i,n){var t=e(i);n=e.isFunction(C[n])?C[n]:C.toggle,t.length>0?(C.debug("Attaching modal events to element",i,n),t.off(O).on("click"+O,n)):C.error(T.notFound,i)},bind:{events:function(){E.on("click"+O,C.event.close),r.on("resize"+k,C.event.resize)}},get:{id:function(){return(Math.random().toString(16)+"000000000").substr(2,8)}},event:{close:function(){C.verbose("Closing element pressed"),e(this).is(D.approve)?A.onApprove.call(j)!==!1?C.hide():C.verbose("Approve callback returned false cancelling hide"):e(this).is(D.deny)?A.onDeny.call(j)!==!1?C.hide():C.verbose("Deny callback returned false cancelling hide"):C.hide()},click:function(i){0===e(i.target).closest(z).length&&(C.debug("Dimmer clicked, hiding all modals"),C.is.active()&&(C.remove.clickaway(),A.allowMultiple?C.hide():C.hideAll()))},debounce:function(e,i){clearTimeout(C.timer),C.timer=setTimeout(e,i)},keyboard:function(e){var i=e.which,n=27;i==n&&(A.closable?(C.debug("Escape key pressed hiding modal"),C.hide()):C.debug("Escape key pressed, but closable is set to false"),e.preventDefault())},resize:function(){y.dimmer("is active")&&v(C.refresh)}},toggle:function(){C.is.active()||C.is.animating()?C.hide():C.show()},show:function(i){i=e.isFunction(i)?i:function(){},C.refreshModals(),C.showModal(i)},hide:function(i){i=e.isFunction(i)?i:function(){},C.refreshModals(),C.hideModal(i)},showModal:function(i){i=e.isFunction(i)?i:function(){},C.is.animating()||!C.is.active()?(C.showDimmer(),C.cacheSizes(),C.set.position(),C.set.screenHeight(),C.set.type(),C.set.clickaway(),!A.allowMultiple&&b.filter("."+F.active).length>0?(C.debug("Other modals visible, queueing show animation"),C.hideOthers(C.showModal)):(A.onShow.call(j),A.transition&&e.fn.transition!==t&&z.transition("is supported")?(C.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(){A.onVisible.apply(j),C.add.keyboardShortcuts(),C.save.focus(),C.set.active(),C.set.autofocus(),i()}})):(C.debug("Showing modal with javascript"),z.fadeIn(A.duration,A.easing,function(){A.onVisible.apply(j),C.add.keyboardShortcuts(),C.save.focus(),C.set.active(),i()})))):C.debug("Modal is already visible")},hideModal:function(i,n){i=e.isFunction(i)?i:function(){},C.debug("Hiding modal"),A.onHide.call(j),(C.is.animating()||C.is.active())&&(A.transition&&e.fn.transition!==t&&z.transition("is supported")?(C.remove.active(),z.transition({debug:A.debug,animation:A.transition+" out",queue:A.queue,duration:A.duration,useFailSafe:!0,onStart:function(){C.othersActive()||n||C.hideDimmer(),C.remove.keyboardShortcuts()},onComplete:function(){A.onHidden.call(j),C.restore.focus(),i()}})):(C.remove.active(),C.othersActive()||C.hideDimmer(),C.remove.keyboardShortcuts(),z.fadeOut(A.duration,A.easing,function(){A.onHidden.call(j),C.restore.focus(),i()})))},showDimmer:function(){y.dimmer("is animating")||!y.dimmer("is active")?(C.debug("Showing dimmer"),y.dimmer("show")):C.debug("Dimmer already visible")},hideDimmer:function(){return y.dimmer("is animating")||y.dimmer("is active")?void y.dimmer("hide",function(){A.transition&&e.fn.transition!==t&&z.transition("is supported")&&(C.remove.clickaway(),C.remove.screenHeight())}):void C.debug("Dimmer is not visible cannot hide")},hideAll:function(i){var n=s.filter(":visible");i=e.isFunction(i)?i:function(){},n.length>0&&(C.debug("Hiding all visible modals"),C.hideDimmer(),n.modal("hide modal",i))},hideOthers:function(i){var n=b.filter(":visible");i=e.isFunction(i)?i:function(){},n.length>0&&(C.debug("Hiding other modals",b),n.modal("hide modal",i,!0))},othersActive:function(){return b.filter("."+F.active).length>0},add:{keyboardShortcuts:function(){C.verbose("Adding keyboard shortcuts"),c.on("keyup"+O,C.event.keyboard)}},save:{focus:function(){p=e(n.activeElement).blur()}},restore:{focus:function(){p&&p.length>0&&p.focus()}},remove:{active:function(){z.removeClass(F.active)},clickaway:function(){A.closable&&w.off("click"+k)},screenHeight:function(){C.cache.height>C.cache.pageHeight&&(C.debug("Removing page height"),l.css("height",""))},keyboardShortcuts:function(){C.verbose("Removing keyboard shortcuts"),c.off("keyup"+O)},scrolling:function(){y.removeClass(F.scrolling),z.removeClass(F.scrolling)}},cacheSizes:function(){var o=z.outerHeight();(C.cache===t||0!==o)&&(C.cache={pageHeight:e(n).outerHeight(),height:o+A.offset,contextHeight:"body"==A.context?e(i).height():y.height()}),C.debug("Caching modal and container sizes",C.cache)},can:{fit:function(){return C.cache.height+2*A.padding<C.cache.contextHeight}},is:{active:function(){return z.hasClass(F.active)},animating:function(){return z.transition("is supported")?z.transition("is animating"):z.is(":visible")},scrolling:function(){return y.hasClass(F.scrolling)},modernBrowser:function(){return!(i.ActiveXObject||"ActiveXObject"in i)}},set:{autofocus:function(){if(A.autofocus){var e=z.find(":input:visible"),i=e.filter("[autofocus]"),n=i.length>0?i:e;n.first().focus()}},clickaway:function(){A.closable&&w.on("click"+k,C.event.click)},screenHeight:function(){C.can.fit()?l.css("height",""):(C.debug("Modal is taller than page content, resizing page height"),l.css("height",C.cache.height+2*A.padding))},active:function(){z.addClass(F.active)},scrolling:function(){y.addClass(F.scrolling),z.addClass(F.scrolling)},type:function(){C.can.fit()?(C.verbose("Modal fits on screen"),C.othersActive||C.remove.scrolling()):(C.verbose("Modal cannot fit on screen setting to scrolling"),C.set.scrolling())},position:function(){C.verbose("Centering modal on page",C.cache),z.css(C.can.fit()?{top:"",marginTop:-(C.cache.height/2)}:{marginTop:"",top:c.scrollTop()})},undetached:function(){y.addClass(F.undetached)}},setting:function(i,n){if(C.debug("Changing setting",i,n),e.isPlainObject(i))e.extend(!0,A,i);else{if(n===t)return A[i];A[i]=n}},internal:function(i,n){if(e.isPlainObject(i))e.extend(!0,C,i);else{if(n===t)return C[i];C[i]=n}},debug:function(){A.debug&&(A.performance?C.performance.log(arguments):(C.debug=Function.prototype.bind.call(console.info,console,A.name+":"),C.debug.apply(console,arguments)))},verbose:function(){A.verbose&&A.debug&&(A.performance?C.performance.log(arguments):(C.verbose=Function.prototype.bind.call(console.info,console,A.name+":"),C.verbose.apply(console,arguments)))},error:function(){C.error=Function.prototype.bind.call(console.error,console,A.name+":"),C.error.apply(console,arguments)},performance:{log:function(e){var i,n,t;A.performance&&(i=(new Date).getTime(),t=d||i,n=i-t,d=i,m.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:j,"Execution Time":n})),clearTimeout(C.performance.timer),C.performance.timer=setTimeout(C.performance.display,500)},display:function(){var i=A.name+":",n=0;d=!1,clearTimeout(C.performance.timer),e.each(m,function(e,i){n+=i["Execution Time"]}),i+=" "+n+"ms",u&&(i+=" '"+u+"'"),(console.group!==t||console.table!==t)&&m.length>0&&(console.groupCollapsed(i),console.table?console.table(m):e.each(m,function(e,i){console.log(i.Name+": "+i["Execution Time"]+"ms")}),console.groupEnd()),m=[]}},invoke:function(i,n,o){var s,r,c,l=N;return n=n||h,o=j||o,"string"==typeof i&&l!==t&&(i=i.split(/[\. ]/),s=i.length-1,e.each(i,function(n,o){var a=n!=s?o+i[n+1].charAt(0).toUpperCase()+i[n+1].slice(1):i;if(e.isPlainObject(l[a])&&n!=s)l=l[a];else{if(l[a]!==t)return r=l[a],!1;if(!e.isPlainObject(l[o])||n==s)return l[o]!==t?(r=l[o],!1):!1;l=l[o]}})),e.isFunction(r)?c=r.apply(o,n):r!==t&&(c=r),e.isArray(a)?a.push(c):a!==t?a=[a,c]:c!==t&&(a=c),r}},g?(N===t&&C.initialize(),C.invoke(f)):(N!==t&&N.invoke("destroy"),C.initialize())}),a!==t?a:this},e.fn.modal.settings={name:"Modal",namespace:"modal",debug:!1,verbose:!1,performance:!0,allowMultiple:!1,detachable:!0,closable:!0,autofocus:!0,dimmerSettings:{closable:!1,useCSS:!0},context:"body",queue:!1,duration:500,easing:"easeOutExpo",offset:0,transition:"scale",padding:50,onShow:function(){},onHide:function(){},onVisible:function(){},onHidden:function(){},onApprove:function(){return!0},onDeny:function(){return!0},selector:{close:".close, .actions .button",approve:".actions .positive, .actions .approve, .actions .ok",deny:".actions .negative, .actions .deny, .actions .cancel",modal:".ui.modal"},error:{dimmer:"UI Dimmer, a required component is not included in this page",method:"The method you called is not defined.",notFound:"The element you specified could not be found"},className:{active:"active",animating:"animating",scrolling:"scrolling",undetached:"undetached"}}}(jQuery,window,document);
|