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