1 line
7.9 KiB
JavaScript
1 line
7.9 KiB
JavaScript
!function(x,e,F,T){"use strict";e=void 0!==e&&e.Math==Math?e:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")(),x.fn.dimmer=function(p){var b,v=x(this),h=(new Date).getTime(),y=[],C=p,w="string"==typeof C,S=[].slice.call(arguments,1);return v.each(function(){var a,i,r=x.isPlainObject(p)?x.extend(!0,{},x.fn.dimmer.settings,p):x.extend({},x.fn.dimmer.settings),n=r.selector,e=r.namespace,t=r.className,s=r.error,o="."+e,m="module-"+e,d=v.selector||"",c="ontouchstart"in F.documentElement?"touchstart":"click",l=x(this),u=this,f=l.data(m),g={preinitialize:function(){a=g.is.dimmer()?(i=l.parent(),l):(i=l,g.has.dimmer()?r.dimmerName?i.find(n.dimmer).filter("."+r.dimmerName):i.find(n.dimmer):g.create())},initialize:function(){g.debug("Initializing dimmer",r),g.bind.events(),g.set.dimmable(),g.instantiate()},instantiate:function(){g.verbose("Storing instance of module",g),f=g,l.data(m,f)},destroy:function(){g.verbose("Destroying previous module",a),g.unbind.events(),g.remove.variation(),i.off(o)},bind:{events:function(){"hover"==r.on?i.on("mouseenter"+o,g.show).on("mouseleave"+o,g.hide):"click"==r.on&&i.on(c+o,g.toggle),g.is.page()&&(g.debug("Setting as a page dimmer",i),g.set.pageDimmer()),g.is.closable()&&(g.verbose("Adding dimmer close event",a),i.on(c+o,n.dimmer,g.event.click))}},unbind:{events:function(){l.removeData(m),i.off(o)}},event:{click:function(e){g.verbose("Determining if event occurred on dimmer",e),0!==a.find(e.target).length&&!x(e.target).is(n.content)||(g.hide(),e.stopImmediatePropagation())}},addContent:function(e){var i=x(e);g.debug("Add content to dimmer",i),i.parent()[0]!==a[0]&&i.detach().appendTo(a)},create:function(){var e=x(r.template.dimmer());return r.dimmerName&&(g.debug("Creating named dimmer",r.dimmerName),e.addClass(r.dimmerName)),e.appendTo(i),e},show:function(e){e=x.isFunction(e)?e:function(){},g.debug("Showing dimmer",a,r),g.set.variation(),g.is.dimmed()&&!g.is.animating()||!g.is.enabled()?g.debug("Dimmer is already shown or disabled"):(g.animate.show(e),r.onShow.call(u),r.onChange.call(u))},hide:function(e){e=x.isFunction(e)?e:function(){},g.is.dimmed()||g.is.animating()?(g.debug("Hiding dimmer",a),g.animate.hide(e),r.onHide.call(u),r.onChange.call(u)):g.debug("Dimmer is not visible")},toggle:function(){g.verbose("Toggling dimmer visibility",a),g.is.dimmed()?g.hide():g.show()},animate:{show:function(e){e=x.isFunction(e)?e:function(){},r.useCSS&&x.fn.transition!==T&&a.transition("is supported")?(r.useFlex?(g.debug("Using flex dimmer"),g.remove.legacy()):(g.debug("Using legacy non-flex dimmer"),g.set.legacy()),"auto"!==r.opacity&&g.set.opacity(),a.transition({displayType:r.useFlex?"flex":"block",animation:r.transition+" in",queue:!1,duration:g.get.duration(),useFailSafe:!0,onStart:function(){g.set.dimmed()},onComplete:function(){g.set.active(),e()}})):(g.verbose("Showing dimmer animation with javascript"),g.set.dimmed(),"auto"==r.opacity&&(r.opacity=.8),a.stop().css({opacity:0,width:"100%",height:"100%"}).fadeTo(g.get.duration(),r.opacity,function(){a.removeAttr("style"),g.set.active(),e()}))},hide:function(e){e=x.isFunction(e)?e:function(){},r.useCSS&&x.fn.transition!==T&&a.transition("is supported")?(g.verbose("Hiding dimmer with css"),a.transition({displayType:r.useFlex?"flex":"block",animation:r.transition+" out",queue:!1,duration:g.get.duration(),useFailSafe:!0,onStart:function(){g.remove.dimmed()},onComplete:function(){g.remove.variation(),g.remove.active(),e()}})):(g.verbose("Hiding dimmer with javascript"),g.remove.dimmed(),a.stop().fadeOut(g.get.duration(),function(){g.remove.active(),a.removeAttr("style"),e()}))}},get:{dimmer:function(){return a},duration:function(){return"object"==typeof r.duration?g.is.active()?r.duration.hide:r.duration.show:r.duration}},has:{dimmer:function(){return r.dimmerName?0<l.find(n.dimmer).filter("."+r.dimmerName).length:0<l.find(n.dimmer).length}},is:{active:function(){return a.hasClass(t.active)},animating:function(){return a.is(":animated")||a.hasClass(t.animating)},closable:function(){return"auto"==r.closable?"hover"!=r.on:r.closable},dimmer:function(){return l.hasClass(t.dimmer)},dimmable:function(){return l.hasClass(t.dimmable)},dimmed:function(){return i.hasClass(t.dimmed)},disabled:function(){return i.hasClass(t.disabled)},enabled:function(){return!g.is.disabled()},page:function(){return i.is("body")},pageDimmer:function(){return a.hasClass(t.pageDimmer)}},can:{show:function(){return!a.hasClass(t.disabled)}},set:{opacity:function(e){var i=a.css("background-color"),n=i.split(","),t=n&&3==n.length,o=n&&4==n.length;e=0===r.opacity?0:r.opacity||e,i=t||o?(n[3]=e+")",n.join(",")):"rgba(0, 0, 0, "+e+")",g.debug("Setting opacity to",e),a.css("background-color",i)},legacy:function(){a.addClass(t.legacy)},active:function(){a.addClass(t.active)},dimmable:function(){i.addClass(t.dimmable)},dimmed:function(){i.addClass(t.dimmed)},pageDimmer:function(){a.addClass(t.pageDimmer)},disabled:function(){a.addClass(t.disabled)},variation:function(e){(e=e||r.variation)&&a.addClass(e)}},remove:{active:function(){a.removeClass(t.active)},legacy:function(){a.removeClass(t.legacy)},dimmed:function(){i.removeClass(t.dimmed)},disabled:function(){a.removeClass(t.disabled)},variation:function(e){(e=e||r.variation)&&a.removeClass(e)}},setting:function(e,i){if(g.debug("Changing setting",e,i),x.isPlainObject(e))x.extend(!0,r,e);else{if(i===T)return r[e];x.isPlainObject(r[e])?x.extend(!0,r[e],i):r[e]=i}},internal:function(e,i){if(x.isPlainObject(e))x.extend(!0,g,e);else{if(i===T)return g[e];g[e]=i}},debug:function(){!r.silent&&r.debug&&(r.performance?g.performance.log(arguments):(g.debug=Function.prototype.bind.call(console.info,console,r.name+":"),g.debug.apply(console,arguments)))},verbose:function(){!r.silent&&r.verbose&&r.debug&&(r.performance?g.performance.log(arguments):(g.verbose=Function.prototype.bind.call(console.info,console,r.name+":"),g.verbose.apply(console,arguments)))},error:function(){r.silent||(g.error=Function.prototype.bind.call(console.error,console,r.name+":"),g.error.apply(console,arguments))},performance:{log:function(e){var i,n;r.performance&&(n=(i=(new Date).getTime())-(h||i),h=i,y.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:u,"Execution Time":n})),clearTimeout(g.performance.timer),g.performance.timer=setTimeout(g.performance.display,500)},display:function(){var e=r.name+":",n=0;h=!1,clearTimeout(g.performance.timer),x.each(y,function(e,i){n+=i["Execution Time"]}),e+=" "+n+"ms",d&&(e+=" '"+d+"'"),1<v.length&&(e+=" ("+v.length+")"),(console.group!==T||console.table!==T)&&0<y.length&&(console.groupCollapsed(e),console.table?console.table(y):x.each(y,function(e,i){console.log(i.Name+": "+i["Execution Time"]+"ms")}),console.groupEnd()),y=[]}},invoke:function(t,e,i){var o,a,n,r=f;return e=e||S,i=u||i,"string"==typeof t&&r!==T&&(t=t.split(/[\. ]/),o=t.length-1,x.each(t,function(e,i){var n=e!=o?i+t[e+1].charAt(0).toUpperCase()+t[e+1].slice(1):t;if(x.isPlainObject(r[n])&&e!=o)r=r[n];else{if(r[n]!==T)return a=r[n],!1;if(!x.isPlainObject(r[i])||e==o)return r[i]!==T?a=r[i]:g.error(s.method,t),!1;r=r[i]}})),x.isFunction(a)?n=a.apply(i,e):a!==T&&(n=a),x.isArray(b)?b.push(n):b!==T?b=[b,n]:n!==T&&(b=n),a}};g.preinitialize(),w?(f===T&&g.initialize(),g.invoke(C)):(f!==T&&f.invoke("destroy"),g.initialize())}),b!==T?b:this},x.fn.dimmer.settings={name:"Dimmer",namespace:"dimmer",silent:!1,debug:!1,verbose:!1,performance:!0,useFlex:!0,dimmerName:!1,variation:!1,closable:"auto",useCSS:!0,transition:"fade",on:!1,opacity:"auto",duration:{show:500,hide:500},onChange:function(){},onShow:function(){},onHide:function(){},error:{method:"The method you called is not defined."},className:{active:"active",animating:"animating",dimmable:"dimmable",dimmed:"dimmed",dimmer:"dimmer",disabled:"disabled",hide:"hide",legacy:"legacy",pageDimmer:"page",show:"show"},selector:{dimmer:"> .ui.dimmer",content:".ui.dimmer > .content, .ui.dimmer > .content > .center"},template:{dimmer:function(){return x("<div />").attr("class","ui dimmer")}}}}(jQuery,window,document); |