Commit dbab13de authored by Valentin Hervieu's avatar Valentin Hervieu

test(mouse events): Finish events tests for draggableRange

parent 256cdc76
/*! angularjs-slider - v2.3.0 - /*! angularjs-slider - v2.3.0 -
(c) Rafal Zajac <rzajac@gmail.com>, Valentin Hervieu <valentin@hervieu.me>, Jussi Saarivirta <jusasi@gmail.com>, Angelin Sirbu <angelin.sirbu@gmail.com> - (c) Rafal Zajac <rzajac@gmail.com>, Valentin Hervieu <valentin@hervieu.me>, Jussi Saarivirta <jusasi@gmail.com>, Angelin Sirbu <angelin.sirbu@gmail.com> -
https://github.com/angular-slider/angularjs-slider - https://github.com/angular-slider/angularjs-slider -
2015-12-24 */ 2015-12-29 */
/*jslint unparam: true */ /*jslint unparam: true */
/*global angular: false, console: false, define, module */ /*global angular: false, console: false, define, module */
(function(root, factory) { (function(root, factory) {
...@@ -166,8 +166,8 @@ ...@@ -166,8 +166,8 @@
value: 0, value: 0,
difference: 0, difference: 0,
offset: 0, offset: 0,
lowDist: 0, lowLimit: 0,
highDist: 0 highLimit: 0
}; };
/** /**
...@@ -287,10 +287,10 @@ ...@@ -287,10 +287,10 @@
this.applyOptions(); this.applyOptions();
this.initElemHandles(); this.initElemHandles();
this.manageElementsStyle(); this.manageElementsStyle();
this.addAccessibility();
this.setDisabledState(); this.setDisabledState();
this.calcViewDimensions(); this.calcViewDimensions();
this.setMinAndMax(); this.setMinAndMax();
this.addAccessibility();
$timeout(function() { $timeout(function() {
self.updateCeilLab(); self.updateCeilLab();
...@@ -461,7 +461,6 @@ ...@@ -461,7 +461,6 @@
break; break;
case 1: case 1:
this.selBar = jElem; this.selBar = jElem;
this.selBarChild = this.selBar.children('rz-selection');
break; break;
case 2: case 2:
this.minH = jElem; this.minH = jElem;
...@@ -839,33 +838,14 @@ ...@@ -839,33 +838,14 @@
* @param {number} newOffset * @param {number} newOffset
*/ */
updateHandles: function(which, newOffset) { updateHandles: function(which, newOffset) {
if (which === 'rzSliderModel') { if (which === 'rzSliderModel')
this.updateLowHandle(newOffset); this.updateLowHandle(newOffset);
this.updateSelectionBar(); else if (which === 'rzSliderHigh')
this.updateTicksScale();
if (this.range) {
this.updateCmbLabel();
}
return;
}
if (which === 'rzSliderHigh') {
this.updateHighHandle(newOffset); this.updateHighHandle(newOffset);
this.updateSelectionBar();
this.updateTicksScale();
if (this.range) {
this.updateCmbLabel();
}
return;
}
// Update both
this.updateLowHandle(newOffset);
this.updateHighHandle(newOffset);
this.updateSelectionBar(); this.updateSelectionBar();
this.updateTicksScale(); this.updateTicksScale();
if (this.range)
this.updateCmbLabel(); this.updateCmbLabel();
}, },
...@@ -1007,7 +987,8 @@ ...@@ -1007,7 +987,8 @@
* @returns {number} * @returns {number}
*/ */
roundStep: function(value) { roundStep: function(value) {
var steppedValue = Math.round(value / this.step) * this.step; var steppedValue = parseFloat(value / this.step).toPrecision(12)
steppedValue = Math.round(steppedValue) * this.step;
steppedValue = steppedValue.toFixed(this.precision); steppedValue = steppedValue.toFixed(this.precision);
return +steppedValue; return +steppedValue;
}, },
...@@ -1150,6 +1131,30 @@ ...@@ -1150,6 +1131,30 @@
return (eventPos - this.handleHalfDim) * this.options.scale; return (eventPos - this.handleHalfDim) * this.options.scale;
}, },
/**
* Get event names for move and event end
*
* @param {Event} event The event
*
* @return {{moveEvent: string, endEvent: string}}
*/
getEventNames: function(event) {
var eventNames = {
moveEvent: '',
endEvent: ''
};
if (event.touches || (event.originalEvent !== undefined && event.originalEvent.touches)) {
eventNames.moveEvent = 'touchmove';
eventNames.endEvent = 'touchend';
} else {
eventNames.moveEvent = 'mousemove';
eventNames.endEvent = 'mouseup';
}
return eventNames;
},
/** /**
* Get the handle closest to an event. * Get the handle closest to an event.
* *
...@@ -1180,7 +1185,6 @@ ...@@ -1180,7 +1185,6 @@
* @returns {undefined} * @returns {undefined}
*/ */
bindEvents: function() { bindEvents: function() {
if (this.options.readOnly || this.options.disabled) return;
var barTracking, barStart, barMove; var barTracking, barStart, barMove;
if (this.options.draggableRange) { if (this.options.draggableRange) {
...@@ -1198,9 +1202,7 @@ ...@@ -1198,9 +1202,7 @@
if (this.options.draggableRangeOnly) { if (this.options.draggableRangeOnly) {
this.minH.on('mousedown', angular.bind(this, barStart, null, barTracking)); this.minH.on('mousedown', angular.bind(this, barStart, null, barTracking));
if (this.range) {
this.maxH.on('mousedown', angular.bind(this, barStart, null, barTracking)); this.maxH.on('mousedown', angular.bind(this, barStart, null, barTracking));
}
} else { } else {
this.minH.on('mousedown', angular.bind(this, this.onStart, this.minH, 'rzSliderModel')); this.minH.on('mousedown', angular.bind(this, this.onStart, this.minH, 'rzSliderModel'));
if (this.range) { if (this.range) {
...@@ -1216,9 +1218,7 @@ ...@@ -1216,9 +1218,7 @@
this.selBar.on('touchstart', angular.bind(this, barMove, this.selBar)); this.selBar.on('touchstart', angular.bind(this, barMove, this.selBar));
if (this.options.draggableRangeOnly) { if (this.options.draggableRangeOnly) {
this.minH.on('touchstart', angular.bind(this, barStart, null, barTracking)); this.minH.on('touchstart', angular.bind(this, barStart, null, barTracking));
if (this.range) {
this.maxH.on('touchstart', angular.bind(this, barStart, null, barTracking)); this.maxH.on('touchstart', angular.bind(this, barStart, null, barTracking));
}
} else { } else {
this.minH.on('touchstart', angular.bind(this, this.onStart, this.minH, 'rzSliderModel')); this.minH.on('touchstart', angular.bind(this, this.onStart, this.minH, 'rzSliderModel'));
if (this.range) { if (this.range) {
...@@ -1431,9 +1431,8 @@ ...@@ -1431,9 +1431,8 @@
active: true, active: true,
value: this.offsetToValue(offset), value: this.offsetToValue(offset),
difference: this.scope.rzSliderHigh - this.scope.rzSliderModel, difference: this.scope.rzSliderHigh - this.scope.rzSliderModel,
offset: offset, lowLimit: offset - this.minH.rzsp,
lowDist: offset - this.minH.rzsp, highLimit: this.maxH.rzsp - offset
highDist: this.maxH.rzsp - offset
}; };
this.onStart(pointer, ref, event); this.onStart(pointer, ref, event);
...@@ -1453,24 +1452,22 @@ ...@@ -1453,24 +1452,22 @@
newMinOffset, newMaxOffset, newMinOffset, newMaxOffset,
newMinValue, newMaxValue; newMinValue, newMaxValue;
if (newOffset <= this.dragging.lowDist) { if (newOffset <= this.dragging.lowLimit) {
if (pointer.rzsp === this.dragging.lowDist) { if (this.minH.rzsp === 0)
return; return;
}
newMinValue = this.minValue; newMinValue = this.minValue;
newMinOffset = 0; newMinOffset = 0;
newMaxValue = this.minValue + this.dragging.difference; newMaxValue = this.minValue + this.dragging.difference;
newMaxOffset = this.valueToOffset(newMaxValue); newMaxOffset = this.valueToOffset(newMaxValue);
} else if (newOffset >= this.maxPos - this.dragging.highDist) { } else if (newOffset >= this.maxPos - this.dragging.highLimit) {
if (pointer.rzsp === this.dragging.highDist) { if (this.maxH.rzsp === this.maxPos)
return; return;
}
newMaxValue = this.maxValue; newMaxValue = this.maxValue;
newMaxOffset = this.maxPos; newMaxOffset = this.maxPos;
newMinValue = this.maxValue - this.dragging.difference; newMinValue = this.maxValue - this.dragging.difference;
newMinOffset = this.valueToOffset(newMinValue); newMinOffset = this.valueToOffset(newMinValue);
} else { } else {
newMinValue = this.offsetToValue(newOffset - this.dragging.lowDist); newMinValue = this.offsetToValue(newOffset - this.dragging.lowLimit);
newMinValue = this.roundStep(newMinValue); newMinValue = this.roundStep(newMinValue);
newMinOffset = this.valueToOffset(newMinValue); newMinOffset = this.valueToOffset(newMinValue);
newMaxValue = newMinValue + this.dragging.difference; newMaxValue = newMinValue + this.dragging.difference;
...@@ -1546,30 +1543,6 @@ ...@@ -1546,30 +1543,6 @@
return switched; return switched;
}, },
/**
* Get event names for move and event end
*
* @param {Event} event The event
*
* @return {{moveEvent: string, endEvent: string}}
*/
getEventNames: function(event) {
var eventNames = {
moveEvent: '',
endEvent: ''
};
if (event.touches || (event.originalEvent !== undefined && event.originalEvent.touches)) {
eventNames.moveEvent = 'touchmove';
eventNames.endEvent = 'touchend';
} else {
eventNames.moveEvent = 'mousemove';
eventNames.endEvent = 'mouseup';
}
return eventNames;
},
/** /**
* Apply the model values using scope.$apply. * Apply the model values using scope.$apply.
* We wrap it with the internalChange flag to avoid the watchers to be called * We wrap it with the internalChange flag to avoid the watchers to be called
......
This diff is collapsed.
...@@ -170,8 +170,8 @@ ...@@ -170,8 +170,8 @@
value: 0, value: 0,
difference: 0, difference: 0,
offset: 0, offset: 0,
lowDist: 0, lowLimit: 0,
highDist: 0 highLimit: 0
}; };
/** /**
...@@ -1135,6 +1135,30 @@ ...@@ -1135,6 +1135,30 @@
return (eventPos - this.handleHalfDim) * this.options.scale; return (eventPos - this.handleHalfDim) * this.options.scale;
}, },
/**
* Get event names for move and event end
*
* @param {Event} event The event
*
* @return {{moveEvent: string, endEvent: string}}
*/
getEventNames: function(event) {
var eventNames = {
moveEvent: '',
endEvent: ''
};
if (event.touches || (event.originalEvent !== undefined && event.originalEvent.touches)) {
eventNames.moveEvent = 'touchmove';
eventNames.endEvent = 'touchend';
} else {
eventNames.moveEvent = 'mousemove';
eventNames.endEvent = 'mouseup';
}
return eventNames;
},
/** /**
* Get the handle closest to an event. * Get the handle closest to an event.
* *
...@@ -1411,9 +1435,8 @@ ...@@ -1411,9 +1435,8 @@
active: true, active: true,
value: this.offsetToValue(offset), value: this.offsetToValue(offset),
difference: this.scope.rzSliderHigh - this.scope.rzSliderModel, difference: this.scope.rzSliderHigh - this.scope.rzSliderModel,
offset: offset, lowLimit: offset - this.minH.rzsp,
lowDist: offset - this.minH.rzsp, highLimit: this.maxH.rzsp - offset
highDist: this.maxH.rzsp - offset
}; };
this.onStart(pointer, ref, event); this.onStart(pointer, ref, event);
...@@ -1433,24 +1456,22 @@ ...@@ -1433,24 +1456,22 @@
newMinOffset, newMaxOffset, newMinOffset, newMaxOffset,
newMinValue, newMaxValue; newMinValue, newMaxValue;
if (newOffset <= this.dragging.lowDist) { if (newOffset <= this.dragging.lowLimit) {
if (pointer.rzsp === this.dragging.lowDist) { if (this.minH.rzsp === 0)
return; return;
}
newMinValue = this.minValue; newMinValue = this.minValue;
newMinOffset = 0; newMinOffset = 0;
newMaxValue = this.minValue + this.dragging.difference; newMaxValue = this.minValue + this.dragging.difference;
newMaxOffset = this.valueToOffset(newMaxValue); newMaxOffset = this.valueToOffset(newMaxValue);
} else if (newOffset >= this.maxPos - this.dragging.highDist) { } else if (newOffset >= this.maxPos - this.dragging.highLimit) {
if (pointer.rzsp === this.dragging.highDist) { if (this.maxH.rzsp === this.maxPos)
return; return;
}
newMaxValue = this.maxValue; newMaxValue = this.maxValue;
newMaxOffset = this.maxPos; newMaxOffset = this.maxPos;
newMinValue = this.maxValue - this.dragging.difference; newMinValue = this.maxValue - this.dragging.difference;
newMinOffset = this.valueToOffset(newMinValue); newMinOffset = this.valueToOffset(newMinValue);
} else { } else {
newMinValue = this.offsetToValue(newOffset - this.dragging.lowDist); newMinValue = this.offsetToValue(newOffset - this.dragging.lowLimit);
newMinValue = this.roundStep(newMinValue); newMinValue = this.roundStep(newMinValue);
newMinOffset = this.valueToOffset(newMinValue); newMinOffset = this.valueToOffset(newMinValue);
newMaxValue = newMinValue + this.dragging.difference; newMaxValue = newMinValue + this.dragging.difference;
...@@ -1526,30 +1547,6 @@ ...@@ -1526,30 +1547,6 @@
return switched; return switched;
}, },
/**
* Get event names for move and event end
*
* @param {Event} event The event
*
* @return {{moveEvent: string, endEvent: string}}
*/
getEventNames: function(event) {
var eventNames = {
moveEvent: '',
endEvent: ''
};
if (event.touches || (event.originalEvent !== undefined && event.originalEvent.touches)) {
eventNames.moveEvent = 'touchmove';
eventNames.endEvent = 'touchend';
} else {
eventNames.moveEvent = 'mousemove';
eventNames.endEvent = 'mouseup';
}
return eventNames;
},
/** /**
* Apply the model values using scope.$apply. * Apply the model values using scope.$apply.
* We wrap it with the internalChange flag to avoid the watchers to be called * We wrap it with the internalChange flag to avoid the watchers to be called
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment