modal.min.js 16 KB

1234567891011
  1. /*
  2. * # Fomantic UI - 2.8.4
  3. * https://github.com/fomantic/Fomantic-UI
  4. * http://fomantic-ui.com/
  5. *
  6. * Copyright 2014 Contributors
  7. * Released under the MIT license
  8. * http://opensource.org/licenses/MIT
  9. *
  10. */
  11. !function(I,R,N,P){"use strict";I.isFunction=I.isFunction||function(e){return"function"==typeof e&&"number"!=typeof e.nodeType},R=void 0!==R&&R.Math==Math?R:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")(),I.fn.modal=function(M){var H,e=I(this),T=I(R),D=I(N),A=I("body"),E=e.selector||"",O=(new Date).getTime(),L=[],z=M,j="string"==typeof z,q=[].slice.call(arguments,1),B=R.requestAnimationFrame||R.mozRequestAnimationFrame||R.webkitRequestAnimationFrame||R.msRequestAnimationFrame||function(e){setTimeout(e,0)};return e.each(function(){var o,r,e,t,n,a,s,i,c,l,d,u=I.isPlainObject(M)?I.extend(!0,{},I.fn.modal.settings,M):I.extend({},I.fn.modal.settings),m=u.selector,f=u.className,g=u.namespace,h=u.error,v="."+g,b="module-"+g,p=I(this),y=I(u.context),w=p.find(m.close),S=this,C=p.data(b),x=!1,k="",F="";d={initialize:function(){d.cache={},d.verbose("Initializing dimmer",y),d.create.id(),d.create.dimmer(),u.allowMultiple&&d.create.innerDimmer(),u.centered||p.addClass("top aligned"),d.refreshModals(),d.bind.events(),u.observeChanges&&d.observeChanges(),d.instantiate()},instantiate:function(){d.verbose("Storing instance of modal"),C=d,p.data(b,C)},create:{dimmer:function(){var e={debug:u.debug,dimmerName:"modals"},i=I.extend(!0,e,u.dimmerSettings);I.fn.dimmer!==P?(d.debug("Creating dimmer"),t=y.dimmer(i),u.detachable?(d.verbose("Modal is detachable, moving content into dimmer"),t.dimmer("add content",p)):d.set.undetached(),n=t.dimmer("get dimmer")):d.error(h.dimmer)},id:function(){c=(Math.random().toString(16)+"000000000").substr(2,8),i="."+c,d.verbose("Creating unique id for element",c)},innerDimmer:function(){0==p.find(m.dimmer).length&&p.prepend('<div class="ui inverted dimmer"></div>')}},destroy:function(){l&&l.disconnect(),d.verbose("Destroying previous modal"),p.removeData(b).off(v),T.off(i),n.off(i),w.off(v),y.dimmer("destroy")},observeChanges:function(){"MutationObserver"in R&&((l=new MutationObserver(function(e){d.debug("DOM tree modified, refreshing"),d.refresh()})).observe(S,{childList:!0,subtree:!0}),d.debug("Setting up mutation observer",l))},refresh:function(){d.remove.scrolling(),d.cacheSizes(),d.can.useFlex()||d.set.modalOffset(),d.set.screenHeight(),d.set.type()},refreshModals:function(){r=p.siblings(m.modal),o=r.add(p)},attachEvents:function(e,i){var n=I(e);i=I.isFunction(d[i])?d[i]:d.toggle,0<n.length?(d.debug("Attaching modal events to element",e,i),n.off(v).on("click"+v,i)):d.error(h.notFound,e)},bind:{events:function(){d.verbose("Attaching events"),p.on("click"+v,m.close,d.event.close).on("click"+v,m.approve,d.event.approve).on("click"+v,m.deny,d.event.deny),T.on("resize"+i,d.event.resize)},scrollLock:function(){t.get(0).addEventListener("touchmove",d.event.preventScroll,{passive:!1})}},unbind:{scrollLock:function(){t.get(0).removeEventListener("touchmove",d.event.preventScroll,{passive:!1})}},get:{id:function(){return(Math.random().toString(16)+"000000000").substr(2,8)}},event:{approve:function(){x||!1===u.onApprove.call(S,I(this))?d.verbose("Approve callback returned false cancelling hide"):(x=!0,d.hide(function(){x=!1}))},preventScroll:function(e){-1!==e.target.className.indexOf("dimmer")&&e.preventDefault()},deny:function(){x||!1===u.onDeny.call(S,I(this))?d.verbose("Deny callback returned false cancelling hide"):(x=!0,d.hide(function(){x=!1}))},close:function(){d.hide()},mousedown:function(e){var i=I(e.target),n=d.is.rtl();(a=0<i.closest(m.modal).length)&&d.verbose("Mouse down event registered inside the modal"),(s=d.is.scrolling()&&(!n&&I(R).outerWidth()-u.scrollbarWidth<=e.clientX||n&&u.scrollbarWidth>=e.clientX))&&d.verbose("Mouse down event registered inside the scrollbar")},mouseup:function(e){if(u.closable)if(a)d.debug("Dimmer clicked but mouse down was initially registered inside the modal");else if(s)d.debug("Dimmer clicked but mouse down was initially registered inside the scrollbar");else{var i=0<I(e.target).closest(m.modal).length,n=I.contains(N.documentElement,e.target);if(!i&&n&&d.is.active()&&p.hasClass(f.front)){if(d.debug("Dimmer clicked, hiding all modals"),u.allowMultiple){if(!d.hideAll())return}else if(!d.hide())return;d.remove.clickaway()}}else d.verbose("Dimmer clicked but closable setting is disabled")},debounce:function(e,i){clearTimeout(d.timer),d.timer=setTimeout(e,i)},keyboard:function(e){27==e.which&&(u.closable?(d.debug("Escape key pressed hiding modal"),p.hasClass(f.front)&&d.hide()):d.debug("Escape key pressed, but closable is set to false"),e.preventDefault())},resize:function(){t.dimmer("is active")&&(d.is.animating()||d.is.active())&&B(d.refresh)}},toggle:function(){d.is.active()||d.is.animating()?d.hide():d.show()},show:function(e){e=I.isFunction(e)?e:function(){},d.refreshModals(),d.set.dimmerSettings(),d.set.dimmerStyles(),d.showModal(e)},hide:function(e){return e=I.isFunction(e)?e:function(){},d.refreshModals(),d.hideModal(e)},showModal:function(e){e=I.isFunction(e)?e:function(){},d.is.animating()||!d.is.active()?(d.showDimmer(),d.cacheSizes(),d.set.bodyMargin(),d.can.useFlex()?d.remove.legacy():(d.set.legacy(),d.set.modalOffset(),d.debug("Using non-flex legacy modal positioning.")),d.set.screenHeight(),d.set.type(),d.set.clickaway(),!u.allowMultiple&&d.others.active()?d.hideOthers(d.showModal):(x=!1,u.allowMultiple&&(d.others.active()&&r.filter("."+f.active).find(m.dimmer).addClass("active"),u.detachable&&p.detach().appendTo(n)),u.onShow.call(S),u.transition&&I.fn.transition!==P&&p.transition("is supported")?(d.debug("Showing modal with css animations"),p.transition({debug:u.debug,animation:u.transition+" in",queue:u.queue,duration:u.duration,useFailSafe:!0,onComplete:function(){u.onVisible.apply(S),u.keyboardShortcuts&&d.add.keyboardShortcuts(),d.save.focus(),d.set.active(),u.autofocus&&d.set.autofocus(),e()}})):d.error(h.noTransition))):d.debug("Modal is already visible")},hideModal:function(e,i,n){var t=r.filter("."+f.active).last();if(e=I.isFunction(e)?e:function(){},d.debug("Hiding modal"),!1===u.onHide.call(S,I(this)))return d.verbose("Hide callback returned false cancelling hide"),x=!1;(d.is.animating()||d.is.active())&&(u.transition&&I.fn.transition!==P&&p.transition("is supported")?(d.remove.active(),p.transition({debug:u.debug,animation:u.transition+" out",queue:u.queue,duration:u.duration,useFailSafe:!0,onStart:function(){d.others.active()||d.others.animating()||i||d.hideDimmer(),u.keyboardShortcuts&&!d.others.active()&&d.remove.keyboardShortcuts()},onComplete:function(){d.unbind.scrollLock(),u.allowMultiple&&(t.addClass(f.front),p.removeClass(f.front),n?o.find(m.dimmer).removeClass("active"):t.find(m.dimmer).removeClass("active")),u.onHidden.call(S),d.remove.dimmerStyles(),d.restore.focus(),e()}})):d.error(h.noTransition))},showDimmer:function(){t.dimmer("is animating")||!t.dimmer("is active")?(d.save.bodyMargin(),d.debug("Showing dimmer"),t.dimmer("show")):d.debug("Dimmer already visible")},hideDimmer:function(){t.dimmer("is animating")||t.dimmer("is active")?(d.unbind.scrollLock(),t.dimmer("hide",function(){d.restore.bodyMargin(),d.remove.clickaway(),d.remove.screenHeight()})):d.debug("Dimmer is not visible cannot hide")},hideAll:function(n){var e=o.filter("."+f.active+", ."+f.animating);if(n=I.isFunction(n)?n:function(){},0<e.length){d.debug("Hiding all visible modals");var t=!0;return I(e.get().reverse()).each(function(e,i){t=t&&I(i).modal("hide modal",n,!1,!0)}),t&&d.hideDimmer(),t}},hideOthers:function(e){var i=r.filter("."+f.active+", ."+f.animating);e=I.isFunction(e)?e:function(){},0<i.length&&(d.debug("Hiding other modals",r),i.modal("hide modal",e,!0))},others:{active:function(){return 0<r.filter("."+f.active).length},animating:function(){return 0<r.filter("."+f.animating).length}},add:{keyboardShortcuts:function(){d.verbose("Adding keyboard shortcuts"),D.on("keyup"+v,d.event.keyboard)}},save:{focus:function(){0<I(N.activeElement).closest(p).length||(e=I(N.activeElement).blur())},bodyMargin:function(){k=A.css("margin-"+(d.can.leftBodyScrollbar()?"left":"right"));var e=parseInt(k.replace(/[^\d.]/g,"")),i=R.innerWidth-N.documentElement.clientWidth;F=e+i}},restore:{focus:function(){e&&0<e.length&&u.restoreFocus&&e.focus()},bodyMargin:function(){var e=d.can.leftBodyScrollbar()?"left":"right";A.css("margin-"+e,k),A.find(m.bodyFixed.replace("right",e)).css("padding-"+e,k)}},remove:{active:function(){p.removeClass(f.active)},legacy:function(){p.removeClass(f.legacy)},clickaway:function(){u.detachable||p.off("mousedown"+i),n.off("mousedown"+i),n.off("mouseup"+i)},dimmerStyles:function(){n.removeClass(f.inverted),t.removeClass(f.blurring)},bodyStyle:function(){""===A.attr("style")&&(d.verbose("Removing style attribute"),A.removeAttr("style"))},screenHeight:function(){d.debug("Removing page height"),A.css("height","")},keyboardShortcuts:function(){d.verbose("Removing keyboard shortcuts"),D.off("keyup"+v)},scrolling:function(){t.removeClass(f.scrolling),p.removeClass(f.scrolling)}},cacheSizes:function(){p.addClass(f.loading);var e=p.prop("scrollHeight"),i=p.outerWidth(),n=p.outerHeight();d.cache.pageHeight!==P&&0===n||(I.extend(d.cache,{pageHeight:I(N).outerHeight(),width:i,height:n+u.offset,scrollHeight:e+u.offset,contextHeight:"body"==u.context?I(R).height():t.height()}),d.cache.topOffset=-d.cache.height/2),p.removeClass(f.loading),d.debug("Caching modal and container sizes",d.cache)},can:{leftBodyScrollbar:function(){return d.cache.leftBodyScrollbar===P&&(d.cache.leftBodyScrollbar=d.is.rtl()&&(d.is.iframe&&!d.is.firefox()||d.is.safari()||d.is.edge()||d.is.ie())),d.cache.leftBodyScrollbar},useFlex:function(){return"auto"===u.useFlex?u.detachable&&!d.is.ie():(u.useFlex&&d.is.ie()?d.debug("useFlex true is not supported in IE"):u.useFlex&&!u.detachable&&d.debug("useFlex true in combination with detachable false is not supported"),u.useFlex)},fit:function(){var e=d.cache.contextHeight,i=d.cache.contextHeight/2,n=d.cache.topOffset,t=d.cache.scrollHeight,o=d.cache.height,r=u.padding;return o<t?i+n+t+r<e:o+2*r<e}},is:{active:function(){return p.hasClass(f.active)},ie:function(){if(d.cache.isIE===P){var e=!R.ActiveXObject&&"ActiveXObject"in R,i="ActiveXObject"in R;d.cache.isIE=e||i}return d.cache.isIE},animating:function(){return p.transition("is supported")?p.transition("is animating"):p.is(":visible")},scrolling:function(){return t.hasClass(f.scrolling)},modernBrowser:function(){return!(R.ActiveXObject||"ActiveXObject"in R)},rtl:function(){return d.cache.isRTL===P&&(d.cache.isRTL="rtl"===A.attr("dir")||"rtl"===A.css("direction")),d.cache.isRTL},safari:function(){return d.cache.isSafari===P&&(d.cache.isSafari=/constructor/i.test(R.HTMLElement)||!!R.ApplePaySession),d.cache.isSafari},edge:function(){return d.cache.isEdge===P&&(d.cache.isEdge=!!R.setImmediate&&!d.is.ie()),d.cache.isEdge},firefox:function(){return d.cache.isFirefox===P&&(d.cache.isFirefox=!!R.InstallTrigger),d.cache.isFirefox},iframe:function(){return!(self===top)}},set:{autofocus:function(){var e=p.find("[tabindex], :input").filter(":visible").filter(function(){return 0===I(this).closest(".disabled").length}),i=e.filter("[autofocus]"),n=0<i.length?i.first():e.first();0<n.length&&n.focus()},bodyMargin:function(){var e=d.can.leftBodyScrollbar()?"left":"right";(u.detachable||d.can.fit())&&A.css("margin-"+e,F+"px"),A.find(m.bodyFixed.replace("right",e)).css("padding-"+e,F+"px")},clickaway:function(){u.detachable||p.on("mousedown"+i,d.event.mousedown),n.on("mousedown"+i,d.event.mousedown),n.on("mouseup"+i,d.event.mouseup)},dimmerSettings:function(){if(I.fn.dimmer!==P){var e={debug:u.debug,dimmerName:"modals",closable:"auto",useFlex:d.can.useFlex(),duration:{show:u.duration,hide:u.duration}},i=I.extend(!0,e,u.dimmerSettings);u.inverted&&(i.variation=i.variation!==P?i.variation+" inverted":"inverted"),y.dimmer("setting",i)}else d.error(h.dimmer)},dimmerStyles:function(){u.inverted?n.addClass(f.inverted):n.removeClass(f.inverted),u.blurring?t.addClass(f.blurring):t.removeClass(f.blurring)},modalOffset:function(){if(u.detachable)p.css({marginTop:!p.hasClass("aligned")&&d.can.fit()?-d.cache.height/2:u.padding/2,marginLeft:-d.cache.width/2});else{var e=d.can.fit();p.css({top:!p.hasClass("aligned")&&e?I(N).scrollTop()+(d.cache.contextHeight-d.cache.height)/2:!e||p.hasClass("top")?I(N).scrollTop()+u.padding:I(N).scrollTop()+(d.cache.contextHeight-d.cache.height-u.padding),marginLeft:-d.cache.width/2})}d.verbose("Setting modal offset for legacy mode")},screenHeight:function(){d.can.fit()?A.css("height",""):p.hasClass("bottom")||(d.debug("Modal is taller than page content, resizing page height"),A.css("height",d.cache.height+2*u.padding))},active:function(){p.addClass(f.active+" "+f.front),r.filter("."+f.active).removeClass(f.front)},scrolling:function(){t.addClass(f.scrolling),p.addClass(f.scrolling),d.unbind.scrollLock()},legacy:function(){p.addClass(f.legacy)},type:function(){d.can.fit()?(d.verbose("Modal fits on screen"),d.others.active()||d.others.animating()||(d.remove.scrolling(),d.bind.scrollLock())):p.hasClass("bottom")?d.verbose("Bottom aligned modal not fitting on screen is unsupported for scrolling"):(d.verbose("Modal cannot fit on screen setting to scrolling"),d.set.scrolling())},undetached:function(){t.addClass(f.undetached)}},setting:function(e,i){if(d.debug("Changing setting",e,i),I.isPlainObject(e))I.extend(!0,u,e);else{if(i===P)return u[e];I.isPlainObject(u[e])?I.extend(!0,u[e],i):u[e]=i}},internal:function(e,i){if(I.isPlainObject(e))I.extend(!0,d,e);else{if(i===P)return d[e];d[e]=i}},debug:function(){!u.silent&&u.debug&&(u.performance?d.performance.log(arguments):(d.debug=Function.prototype.bind.call(console.info,console,u.name+":"),d.debug.apply(console,arguments)))},verbose:function(){!u.silent&&u.verbose&&u.debug&&(u.performance?d.performance.log(arguments):(d.verbose=Function.prototype.bind.call(console.info,console,u.name+":"),d.verbose.apply(console,arguments)))},error:function(){u.silent||(d.error=Function.prototype.bind.call(console.error,console,u.name+":"),d.error.apply(console,arguments))},performance:{log:function(e){var i,n;u.performance&&(n=(i=(new Date).getTime())-(O||i),O=i,L.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:S,"Execution Time":n})),clearTimeout(d.performance.timer),d.performance.timer=setTimeout(d.performance.display,500)},display:function(){var e=u.name+":",n=0;O=!1,clearTimeout(d.performance.timer),I.each(L,function(e,i){n+=i["Execution Time"]}),e+=" "+n+"ms",E&&(e+=" '"+E+"'"),(console.group!==P||console.table!==P)&&0<L.length&&(console.groupCollapsed(e),console.table?console.table(L):I.each(L,function(e,i){console.log(i.Name+": "+i["Execution Time"]+"ms")}),console.groupEnd()),L=[]}},invoke:function(t,e,i){var o,r,n,a=C;return e=e||q,i=S||i,"string"==typeof t&&a!==P&&(t=t.split(/[\. ]/),o=t.length-1,I.each(t,function(e,i){var n=e!=o?i+t[e+1].charAt(0).toUpperCase()+t[e+1].slice(1):t;if(I.isPlainObject(a[n])&&e!=o)a=a[n];else{if(a[n]!==P)return r=a[n],!1;if(!I.isPlainObject(a[i])||e==o)return a[i]!==P&&(r=a[i]),!1;a=a[i]}})),I.isFunction(r)?n=r.apply(i,e):r!==P&&(n=r),Array.isArray(H)?H.push(n):H!==P?H=[H,n]:n!==P&&(H=n),r}},j?(C===P&&d.initialize(),d.invoke(z)):(C!==P&&C.invoke("destroy"),d.initialize())}),H!==P?H:this},I.fn.modal.settings={name:"Modal",namespace:"modal",useFlex:"auto",offset:0,silent:!1,debug:!1,verbose:!1,performance:!0,observeChanges:!1,allowMultiple:!1,detachable:!0,closable:!0,autofocus:!0,restoreFocus:!0,inverted:!1,blurring:!1,centered:!0,dimmerSettings:{closable:!1,useCSS:!0},keyboardShortcuts:!0,context:"body",queue:!1,duration:500,transition:"scale",padding:50,scrollbarWidth:10,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",dimmer:"> .ui.dimmer",bodyFixed:"> .ui.fixed.menu, > .ui.right.toast-container, > .ui.right.sidebar"},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",inverted:"inverted",legacy:"legacy",loading:"loading",scrolling:"scrolling",undetached:"undetached",front:"front"}}}(jQuery,window,document);