dial-min.js revision 691af6c84a00ad5f629ffcfa3b1e42c38da5da4f
YUI.add("dial",function(b){var c=false,d;if(b.UA.ie&&b.UA.ie<9){c=true;}var e=b.Lang,i=b.Widget,f=b.Node;function h(j){h.superclass.constructor.apply(this,arguments);}h.NAME="dial";h.ATTRS={min:{value:-220},max:{value:220},diameter:{value:100},handleDia:{value:0.2},markerDia:{value:0.1},centerButtonDia:{value:0.5},value:{value:0,validator:function(j){return this._validateValue(j);}},minorStep:{value:1},majorStep:{value:10},stepsPerRev:{value:100},decimalPlaces:{value:0},strings:{valueFn:function(){return b.Intl.get("dial");}},handleDist:{value:0.75}};function g(j){return b.ClassNameManager.getClassName(h.NAME,j);}h.CSS_CLASSES={label:g("label"),labelString:g("label-string"),valueString:g("value-string"),northMark:g("north-mark"),ring:g("ring"),ringVml:g("ring-vml"),marker:g("marker"),markerVml:g("marker-vml"),centerButton:g("center-button"),centerButtonVml:g("center-button-vml"),resetString:g("reset-string"),handle:g("handle"),handleVml:g("handle-vml"),hidden:g("hidden"),dragging:b.ClassNameManager.getClassName("dd-dragging")};var a=h.CSS_CLASSES.label+b.guid();h.LABEL_TEMPLATE='<div id="'+a+'" class="'+h.CSS_CLASSES.label+'"><span class="'+h.CSS_CLASSES.labelString+'">{label}</span><span class="'+h.CSS_CLASSES.valueString+'"></span></div>';if(c===false){h.RING_TEMPLATE='<div class="'+h.CSS_CLASSES.ring+'"><div class="'+h.CSS_CLASSES.northMark+'"></div></div>';h.MARKER_TEMPLATE='<div class="'+h.CSS_CLASSES.marker+" "+h.CSS_CLASSES.hidden+'"></div>';h.CENTER_BUTTON_TEMPLATE='<div class="'+h.CSS_CLASSES.centerButton+'"><div class="'+h.CSS_CLASSES.resetString+" "+h.CSS_CLASSES.hidden+'">{resetStr}</div></div>';h.HANDLE_TEMPLATE='<div class="'+h.CSS_CLASSES.handle+'" aria-labelledby="'+a+'" aria-valuetext="" aria-valuemax="" aria-valuemin="" aria-valuenow="" role="slider" tabindex="0" title="{tooltipHandle}">';}else{h.RING_TEMPLATE='<div class="'+h.CSS_CLASSES.ring+" "+h.CSS_CLASSES.ringVml+'">'+'<div class="'+h.CSS_CLASSES.northMark+'"></div>'+'<v:oval strokecolor="#ceccc0" strokeweight="1px"><v:fill type=gradient color="#8B8A7F" color2="#EDEDEB" angle="45"/></v:oval>'+"</div>"+"";h.MARKER_TEMPLATE='<div class="'+h.CSS_CLASSES.markerVml+" "+h.CSS_CLASSES.hidden+'">'+'<v:oval stroked="false">'+'<v:fill opacity="20%" color="#000"/>'+"</v:oval>"+"</div>"+"";h.CENTER_BUTTON_TEMPLATE='<div class="'+h.CSS_CLASSES.centerButton+" "+h.CSS_CLASSES.centerButtonVml+'">'+'<v:oval strokecolor="#ceccc0" strokeweight="1px">'+'<v:fill type=gradient color="#C7C5B9" color2="#fefcf6" colors="35% #d9d7cb, 65% #fefcf6" angle="45"/>'+'<v:shadow on="True" color="#000" opacity="10%" offset="2px, 2px"/>'+"</v:oval>"+'<div class="'+h.CSS_CLASSES.resetString+" "+h.CSS_CLASSES.hidden+'">{resetStr}</div>'+"</div>"+"";h.HANDLE_TEMPLATE='<div class="'+h.CSS_CLASSES.handleVml+'" aria-labelledby="'+a+'" aria-valuetext="" aria-valuemax="" aria-valuemin="" aria-valuenow="" role="slider" tabindex="0" title="{tooltipHandle}">'+'<v:oval stroked="false">'+'<v:fill opacity="20%" color="#6C3A3A"/>'+"</v:oval>"+"</div>"+"";}b.extend(h,i,{renderUI:function(){this._renderLabel();this._renderRing();this._renderMarker();this._renderCenterButton();this._renderHandle();this.contentBox=this.get("contentBox");this._originalValue=this.get("value");this._timesWrapped=0;this._angle=this._getAngleFromValue(this.get("value"));this._prevAng=this._angle;this._setTimesWrappedFromValue(this._originalValue);this._handleNode.set("aria-valuemin",this.get("min"));this._handleNode.set("aria-valuemax",this.get("max"));},_setBorderRadius:function(){this._ringNode.setStyles({"WebkitBorderRadius":this._ringNodeRadius+"px","MozBorderRadius":this._ringNodeRadius+"px","borderRadius":this._ringNodeRadius+"px"});this._handleNode.setStyles({"WebkitBorderRadius":this._handleNodeRadius+"px","MozBorderRadius":this._handleNodeRadius+"px","borderRadius":this._handleNodeRadius+"px"});this._markerNode.setStyles({"WebkitBorderRadius":this._markerNodeRadius+"px","MozBorderRadius":this._markerNodeRadius+"px","borderRadius":this._markerNodeRadius+"px"});this._centerButtonNode.setStyles({"WebkitBorderRadius":this._centerButtonNodeRadius+"px","MozBorderRadius":this._centerButtonNodeRadius+"px","borderRadius":this._centerButtonNodeRadius+"px"});},bindUI:function(){this.after("valueChange",this._afterValueChange);var k=this.get("boundingBox"),l=(!b.UA.opera)?"down:":"press:",m=(!b.UA.opera)?"down:":"press:";l+="38, 40, 33, 34, 35, 36";m+="37, 39";b.on("key",b.bind(this._onDirectionKey,this),k,l);b.on("key",b.bind(this._onLeftRightKey,this),k,m);b.on("mouseenter",function(){this.one("."+h.CSS_CLASSES.resetString).removeClass(h.CSS_CLASSES.hidden);},this._centerButtonNode);b.on("mouseleave",function(){this.one("."+h.CSS_CLASSES.resetString).addClass(h.CSS_CLASSES.hidden);},this._centerButtonNode);b.on("click",b.bind(this._resetDial,this),this._centerButtonNode);b.on("mousedown",b.bind(function(){this._handleNode.focus();},this),this._handleNode);var j=new b.DD.Drag({node:this._handleNode,on:{"drag:drag":b.bind(this._handleDrag,this),"drag:start":b.bind(this._handleDragStart,this),"drag:end":b.bind(this._handleDragEnd,this)}});},_setTimesWrappedFromValue:function(j){if(j%this.get("stepsPerRev")===0){this._timesWrapped=(j/this.get("stepsPerRev"));}else{this._timesWrapped=Math.floor(j/this.get("stepsPerRev"));}},_handleDrag:function(m){var o=(m.pageX+this._handleNodeRadius),n=(m.pageY+this._handleNodeRadius);var k=Math.atan((this._centerYOnPage-n)/(this._centerXOnPage-o))*(180/Math.PI),j=(this._centerXOnPage-o);k=((this._centerXOnPage-o)<0)?k+90:k+90+180;if((this._prevAng>270)&&(k<90)){this._timesWrapped=(this._timesWrapped+1);}else{if((this._prevAng<90)&&(k>270)){this._timesWrapped=(this._timesWrapped-1);}}this._prevAng=k;var l=this._getValueFromAngle(k);if((l>this.get("min"))&&(l<this.get("max"))){this.set("value",l);}else{if(l>this.get("max")){this.set("value",this.get("max"));}else{if(l<this.get("min")){this.set("value",this.get("min"));}}}},_handleDragStart:function(j){this._markerNode.removeClass(h.CSS_CLASSES.hidden);
this._centerYOnPage=(this._ringNode.getY()+this._ringNodeRadius);this._centerXOnPage=(this._ringNode.getX()+this._ringNodeRadius);},_handleDragEnd:function(){var j=this._handleNode;j.transition({duration:0.08,easing:"ease-in",left:this._setNodeToFixedRadius(this._handleNode,true)[0]+"px",top:this._setNodeToFixedRadius(this._handleNode,true)[1]+"px"},b.bind(function(){this._markerNode.addClass(h.CSS_CLASSES.hidden);},this));},_setNodeToFixedRadius:function(m,p){var k=(this._angle-90),j=(Math.PI/180),l=Math.round(Math.sin(k*j)*this._handleDist),o=Math.round(Math.cos(k*j)*this._handleDist),n=m.get("offsetWidth");l=l-(n*0.5);o=o-(n*0.5);if(p){return[(this._ringNodeRadius+o),(this._ringNodeRadius+l)];}else{m.setStyle("left",(this._ringNodeRadius+o)+"px");m.setStyle("top",(this._ringNodeRadius+l)+"px");}},syncUI:function(){this._setSizes();this._setBorderRadius();this._uiSetValue(this.get("value"));},_setSizes:function(){var m=this.get("diameter");var l=function(p,r,o){var q="px";p.getElementsByTagName("oval").setStyle("width",(r*o)+q);p.getElementsByTagName("oval").setStyle("height",(r*o)+q);p.setStyle("width",(r*o)+q);p.setStyle("height",(r*o)+q);};l(this._ringNode,m,1);l(this._handleNode,m,this.get("handleDia"));l(this._markerNode,m,this.get("markerDia"));l(this._centerButtonNode,m,this.get("centerButtonDia"));this._ringNodeRadius=this._ringNode.get("offsetWidth")*0.5;this._handleNodeRadius=this._handleNode.get("offsetWidth")*0.5;this._markerNodeRadius=this._markerNode.get("offsetWidth")*0.5;this._centerButtonNodeRadius=this._centerButtonNode.get("offsetWidth")*0.5;this._handleDist=this._ringNodeRadius*this.get("handleDist");var k=(this._ringNodeRadius-this._centerButtonNodeRadius);this._centerButtonNode.setStyle("left",k+"px");this._centerButtonNode.setStyle("top",k+"px");var n=(this._centerButtonNodeRadius-(this._resetString.get("offsetWidth")*0.5));var j=(this._centerButtonNodeRadius-(this._resetString.get("offsetHeight")*0.5));this._resetString.setStyles({"left":n+"px","top":j+"px"});},_renderLabel:function(){var j=this.get("contentBox"),k=j.one("."+h.CSS_CLASSES.label);if(!k){k=f.create(b.substitute(h.LABEL_TEMPLATE,this.get("strings")));j.append(k);}this._labelNode=k;this._valueStringNode=this._labelNode.one("."+h.CSS_CLASSES.valueString);},_renderRing:function(){var j=this.get("contentBox"),k=j.one("."+h.CSS_CLASSES.ring);if(!k){k=j.appendChild(h.RING_TEMPLATE);k.setStyles({width:this.get("diameter")+"px",height:this.get("diameter")+"px"});}this._ringNode=k;},_renderMarker:function(){var k=this.get("contentBox"),j=k.one("."+h.CSS_CLASSES.marker);if(!j){j=k.one("."+h.CSS_CLASSES.ring).appendChild(h.MARKER_TEMPLATE);}this._markerNode=j;},_renderCenterButton:function(){var j=this.get("contentBox"),k=j.one("."+h.CSS_CLASSES.centerButton);if(!k){k=f.create(b.substitute(h.CENTER_BUTTON_TEMPLATE,this.get("strings")));j.one("."+h.CSS_CLASSES.ring).append(k);}this._centerButtonNode=k;this._resetString=this._centerButtonNode.one("."+h.CSS_CLASSES.resetString);},_renderHandle:function(){var j=this.get("contentBox"),k=j.one("."+h.CSS_CLASSES.handle);if(!k){k=f.create(b.substitute(h.HANDLE_TEMPLATE,this.get("strings")));j.one("."+h.CSS_CLASSES.ring).append(k);}this._handleNode=k;},_setLabelString:function(j){this.get("contentBox").one("."+h.CSS_CLASSES.labelString).setContent(j);},_setResetString:function(j){this.get("contentBox").one("."+h.CSS_CLASSES.resetString).setContent(j);},_setTooltipString:function(j){this._handleNode.set("title",j);},_onDirectionKey:function(j){j.preventDefault();switch(j.charCode){case 38:this._incrMinor();break;case 40:this._decrMinor();break;case 36:this._resetDial();break;case 35:this._setToMax();break;case 33:this._incrMajor();break;case 34:this._decrMajor();break;}},_onLeftRightKey:function(j){j.preventDefault();switch(j.charCode){case 37:this._decrMinor();break;case 39:this._incrMinor();break;}},_incrMinor:function(){var j=(this.get("value")+this.get("minorStep"));j=Math.min(j,this.get("max"));this.set("value",j.toFixed(this.get("decimalPlaces"))-0);},_decrMinor:function(){var j=(this.get("value")-this.get("minorStep"));j=Math.max(j,this.get("min"));this.set("value",j.toFixed(this.get("decimalPlaces"))-0);},_incrMajor:function(){var j=(this.get("value")+this.get("majorStep"));j=Math.min(j,this.get("max"));this.set("value",j.toFixed(this.get("decimalPlaces"))-0);},_decrMajor:function(){var j=(this.get("value")-this.get("majorStep"));j=Math.max(j,this.get("min"));this.set("value",j.toFixed(this.get("decimalPlaces"))-0);},_setToMax:function(){this.set("value",this.get("max"));},_setToMin:function(){this.set("value",this.get("min"));},_resetDial:function(){this.set("value",this._originalValue);this._handleNode.focus();},_getAngleFromValue:function(j){var l=j%this.get("stepsPerRev");var k=l/this.get("stepsPerRev")*360;return k;},_getValueFromAngle:function(k){if(k<0){k=(360+k);}else{if(k===0){k=360;}}var j=(k/360)*this.get("stepsPerRev");j=(j+(this._timesWrapped*this.get("stepsPerRev")));return j.toFixed(this.get("decimalPlaces"))-0;},_afterValueChange:function(j){this._uiSetValue(j.newVal);},_uiSetValue:function(j){this._angle=this._getAngleFromValue(j);if(this._handleNode.hasClass(h.CSS_CLASSES.dragging)===false){this._setTimesWrappedFromValue(j);this._setNodeToFixedRadius(this._handleNode,false);this._prevAng=this._getAngleFromValue(this.get("value"));}this._valueStringNode.setContent(j);this._handleNode.set("aria-valuenow",j);this._handleNode.set("aria-valuetext",j);this._setNodeToFixedRadius(this._markerNode,false);if((j===this.get("max"))||(j===this.get("min"))){if(this._markerNode.hasClass("marker-max-min")===false){this._markerNode.addClass("marker-max-min");if(c===true){this._markerNode.getElementsByTagName("fill").set("color","#AB3232");}}}else{if(c===true){this._markerNode.getElementsByTagName("fill").set("color","#000");}if(this._markerNode.hasClass("marker-max-min")===true){this._markerNode.removeClass("marker-max-min");}}},_validateValue:function(l){var k=this.get("min"),j=this.get("max");