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.4 KiB

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