osu-wayback/static/components/modal.min.js
2018-01-12 23:16:10 +01:00

1 line
12 KiB
JavaScript

!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,C,S,M=e.isPlainObject(t)?e.extend(!0,{},e.fn.modal.settings,t):e.extend({},e.fn.modal.settings),H=M.selector,F=M.className,T=M.namespace,A=M.error,D="."+T,x="module-"+T,O=e(this),z=e(M.context),q=O.find(H.close),E=this,j=O.data(x),N=!1;S={initialize:function(){S.verbose("Initializing dimmer",z),S.create.id(),S.create.dimmer(),S.refreshModals(),S.bind.events(),M.observeChanges&&S.observeChanges(),S.instantiate()},instantiate:function(){S.verbose("Storing instance of modal"),j=S,O.data(x,j)},create:{dimmer:function(){var i={debug:M.debug,dimmerName:"modals"},n=e.extend(!0,i,M.dimmerSettings);if(void 0===e.fn.dimmer)return void S.error(A.dimmer);S.debug("Creating dimmer"),p=z.dimmer(n),M.detachable?(S.verbose("Modal is detachable, moving content into dimmer"),p.dimmer("add content",O)):S.set.undetached(),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"),O.removeData(x).off(D),r.off(k),y.off(k),q.off(D),z.dimmer("destroy")},observeChanges:function(){"MutationObserver"in i&&(C=new MutationObserver(function(e){S.debug("DOM tree modified, refreshing"),S.refresh()}),C.observe(E,{childList:!0,subtree:!0}),S.debug("Setting up mutation observer",C))},refresh:function(){S.remove.scrolling(),S.cacheSizes(),S.set.screenHeight(),S.set.type(),S.set.position()},refreshModals:function(){v=O.siblings(H.modal),a=v.add(O)},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(D).on("click"+D,n)):S.error(A.notFound,i)},bind:{events:function(){S.verbose("Attaching events"),O.on("click"+D,H.close,S.event.close).on("click"+D,H.approve,S.event.approve).on("click"+D,H.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(N||!1===M.onApprove.call(E,e(this)))return void S.verbose("Approve callback returned false cancelling hide");N=!0,S.hide(function(){N=!1})},deny:function(){if(N||!1===M.onDeny.call(E,e(this)))return void S.verbose("Deny callback returned false cancelling hide");N=!0,S.hide(function(){N=!1})},close:function(){S.hide()},click:function(i){var t=e(i.target),o=t.closest(H.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(),M.allowMultiple?S.hide():S.hideAll()))},debounce:function(e,i){clearTimeout(S.timer),S.timer=setTimeout(e,i)},keyboard:function(e){27==e.which&&(M.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")&&(S.is.animating()||S.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.set.dimmerSettings(),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(),!M.allowMultiple&&S.others.active()?S.hideOthers(S.showModal):(M.allowMultiple&&M.detachable&&O.detach().appendTo(y),M.onShow.call(E),M.transition&&void 0!==e.fn.transition&&O.transition("is supported")?(S.debug("Showing modal with css animations"),O.transition({debug:M.debug,animation:M.transition+" in",queue:M.queue,duration:M.duration,useFailSafe:!0,onComplete:function(){M.onVisible.apply(E),M.keyboardShortcuts&&S.add.keyboardShortcuts(),S.save.focus(),S.set.active(),M.autofocus&&S.set.autofocus(),i()}})):S.error(A.noTransition))):S.debug("Modal is already visible")},hideModal:function(i,n){if(i=e.isFunction(i)?i:function(){},S.debug("Hiding modal"),!1===M.onHide.call(E,e(this)))return void S.verbose("Hide callback returned false cancelling hide");(S.is.animating()||S.is.active())&&(M.transition&&void 0!==e.fn.transition&&O.transition("is supported")?(S.remove.active(),O.transition({debug:M.debug,animation:M.transition+" out",queue:M.queue,duration:M.duration,useFailSafe:!0,onStart:function(){S.others.active()||n||S.hideDimmer(),M.keyboardShortcuts&&S.remove.keyboardShortcuts()},onComplete:function(){M.onHidden.call(E),S.restore.focus(),i()}})):S.error(A.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("."+F.active+", ."+F.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("."+F.active+", ."+F.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("."+F.active).length>0},animating:function(){return v.filter("."+F.animating).length>0}},add:{keyboardShortcuts:function(){S.verbose("Adding keyboard shortcuts"),s.on("keyup"+D,S.event.keyboard)}},save:{focus:function(){b=e(n.activeElement).blur()}},restore:{focus:function(){b&&b.length>0&&b.focus()}},remove:{active:function(){O.removeClass(F.active)},clickaway:function(){M.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"+D)},scrolling:function(){p.removeClass(F.scrolling),O.removeClass(F.scrolling)}},cacheSizes:function(){O.addClass(F.loading);var t=O.prop("scrollHeight"),o=O.outerHeight();void 0!==S.cache&&0===o||(S.cache={pageHeight:e(n).outerHeight(),height:o+M.offset,scrollHeight:t+M.offset,contextHeight:"body"==M.context?e(i).height():p.height()},S.cache.topOffset=-S.cache.height/2),O.removeClass(F.loading),S.debug("Caching modal and container sizes",S.cache)},can:{fit:function(){var e=S.cache.contextHeight,i=S.cache.contextHeight/2,n=S.cache.topOffset,t=S.cache.scrollHeight,o=S.cache.height,a=M.padding,r=i+n;return t>o?r+t+a<e:o+2*a<e}},is:{active:function(){return O.hasClass(F.active)},animating:function(){return O.transition("is supported")?O.transition("is animating"):O.is(":visible")},scrolling:function(){return p.hasClass(F.scrolling)},modernBrowser:function(){return!(i.ActiveXObject||"ActiveXObject"in i)}},set:{autofocus:function(){var e=O.find("[tabindex], :input").filter(":visible"),i=e.filter("[autofocus]"),n=i.length>0?i.first():e.first();n.length>0&&n.focus()},clickaway:function(){M.closable&&y.on("click"+k,S.event.click)},dimmerSettings:function(){if(void 0===e.fn.dimmer)return void S.error(A.dimmer);var i={debug:M.debug,dimmerName:"modals",variation:!1,closable:"auto",duration:{show:M.duration,hide:M.duration}},n=e.extend(!0,i,M.dimmerSettings);M.inverted?(n.variation=void 0!==n.variation?n.variation+" inverted":"inverted",y.addClass(F.inverted)):y.removeClass(F.inverted),M.blurring?p.addClass(F.blurring):p.removeClass(F.blurring),z.dimmer("setting",n)},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*M.padding))},active:function(){O.addClass(F.active)},scrolling:function(){p.addClass(F.scrolling),O.addClass(F.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()?O.css({top:"",marginTop:S.cache.topOffset}):O.css({marginTop:"",top:s.scrollTop()})},undetached:function(){p.addClass(F.undetached)}},setting:function(i,n){if(S.debug("Changing setting",i,n),e.isPlainObject(i))e.extend(!0,M,i);else{if(void 0===n)return M[i];e.isPlainObject(M[i])?e.extend(!0,M[i],n):M[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(){!M.silent&&M.debug&&(M.performance?S.performance.log(arguments):(S.debug=Function.prototype.bind.call(console.info,console,M.name+":"),S.debug.apply(console,arguments)))},verbose:function(){!M.silent&&M.verbose&&M.debug&&(M.performance?S.performance.log(arguments):(S.verbose=Function.prototype.bind.call(console.info,console,M.name+":"),S.verbose.apply(console,arguments)))},error:function(){M.silent||(S.error=Function.prototype.bind.call(console.error,console,M.name+":"),S.error.apply(console,arguments))},performance:{log:function(e){var i,n,t;M.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=M.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",inverted:"inverted",loading:"loading",scrolling:"scrolling",undetached:"undetached"}}}(jQuery,window,document);