blue-twilight/public/semantic-ui/components/modal.min.js

10 lines
11 KiB
JavaScript

/*!
* # Semantic UI 2.2.9 - Modal
* http://github.com/semantic-org/semantic-ui/
*
*
* Released under the MIT license
* http://opensource.org/licenses/MIT
*
*/
!function(e,i,n,t){"use strict";i=void 0!==i&&i.Math==Math?i:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")(),e.fn.modal=function(t){var o,a=e(this),r=e(i),s=e(n),c=e("body"),l=a.selector||"",d=(new Date).getTime(),u=[],m=arguments[0],f="string"==typeof m,g=[].slice.call(arguments,1),h=i.requestAnimationFrame||i.mozRequestAnimationFrame||i.webkitRequestAnimationFrame||i.msRequestAnimationFrame||function(e){setTimeout(e,0)};return a.each(function(){var a,v,b,p,y,k,w,M,S,C=e.isPlainObject(t)?e.extend(!0,{},e.fn.modal.settings,t):e.extend({},e.fn.modal.settings),F=C.selector,A=C.className,D=C.namespace,H=C.error,T="."+D,x="module-"+D,z=e(this),O=e(C.context),q=z.find(F.close),E=this,j=z.data(x);S={initialize:function(){S.verbose("Initializing dimmer",O),S.create.id(),S.create.dimmer(),S.refreshModals(),S.bind.events(),C.observeChanges&&S.observeChanges(),S.instantiate()},instantiate:function(){S.verbose("Storing instance of modal"),j=S,z.data(x,j)},create:{dimmer:function(){var i={debug:C.debug,dimmerName:"modals",duration:{show:C.duration,hide:C.duration}},n=e.extend(!0,i,C.dimmerSettings);if(C.inverted&&(n.variation=void 0!==n.variation?n.variation+" inverted":"inverted"),void 0===e.fn.dimmer)return void S.error(H.dimmer);S.debug("Creating dimmer with settings",n),p=O.dimmer(n),C.detachable?(S.verbose("Modal is detachable, moving content into dimmer"),p.dimmer("add content",z)):S.set.undetached(),C.blurring&&p.addClass(A.blurring),y=p.dimmer("get dimmer")},id:function(){w=(Math.random().toString(16)+"000000000").substr(2,8),k="."+w,S.verbose("Creating unique id for element",w)}},destroy:function(){S.verbose("Destroying previous modal"),z.removeData(x).off(T),r.off(k),y.off(k),q.off(T),O.dimmer("destroy")},observeChanges:function(){"MutationObserver"in i&&(M=new MutationObserver(function(e){S.debug("DOM tree modified, refreshing"),S.refresh()}),M.observe(E,{childList:!0,subtree:!0}),S.debug("Setting up mutation observer",M))},refresh:function(){S.remove.scrolling(),S.cacheSizes(),S.set.screenHeight(),S.set.type(),S.set.position()},refreshModals:function(){v=z.siblings(F.modal),a=v.add(z)},attachEvents:function(i,n){var t=e(i);n=e.isFunction(S[n])?S[n]:S.toggle,t.length>0?(S.debug("Attaching modal events to element",i,n),t.off(T).on("click"+T,n)):S.error(H.notFound,i)},bind:{events:function(){S.verbose("Attaching events"),z.on("click"+T,F.close,S.event.close).on("click"+T,F.approve,S.event.approve).on("click"+T,F.deny,S.event.deny),r.on("resize"+k,S.event.resize)}},get:{id:function(){return(Math.random().toString(16)+"000000000").substr(2,8)}},event:{approve:function(){if(C.onApprove.call(E,e(this))===!1)return void S.verbose("Approve callback returned false cancelling hide");S.hide()},deny:function(){if(C.onDeny.call(E,e(this))===!1)return void S.verbose("Deny callback returned false cancelling hide");S.hide()},close:function(){S.hide()},click:function(i){var t=e(i.target),o=t.closest(F.modal).length>0,a=e.contains(n.documentElement,i.target);!o&&a&&(S.debug("Dimmer clicked, hiding all modals"),S.is.active()&&(S.remove.clickaway(),C.allowMultiple?S.hide():S.hideAll()))},debounce:function(e,i){clearTimeout(S.timer),S.timer=setTimeout(e,i)},keyboard:function(e){27==e.which&&(C.closable?(S.debug("Escape key pressed hiding modal"),S.hide()):S.debug("Escape key pressed, but closable is set to false"),e.preventDefault())},resize:function(){p.dimmer("is active")&&h(S.refresh)}},toggle:function(){S.is.active()||S.is.animating()?S.hide():S.show()},show:function(i){i=e.isFunction(i)?i:function(){},S.refreshModals(),S.showModal(i)},hide:function(i){i=e.isFunction(i)?i:function(){},S.refreshModals(),S.hideModal(i)},showModal:function(i){i=e.isFunction(i)?i:function(){},S.is.animating()||!S.is.active()?(S.showDimmer(),S.cacheSizes(),S.set.position(),S.set.screenHeight(),S.set.type(),S.set.clickaway(),!C.allowMultiple&&S.others.active()?S.hideOthers(S.showModal):(C.onShow.call(E),C.transition&&void 0!==e.fn.transition&&z.transition("is supported")?(S.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(E),C.keyboardShortcuts&&S.add.keyboardShortcuts(),S.save.focus(),S.set.active(),C.autofocus&&S.set.autofocus(),i()}})):S.error(H.noTransition))):S.debug("Modal is already visible")},hideModal:function(i,n){if(i=e.isFunction(i)?i:function(){},S.debug("Hiding modal"),C.onHide.call(E,e(this))===!1)return void S.verbose("Hide callback returned false cancelling hide");(S.is.animating()||S.is.active())&&(C.transition&&void 0!==e.fn.transition&&z.transition("is supported")?(S.remove.active(),z.transition({debug:C.debug,animation:C.transition+" out",queue:C.queue,duration:C.duration,useFailSafe:!0,onStart:function(){S.others.active()||n||S.hideDimmer(),C.keyboardShortcuts&&S.remove.keyboardShortcuts()},onComplete:function(){C.onHidden.call(E),S.restore.focus(),i()}})):S.error(H.noTransition))},showDimmer:function(){p.dimmer("is animating")||!p.dimmer("is active")?(S.debug("Showing dimmer"),p.dimmer("show")):S.debug("Dimmer already visible")},hideDimmer:function(){if(!p.dimmer("is animating")&&!p.dimmer("is active"))return void S.debug("Dimmer is not visible cannot hide");p.dimmer("hide",function(){S.remove.clickaway(),S.remove.screenHeight()})},hideAll:function(i){var n=a.filter("."+A.active+", ."+A.animating);i=e.isFunction(i)?i:function(){},n.length>0&&(S.debug("Hiding all visible modals"),S.hideDimmer(),n.modal("hide modal",i))},hideOthers:function(i){var n=v.filter("."+A.active+", ."+A.animating);i=e.isFunction(i)?i:function(){},n.length>0&&(S.debug("Hiding other modals",v),n.modal("hide modal",i,!0))},others:{active:function(){return v.filter("."+A.active).length>0},animating:function(){return v.filter("."+A.animating).length>0}},add:{keyboardShortcuts:function(){S.verbose("Adding keyboard shortcuts"),s.on("keyup"+T,S.event.keyboard)}},save:{focus:function(){b=e(n.activeElement).blur()}},restore:{focus:function(){b&&b.length>0&&b.focus()}},remove:{active:function(){z.removeClass(A.active)},clickaway:function(){C.closable&&y.off("click"+k)},bodyStyle:function(){""===c.attr("style")&&(S.verbose("Removing style attribute"),c.removeAttr("style"))},screenHeight:function(){S.debug("Removing page height"),c.css("height","")},keyboardShortcuts:function(){S.verbose("Removing keyboard shortcuts"),s.off("keyup"+T)},scrolling:function(){p.removeClass(A.scrolling),z.removeClass(A.scrolling)}},cacheSizes:function(){var t=z.outerHeight();void 0!==S.cache&&0===t||(S.cache={pageHeight:e(n).outerHeight(),height:t+C.offset,contextHeight:"body"==C.context?e(i).height():p.height()}),S.debug("Caching modal and container sizes",S.cache)},can:{fit:function(){return S.cache.height+2*C.padding<S.cache.contextHeight}},is:{active:function(){return z.hasClass(A.active)},animating:function(){return z.transition("is supported")?z.transition("is animating"):z.is(":visible")},scrolling:function(){return p.hasClass(A.scrolling)},modernBrowser:function(){return!(i.ActiveXObject||"ActiveXObject"in i)}},set:{autofocus:function(){var e=z.find("[tabindex], :input").filter(":visible"),i=e.filter("[autofocus]"),n=i.length>0?i.first():e.first();n.length>0&&n.focus()},clickaway:function(){C.closable&&y.on("click"+k,S.event.click)},screenHeight:function(){S.can.fit()?c.css("height",""):(S.debug("Modal is taller than page content, resizing page height"),c.css("height",S.cache.height+2*C.padding))},active:function(){z.addClass(A.active)},scrolling:function(){p.addClass(A.scrolling),z.addClass(A.scrolling)},type:function(){S.can.fit()?(S.verbose("Modal fits on screen"),S.others.active()||S.others.animating()||S.remove.scrolling()):(S.verbose("Modal cannot fit on screen setting to scrolling"),S.set.scrolling())},position:function(){S.verbose("Centering modal on page",S.cache),S.can.fit()?z.css({top:"",marginTop:-(S.cache.height/2)}):z.css({marginTop:"",top:s.scrollTop()})},undetached:function(){p.addClass(A.undetached)}},setting:function(i,n){if(S.debug("Changing setting",i,n),e.isPlainObject(i))e.extend(!0,C,i);else{if(void 0===n)return C[i];e.isPlainObject(C[i])?e.extend(!0,C[i],n):C[i]=n}},internal:function(i,n){if(e.isPlainObject(i))e.extend(!0,S,i);else{if(void 0===n)return S[i];S[i]=n}},debug:function(){!C.silent&&C.debug&&(C.performance?S.performance.log(arguments):(S.debug=Function.prototype.bind.call(console.info,console,C.name+":"),S.debug.apply(console,arguments)))},verbose:function(){!C.silent&&C.verbose&&C.debug&&(C.performance?S.performance.log(arguments):(S.verbose=Function.prototype.bind.call(console.info,console,C.name+":"),S.verbose.apply(console,arguments)))},error:function(){C.silent||(S.error=Function.prototype.bind.call(console.error,console,C.name+":"),S.error.apply(console,arguments))},performance:{log:function(e){var i,n,t;C.performance&&(i=(new Date).getTime(),t=d||i,n=i-t,d=i,u.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:E,"Execution Time":n})),clearTimeout(S.performance.timer),S.performance.timer=setTimeout(S.performance.display,500)},display:function(){var i=C.name+":",n=0;d=!1,clearTimeout(S.performance.timer),e.each(u,function(e,i){n+=i["Execution Time"]}),i+=" "+n+"ms",l&&(i+=" '"+l+"'"),(void 0!==console.group||void 0!==console.table)&&u.length>0&&(console.groupCollapsed(i),console.table?console.table(u):e.each(u,function(e,i){console.log(i.Name+": "+i["Execution Time"]+"ms")}),console.groupEnd()),u=[]}},invoke:function(i,n,t){var a,r,s,c=j;return n=n||g,t=E||t,"string"==typeof i&&void 0!==c&&(i=i.split(/[\. ]/),a=i.length-1,e.each(i,function(n,t){var o=n!=a?t+i[n+1].charAt(0).toUpperCase()+i[n+1].slice(1):i;if(e.isPlainObject(c[o])&&n!=a)c=c[o];else{if(void 0!==c[o])return r=c[o],!1;if(!e.isPlainObject(c[t])||n==a)return void 0!==c[t]&&(r=c[t],!1);c=c[t]}})),e.isFunction(r)?s=r.apply(t,n):void 0!==r&&(s=r),e.isArray(o)?o.push(s):void 0!==o?o=[o,s]:void 0!==s&&(o=s),r}},f?(void 0===j&&S.initialize(),S.invoke(m)):(void 0!==j&&j.invoke("destroy"),S.initialize())}),void 0!==o?o:this},e.fn.modal.settings={name:"Modal",namespace:"modal",silent:!1,debug:!1,verbose:!1,performance:!0,observeChanges:!1,allowMultiple:!1,detachable:!0,closable:!0,autofocus:!0,inverted:!1,blurring:!1,dimmerSettings:{closable:!1,useCSS:!0},keyboardShortcuts:!0,context:"body",queue:!1,duration:500,offset:0,transition:"scale",padding:50,onShow:function(){},onVisible:function(){},onHide:function(){return!0},onHidden:function(){},onApprove:function(){return!0},onDeny:function(){return!0},selector:{close:"> .close",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",blurring:"blurring",scrolling:"scrolling",undetached:"undetached"}}}(jQuery,window,document);