Dial.js revision 59927fc7ef43db5ef49fce3811b307e2f0a4267c
/**
* Create a circular dial value range input visualized as a draggable handle on a
* background element.
*
* @module dial
*/
var supportsVML = false;
'v', // vml namespace
'urn:schemas-microsoft-com:vml',
'#default#VML' // required for IE8
);
supportsVML = true;
}
}
/**
* Create a dial to represent an input control capable of representing a
* series of intermediate states based on the position of the Dial's handle.
* These states are typically aligned to a value algorithm whereby the angle of the handle's
* position corresponds to a given value.
*
* @class Dial
* @extends Widget
* @param config {Object} Configuration object
* @constructor
*/
}
// static properties
/**
* The identity of the widget.
*
* @property Dial.NAME
* @type String
* @default 'dial'
* @readOnly
* @protected
* @static
*/
/**
* Static property used to define the default attribute configuration of
* the Widget.
*
* @property Dial.ATTRS
* @type {Object}
* @protected
* @static
*/
/**
* minimum value allowed
*
* @attribute min
* @type {Number}
* @default -220
*/
min : {
value:-220
},
/**
* maximum value allowed
*
* @attribute max
* @type {Number}
* @default 220
*/
max : {
value:220
},
/**
* diameter of the circular background object
* other objects scale accordingly
*
* @attribute diameter
* @type {Number} the number of px in diameter
* @default 100
*/
diameter : {
value:100
},
/**
* initial value of the Dial
*
* @attribute value
* @type {Number}
* @default 0
*/
value : {
value:0,
return this._validateValue(val);
}
},
/**
*
* @attribute minorStep
* @type {Number}
* @default 1
*/
minorStep : {
value:1
},
/**
*
* @attribute majorStep
* @type {Number}
* @default 10
*/
majorStep : {
value:10
},
/**
* number of value increments in one 360 degree revolution
* of the handle around the dial
*
* @attribute stepsPerRev
* @type {Number}
* @default 100
*/
stepsPerRev : {
value:100
},
/**
* number of decimal places of accuracy in the value
*
* @attribute decimalPlaces
* @type {Number}
* @default 0
*/
decimalPlaces : {
value:0
},
/**
* visible strings for the dial UI. This attribute is
* defined by the base Widget class but has an empty value. The
* Dial is simply providing a default value for the attribute.
* Gets localized strings in the current language
*
* @attribute strings
* @type {Object}
* @default {label: 'My label', resetStr: 'Reset', tooltipHandle: 'Drag to set value'}
*/
strings: {
// valueFn: function () {
// return Y.Intl.get('autocomplete-list');
// }
// value: Y.Intl.get('dial')
resetStr: 'Reset',
tooltipHandle: 'Drag to set value'
}
},
/**
* distance from the center of the dial to the
* resting place of the center of the handle and marker.
* The value is a percent of the radius of the dial.
*
* @attribute handleDist
* @type {number}
* @default 0.75
*/
value:0.75
}
};
/**
* returns a properly formed yui class name
*
* @function
* @param {String} string to be appended at the end of class name
* @return
* @private
*/
function makeClassName(str) {
}
/**
* array of static constants used to identify the classname applied to the Dial DOM objects
*
* @property Dial.CSS_CLASSES
* @type {Array}
* @private
* @static
*/
Dial.CSS_CLASSES = {
};
/* Static constants used to define the markup templates used to create Dial DOM elements */
/**
* template that will contain the Dial's label.
*
* @property Dial.LABEL_TEMPLATE
* @type {String}
* @default <div>...</div>
* @private
*/
Dial.LABEL_TEMPLATE = '<div id="' + labelId + '" class="' + Dial.CSS_CLASSES.label + '"><span class="' + Dial.CSS_CLASSES.labelString + '">{label}</span><span class="' + Dial.CSS_CLASSES.valueString + '"></span></div>';
if(supportsVML === false){
/**
* template that will contain the Dial's background ring.
*
* @property Dial.RING_TEMPLATE
* @type {String}
* @default <div class="[...-ring]"><div class="[...-northMark]"></div></div>
* @private
*/
Dial.RING_TEMPLATE = '<div class="' + Dial.CSS_CLASSES.ring + '"><div class="' + Dial.CSS_CLASSES.northMark + '"></div></div>';
/**
* template that will contain the Dial's current angle marker.
*
* @property Dial.MARKER_TEMPLATE
* @type {String}
* @default <div class="[...-marker] marker-hidden"><div class="[...-markerUser]"></div></div>
* @private
*/
Dial.MARKER_TEMPLATE = '<div class="' + Dial.CSS_CLASSES.marker + ' marker-hidden"><div class="' + Dial.CSS_CLASSES.markerUser + '"></div></div>';
/**
* template that will contain the Dial's center button.
*
* @property Dial.CENTER_BUTTON_TEMPLATE
* @type {String}
* @default <div class="[...-centerButton]"><div class="[...-resetString]">' + Y.substitute('{resetStr}', Dial.ATTRS.strings.value) + '</div></div>
* @private
*/
Dial.CENTER_BUTTON_TEMPLATE = '<div class="' + Dial.CSS_CLASSES.centerButton + '"><div class="' + Dial.CSS_CLASSES.resetString + '">{resetStr}</div></div>';
/**
* template that will contain the Dial's handle.
*
* @property Dial.HANDLE_TEMPLATE
* @type {String}
* @default <div class="[...-handle]"><div class="[...-handleUser]" aria-labelledby="' + labelId + '" aria-valuetext="" aria-valuemax="" aria-valuemin="" aria-valuenow="" role="slider" tabindex="0"></div></div>';// title="{tooltipHandle}"
* @private
*/
Dial.HANDLE_TEMPLATE = '<div class="' + Dial.CSS_CLASSES.handle + '"><div class="' + Dial.CSS_CLASSES.handleUser + '" aria-labelledby="' + labelId + '" aria-valuetext="" aria-valuemax="" aria-valuemin="" aria-valuenow="" role="slider" tabindex="0" title="{tooltipHandle}"></div></div>';// title="{tooltipHandle}"
}else{ // VML case
'<v:oval strokecolor="#ceccc0" strokeweight="1px" class="' + Dial.CSS_CLASSES.ringVml + '"><v:fill type=gradient color="#8B8A7F" color2="#EDEDEB" angle="45"/></v:oval>'+
'<v:oval></v:oval>'+
'</div>'+
'';
'<v:fill opacity="20%" color="#000"/>'+
'</v:oval>'+
'<v:oval></v:oval>'+
'</div>'+
'';
'<v:oval strokecolor="#ceccc0" strokeweight="1px" class="' + Dial.CSS_CLASSES.centerButtonVml + '">'+
'<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>'+
'<v:oval></v:oval>'+
'</div>'+
'';
' aria-labelledby="' + labelId + '" aria-valuetext="" aria-valuemax="" aria-valuemin="" aria-valuenow="" role="slider" tabindex="0" title="{tooltipHandle}">'+ //title="{tooltipHandle}"
'<v:fill opacity="20%" color="#6C3A3A"/>'+
'</v:oval>'+
'<v:oval></v:oval>'+
'</div>'+
'';
}
/* Dial extends the base Widget class */
/**
* creates the DOM structure for the Dial.
*
* @method renderUI
* @private
*/
renderUI : function() {
this._renderLabel();
this._renderRing();
this._renderMarker();
this._renderCenterButton();
this._renderHandle();
// object handles
// constants
// variables
this._timesWrapped = 0;
// init
},
/**
* Creates the Y.DD.Drag instance used for the handle movement and
* binds Dial interaction to the configured value model.
*
* @method bindUI
* @private
*/
bindUI : function() {
// Looking for a key event which will fire continously across browsers while the key is held down.
keyEventSpec += "38, 40, 33, 34, 35, 36";
keyLeftRightSpec += "37, 39";
node: this._handleNode,
on : {
}
});
},
/**
* Sets _timesWrapped based on Dial value
* to net integer revolutions the user dragged the handle around the Dial
*
* @method _setTimesWrapedFromValue
* @param val {Number} current value of the Dial
* @private
*/
_setTimesWrapedFromValue : function(val){
}else{
}
},
/**
* Sets the string in the object the user clicks to reset the Dial value
*
* @method _dialCenterOver
* @private
*/
_dialCenterOver : function(e){
},
/**
* Sets the string in the object the user clicks to reset the Dial value
*
* @method _dialCenterOut
* @private
*/
_dialCenterOut : function(e){
},
/**
* handles the user dragging the handle around the Dial, calculates the angle,
* checks for wrapping around top center, handles exceeding min or max values
*
* @method _handleDrag
* @private
*/
_handleDrag : function(e){
var ang = Math.atan( (this._centerYOnPage - e.pageY) / (this._centerXOnPage - e.pageX) ) * (180 / Math.PI),
if(deltaX < 0){
}else{
}
// check for need to set timesWrapped
if((this._prevX <= this._centerXOnPage) && (e.pageX > this._centerXOnPage)){ // If wrapping, clockwise
}else if((this._prevX > this._centerXOnPage) && (e.pageX <= this._centerXOnPage)){ // if un-wrapping, counter-clockwise
}
}
// handle hitting max and min and going beyond, stops at max or min
//if((newValue > this.get('min')) && (newValue < this.get('max'))) {
}
},
/**
* handles the user starting to drag the handle around the Dial
*
* @method _handleDragStart
* @private
*/
_handleDragStart : function(e){
if(!this._prevX){
}
},
/*
* When handle is handleDragEnd, this animates the return to the fixed dial
*/
/**
* handles the end of a user dragging the handle, animates the handle returning to
* resting position.
*
* @method _handleDragEnd
* @private
*/
_handleDragEnd : function(){
var node = this._handleNode;
easing: 'ease-in',
}, Y.bind(function(){
}, this)
);
},
/**
* returns the XY of the fixed position, handleDist, from the center of the Dial (resting position)
* The XY also represents the angle related to the current value
* If no param is passed, [X,Y] is returned.
* If param is passed, the XY of the node passed is set.
*
* @method _setNodeToFixedRadius
* @param obj {Node}
* @private
* @return {Array} an array of [XY] is optionally returned
*/
_setNodeToFixedRadius : function(obj){
if(obj){
obj.setXY([(this._ringNode.getX() + this._centerX + newX), (this._ringNode.getY() + this._centerY + newY)]);
}else{ // just need the style for css transform left and top to animate the handle drag:end
}
},
/**
* Synchronizes the DOM state with the attribute settings.
*
* @method syncUI
* @private
*/
syncUI : function() {
},
/**
* renders the DOM object for the Dial's label
*
* @method _renderLabel
* @private
*/
_renderLabel : function() {
if (!label) {
}
this._labelNode = label;
},
/**
* renders the DOM object for the Dial's background ring
*
* @method _renderRing
* @private
*/
_renderRing : function() {
if (!ring) {
}
},
/**
* renders the DOM object for the Dial's background marker which
* tracks the angle of the user dragging the handle
*
* @method _renderMarker
* @private
*/
_renderMarker : function() {
if (!marker) {
}
this._markerNode = marker;
},
/**
* places the centerbutton's reset string in the center of the button
* based on the size of the string object
*
* @method _setXYResetString
* @private
*/
_setXYResetString : function(){
this._resetString.setStyle('top', (this._centerButtonNode.get('region').height / 2) - (this._resetString.get('region').height / 2) + 'px');
this._resetString.setStyle('left', (this._centerButtonNode.get('region').width / 2) - (this._resetString.get('region').width / 2) + 'px');
},
/**
* renders the DOM object for the Dial's center
*
* @method _renderCenterButton
* @private
*/
_renderCenterButton : function() {
if (!centerButton) {
}
this._centerButtonNode = centerButton;
this._setXYResetString(); // centering the reset string in the button
//var offset = (this._ringNode.get('region').width - this._centerButtonNode.get('region').width) / 2;
},
/**
* renders the DOM object for the Dial's user draggable handle
*
* @method _renderHandle
* @private
*/
_renderHandle : function() {
if (!handle) {
}
this._handleNode = handle;
},
/**
* sets the visible UI label string
*
* @method setLabelString
* @param str {String}
* @private
*/
setLabelString : function(str) {
},
/**
* sets the visible UI label string
*
* @method setResetString
* @param str {String}
* @private
*/
setResetString : function(str) {
this._setXYResetString(); // recenters the string in the button
},
/**
* sets the tooltip string in the Dial's handle
*
* @method setTooltipString
* @param str {String}
* @private
*/
setTooltipString : function(str) {
},
/**
* sets the Dial's value in response to key events.
* Left and right keys are in a separate method
* in case an implementation wants to increment values
* but needs left and right arrow keys for other purposes.
*
* @method _onDirectionKey
* @param e {Event}
* @private
*/
_onDirectionKey : function(e) {
e.preventDefault();
switch (e.charCode) {
case 38: // up
this._incrMinor();
break;
case 40: // down
this._decrMinor();
break;
case 36: // home
this._resetDial();
break;
case 35: // end
this._setToMax();
break;
case 33: // page up
this._incrMajor();
break;
case 34: // page down
this._decrMajor();
break;
}
},
/**
* sets the Dial's value in response to left or right key events
*
* @method _onLeftRightKey
* @param e {Event}
* @private
*/
_onLeftRightKey : function(e) {
e.preventDefault();
switch (e.charCode) {
case 37: // left
this._decrMinor();
break;
case 39: // right
this._incrMinor();
break;
}
},
/**
* increments Dial value by a minor increment
*
* @method _incrMinor
* @private
*/
_incrMinor : function(){
},
/**
* decrements Dial value by a minor increment
*
* @method _decrMinor
* @private
*/
_decrMinor : function(){
},
/**
* increments Dial value by a major increment
*
* @method _incrMajor
* @private
*/
_incrMajor : function(){
},
/**
* decrements Dial value by a major increment
*
* @method _decrMajor
* @private
*/
_decrMajor : function(){
},
/**
* sets Dial value to dial's max attr
*
* @method _decrMajor
* @private
*/
_setToMax : function(){
},
/**
* sets Dial value to dial's min attr
*
* @method _decrMajor
* @private
*/
_setToMin : function(){
},
/**
* resets Dial value to the orignal initial value.
*
* @method _resetDial
* @private
*/
_resetDial : function(){
this._handleUserNode.focus();
},
/**
* returns the handle angle associated with the current value of the Dial
*
* @method _getAngleFromValue
* @param newVal {Number} the current value of the Dial
* @return {Number} the angle associated with the current Dial value
*/
_getAngleFromValue : function(newVal){
return angleFromValue;
},
/**
* returns the value of the Dial calculated from the current handle angle
*
* @method _getValueFromAngle
* @param angle {Number} the current angle of the Dial's handle
* @return {Number} the current Dial value corresponding to the handle position
*/
_getValueFromAngle : function(angle){
if(angle < 0){
}else if(angle === 0){
angle = 360;
}
//return Math.round(value * 100) / 100;
},
/**
* calls the method to update the UI whenever the Dial value changes
*
* @method _afterValueChange
* @param e {Event}
* @private
*/
_afterValueChange : function(e) {
this._uiSetValue(e.newVal);
},
/**
* Updates the UI display value of the Dial to reflect
* the value passed in.
* Makes all other needed UI display changes
*
* @method _uiSetValue
* @param val {Number} value of the Dial
* @protected
*/
_uiSetValue : function(val) {
this._setTimesWrapedFromValue(val);
this._setNodeToFixedRadius(this._handleNode);
}
this._setNodeToFixedRadius(this._markerNode);
if(supportsVML === true){
}
}
}else{
if(supportsVML === true){
}
}
}
},
/**
* value attribute default validator. Verifies that
*
* @method _validateValue
* @param val {Number} value of the Dial
* @private
*/
_validateValue: function(val) {
}
});