Permalink
Browse files

gallery-2012.04.18-20-14 dhulk gallery-yui-dualslider

  • Loading branch information...
1 parent d8c5be9 commit 8480c5edef97156ae4cbaeab5d7a1618fc27114c YUI Builder committed Apr 18, 2012
Showing with 148 additions and 11 deletions.
  1. +148 −11 src/gallery-yui-dualslider/js/yui-dualslider.js
@@ -1,4 +1,3 @@
-
//Inherit and extend slider to add dual slider
var VALUE = 'value', VALUE2 = 'value2', THUMBSEPARATION = 'thumbSeparation', THUMBSFLIPPED = 'thumbsFlipped';
@@ -53,6 +52,151 @@
contentBox.addClass( this.getClassName( this.axis ) );
},
+
+ /**
+ * increments Slider value by a minor increment
+ *
+ * @method _incrMinor
+ * @protected
+ */
+ _incrMinor : function(thumbToAdjust){
+ this.set(thumbToAdjust, (this.get(thumbToAdjust) + this.get('minorStep')));
+ },
+
+ /**
+ * decrements Slider value by a minor increment
+ *
+ * @method _decrMinor
+ * @protected
+ */
+ _decrMinor : function(thumbToAdjust){
+ this.set(thumbToAdjust, (this.get(thumbToAdjust) - this.get('minorStep')));
+ },
+
+ /**
+ * increments Slider value by a major increment
+ *
+ * @method _incrMajor
+ * @protected
+ */
+ _incrMajor : function(thumbToAdjust){
+ this.set(thumbToAdjust, (this.get(thumbToAdjust) + this.get('majorStep')));
+ },
+
+ /**
+ * decrements Slider value by a major increment
+ *
+ * @method _decrMajor
+ * @protected
+ */
+ _decrMajor : function(thumbToAdjust){
+ this.set(thumbToAdjust, (this.get(thumbToAdjust) - this.get('majorStep')));
+ },
+
+ /**
+ * sets the Slider value to the min value.
+ *
+ * @method _setToMin
+ * @protected
+ */
+ _setToMin : function(thumbToAdjust){
+ this.set(thumbToAdjust, this.get('min'));
+ },
+
+ /**
+ * sets the Slider value to the max value.
+ *
+ * @method _setToMax
+ * @protected
+ */
+ _setToMax : function(thumbToAdjust){
+ this.set(thumbToAdjust, this.get('max'));
+ },
+
+ /**
+ * sets the Slider'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} the key event
+ * @protected
+ */
+ _onDirectionKey : function(e) {
+ e.preventDefault();
+ var targetNode = e.target;
+ var thumbToAdjust = (targetNode === this.thumb ? "value" : "value2");
+ if(this.get('disabled') === false){
+ switch (e.charCode) {
+ case 38: // up
+ this._incrMinor(thumbToAdjust);
+ break;
+ case 40: // down
+ this._decrMinor(thumbToAdjust);
+ break;
+ case 36: // home
+ this._setToMin(thumbToAdjust);
+ break;
+ case 35: // end
+ this._setToMax(thumbToAdjust);
+ break;
+ case 33: // page up
+ this._incrMajor(thumbToAdjust);
+ break;
+ case 34: // page down
+ this._decrMajor(thumbToAdjust);
+ break;
+ }
+ }
+ },
+
+ /**
+ * sets the Slider's value in response to left or right key events
+ *
+ * @method _onLeftRightKey
+ * @param e {Event} the key event
+ * @protected
+ */
+ _onLeftRightKey : function(e) {
+ e.preventDefault();
+ var targetNode = e.target;
+ var thumbToAdjust = (targetNode === this.thumb ? "value" : "value2");
+ if(this.get('disabled') === false){
+ switch (e.charCode) {
+ case 37: // left
+ this._decrMinor(thumbToAdjust);
+ break;
+ case 39: // right
+ this._incrMinor(thumbToAdjust);
+ break;
+ }
+ }
+ },
+
+ /**
+ * sets the Slider's value in response to left or right key events when a meta (mac command/apple) key is also pressed
+ *
+ * @method _onLeftRightKeyMeta
+ * @param e {Event} the key event
+ * @protected
+ */
+ _onLeftRightKeyMeta : function(e) {
+ e.preventDefault();
+ var targetNode = e.target;
+ var thumbToAdjust = (targetNode === this.thumb ? "value" : "value2");
+ if(this.get('disabled') === false){
+ switch (e.charCode) {
+ case 37: // left + meta
+ this._setToMin(thumbToAdjust);
+ break;
+ case 39: // right + meta
+ this._setToMax(thumbToAdjust);
+ break;
+ }
+ }
+ },
+
/**
* Makes the thumb draggable and constrains it to the rail.
*
@@ -177,8 +321,7 @@
railLength = parseInt(this.get('length')),
thumbSize = parseInt(this.thumb.getStyle( this._key.dim ));
- var sepFactor = thumbSep / rangeSize;
- if (sepFactor < 0) sepFactor *= -1;
+ var sepFactor = Math.abs(thumbSep / rangeSize);
if (sepFactor > this._factor)
thumbSep = (railLength - thumbSize) * sepFactor;
@@ -236,7 +379,7 @@
case this._dd2:
if (imagePadding !== null) {
//Padding logic is reversed for the second thumb
- imagePadding *= -1
+ imagePadding = Math.abs(imagePadding);
switch (this.axis) {
case 'x':
this.thumb2.setX(thumbPos + imagePadding);
@@ -410,13 +553,7 @@
thumb2Pos = this.thumb2.getY();
break;
}
- var distToThumb = mousePos - thumbPos , distToThumb2 = mousePos - thumb2Pos;
-
- //Change negative values to positive
- if (distToThumb < 0)
- distToThumb *= -1;
- if (distToThumb2 < 0)
- distToThumb2 *= -1;
+ var distToThumb = Math.abs(mousePos - thumbPos) , distToThumb2 = Math.abs(mousePos - thumb2Pos);
if (distToThumb < distToThumb2)
return this._dd;

0 comments on commit 8480c5e

Please sign in to comment.