mirror of
https://github.com/humhub/humhub.git
synced 2025-02-20 08:05:23 +01:00
1 line
6.0 KiB
JavaScript
1 line
6.0 KiB
JavaScript
|
$(function(){var Dial=function(c,opt){var v=null,ctx=c[0].getContext("2d"),PI2=2*Math.PI,mx,my,x,y,self=this;this.onChange=function(){};this.onCancel=function(){};this.onRelease=function(){};this.val=function(nv){if(null!=nv){opt.stopper&&(nv=Math.max(Math.min(nv,opt.max),opt.min));v=nv;this.onChange(nv);this.draw(nv)}else{var b,a;b=a=Math.atan2(mx-x,-(my-y-opt.width/2))-opt.angleOffset;(a<0)&&(b=a+PI2);nv=Math.round(b*(opt.max-opt.min)/PI2)+opt.min;return(nv>opt.max)?opt.max:nv}};this.change=function(nv){opt.stopper&&(nv=Math.max(Math.min(nv,opt.max),opt.min));this.onChange(nv);this.draw(nv)};this.angle=function(nv){return(nv-opt.min)*PI2/(opt.max-opt.min)};this.draw=function(nv){var a=this.angle(nv),sa=1.5*Math.PI+opt.angleOffset,sat=sa,ea=sa+this.angle(v),eat=sat+a,r=opt.width/2,lw=r*opt.thickness,cgcolor=Dial.getCgColor(opt.cgColor),tick;ctx.clearRect(0,0,opt.width,opt.width);ctx.lineWidth=lw;if(opt.draw(a,v,opt,ctx)){return}for(tick=0;tick<opt.ticks;tick++){ctx.beginPath();if(a>(((2*Math.PI)/opt.ticks)*tick)&&opt.tickColorizeValues){ctx.strokeStyle=opt.fgColor}else{ctx.strokeStyle=opt.tickColor}var tick_sa=(((2*Math.PI)/opt.ticks)*tick)-(0.5*Math.PI);ctx.arc(r,r,r-lw-opt.tickLength,tick_sa,tick_sa+opt.tickWidth,false);ctx.stroke()}opt.cursor&&(sa=ea-0.3)&&(ea=ea+0.3)&&(sat=eat-0.3)&&(eat=eat+0.3);switch(opt.skin){case"default":ctx.beginPath();ctx.strokeStyle=opt.bgColor;ctx.arc(r,r,r-lw/2,0,PI2,true);ctx.stroke();if(opt.displayPrevious){ctx.beginPath();ctx.strokeStyle=(v==nv)?opt.fgColor:cgcolor;ctx.arc(r,r,r-lw/2,sa,ea,false);ctx.stroke()}ctx.beginPath();ctx.strokeStyle=opt.fgColor;ctx.arc(r,r,r-lw/2,sat,eat,false);ctx.stroke();break;case"tron":if(opt.displayPrevious){ctx.beginPath();ctx.strokeStyle=(v==nv)?opt.fgColor:cgcolor;ctx.arc(r,r,r-lw,sa,ea,false);ctx.stroke()}ctx.beginPath();ctx.strokeStyle=opt.fgColor;ctx.arc(r,r,r-lw,sat,eat,false);ctx.stroke();ctx.lineWidth=2;ctx.beginPath();ctx.strokeStyle=opt.fgColor;ctx.arc(r,r,r-lw+1+lw*2/3,0,2*Math.PI,false);ctx.stroke();break}};this.capture=function(e){switch(e.type){case"mousemove":case"mousedown":mx=e.pageX;my=e.pageY;break;case"touchmove":case"touchstart":mx=e.originalEvent.touches[0].pageX;my=e.originalEvent.touches[0].pageY;break}this.change(this.val())};this.cancel=function(){self.val(v);self.onCancel()};this.startDrag=function(e){var p=c.offset(),$doc=$(document);x=p.left+(opt.width/2);y=p.top;this.capture(e);$doc.bind("mousemove.dial touchmove.dial",function(e){self.capture(e)}).bind("keyup.dial",function(e){if(e.keyCode===27){$doc.unbind("mouseup.dial mousemove.dial keyup.dial");self.cancel()}}).bind("mouseup.dial touchend.dial",function(e){$doc.unbind("mousemove.dial touchmove.dial mouseup.dial touchend.dial keyup.dial");self.val(self.val());self.onRelease(v)})}};Dial.getCgColor=function(h){h=h.substring(1,7);var rgb=[parseInt(h.substring(0,2),16),parseInt(h.substring(2,4),16),parseInt(h.substring(4,6),16)];return"rgba("+rgb[0]+","+rgb[1]+","+rgb[2]+",.5)"};$.fn.knob=$.fn.dial=function(gopt){return this.each(function(){var $this=$(this),opt;if($this.data("dialed")){return $this}$this.data("dialed",true);opt=$.extend({min:$this.data("min")||0,max:$this.data("max")||100,stopper:true,readOnly:$this.data("readonly"),cursor:$this.data("cursor"),thickness:$this.data("thickness")||0.35,width:$this.data("width")||200,displayInput:$this.data("displayinput")==null||$this.data("displayinput"),displayPrevious:$this.data("displayprevious"),fgColor:$this.data("fgcolor")||"#87CEEB",cgColor:$this.data("cgcolor")||$this.data("fgcolor")||"#87CEEB",bgColor:$this.data("bgcolor")||"#EEEEEE",tickColor:$this.data("tickColor")||$this.data("fgcolor")||"#DDDDDD",ticks:$this.data("ticks")||0,tickLength:$this.data("tickLength")||0,tickWidth:$this.data("tickWidth")||0.02,tickColorizeValues:$this.data("tickColorizeValues")||true,skin:$this.data("skin")||"default",angleOffset:degreeToRadians($this.data("angleoffset")),draw:function(a,v,opt,ctx){},change:function(v){},release:function(v,ipt){}},gopt);var c=$('<canvas width="'+opt.width+'" height="'+opt.width+'"></canvas>'),wd=$("<div
|