Commit 8197e820 authored by Valentin Hervieu's avatar Valentin Hervieu

Clean code for keyboardSupport and ignore test coverage files

parent a65063e7
node_modules/ node_modules/
.idea/ .idea/
bower_components/ bower_components/
temp/ temp/
\ No newline at end of file tests/coverage/
...@@ -644,15 +644,19 @@ ...@@ -644,15 +644,19 @@
* Updates aria attributes according to current values * Updates aria attributes according to current values
*/ */
updateAriaAttributes: function() { updateAriaAttributes: function() {
this.minH.attr('aria-valuenow', this.scope.rzSliderModel); this.minH.attr({
this.minH.attr('aria-valuetext', this.customTrFn(this.scope.rzSliderModel)); 'aria-valuenow': this.scope.rzSliderModel,
this.minH.attr('aria-valuemin', this.minValue); 'aria-valuetext': this.customTrFn(this.scope.rzSliderModel),
this.minH.attr('aria-valuemax', this.maxValue); 'aria-valuemin': this.minValue,
'aria-valuemax': this.maxValue
});
if (this.range) { if (this.range) {
this.maxH.attr('aria-valuenow', this.scope.rzSliderHigh); this.maxH.attr({
this.maxH.attr('aria-valuetext', this.customTrFn(this.scope.rzSliderHigh)); 'aria-valuenow': this.scope.rzSliderHigh,
this.maxH.attr('aria-valuemin', this.minValue); 'aria-valuetext': this.customTrFn(this.scope.rzSliderHigh),
this.maxH.attr('aria-valuemax', this.maxValue); 'aria-valuemin': this.minValue,
'aria-valuemax': this.maxValue
});
} }
}, },
...@@ -1117,6 +1121,16 @@ ...@@ -1117,6 +1121,16 @@
return Math.abs(offset - this.minH.rzsp) < Math.abs(offset - this.maxH.rzsp) ? this.minH : this.maxH; return Math.abs(offset - this.minH.rzsp) < Math.abs(offset - this.maxH.rzsp) ? this.minH : this.maxH;
}, },
/**
* Wrapper function to focus an angular element
*
* @param el {AngularElement} the element to focus
*/
focusElement: function(el) {
var DOM_ELEMENT = 0;
el[DOM_ELEMENT].focus();
},
/** /**
* Bind mouse and touch events to slider handles * Bind mouse and touch events to slider handles
* *
...@@ -1208,7 +1222,7 @@ ...@@ -1208,7 +1222,7 @@
pointer.addClass('rz-active'); pointer.addClass('rz-active');
if (this.options.keyboardSupport) if (this.options.keyboardSupport)
pointer[0].focus(); this.focusElement(pointer);
ehMove = angular.bind(this, this.dragging.active ? this.onDragMove : this.onMove, pointer); ehMove = angular.bind(this, this.dragging.active ? this.onDragMove : this.onMove, pointer);
ehEnd = angular.bind(this, this.onEnd, ehMove); ehEnd = angular.bind(this, this.onEnd, ehMove);
...@@ -1420,7 +1434,7 @@ ...@@ -1420,7 +1434,7 @@
this.minH.removeClass('rz-active'); this.minH.removeClass('rz-active');
this.maxH.addClass('rz-active'); this.maxH.addClass('rz-active');
if (this.options.keyboardSupport) if (this.options.keyboardSupport)
this.maxH[0].focus(); this.focusElement(this.maxH);
valueChanged = true; valueChanged = true;
} else if (this.tracking === 'rzSliderHigh' && newValue <= this.scope.rzSliderModel) { } else if (this.tracking === 'rzSliderHigh' && newValue <= this.scope.rzSliderModel) {
switched = true; switched = true;
...@@ -1431,7 +1445,7 @@ ...@@ -1431,7 +1445,7 @@
this.maxH.removeClass('rz-active'); this.maxH.removeClass('rz-active');
this.minH.addClass('rz-active'); this.minH.addClass('rz-active');
if (this.options.keyboardSupport) if (this.options.keyboardSupport)
this.minH[0].focus(); this.focusElement(this.minH);
valueChanged = true; valueChanged = true;
} }
} }
......
This diff is collapsed.
...@@ -644,15 +644,19 @@ ...@@ -644,15 +644,19 @@
* Updates aria attributes according to current values * Updates aria attributes according to current values
*/ */
updateAriaAttributes: function() { updateAriaAttributes: function() {
this.minH.attr('aria-valuenow', this.scope.rzSliderModel); this.minH.attr({
this.minH.attr('aria-valuetext', this.customTrFn(this.scope.rzSliderModel)); 'aria-valuenow': this.scope.rzSliderModel,
this.minH.attr('aria-valuemin', this.minValue); 'aria-valuetext': this.customTrFn(this.scope.rzSliderModel),
this.minH.attr('aria-valuemax', this.maxValue); 'aria-valuemin': this.minValue,
'aria-valuemax': this.maxValue
});
if (this.range) { if (this.range) {
this.maxH.attr('aria-valuenow', this.scope.rzSliderHigh); this.maxH.attr({
this.maxH.attr('aria-valuetext', this.customTrFn(this.scope.rzSliderHigh)); 'aria-valuenow': this.scope.rzSliderHigh,
this.maxH.attr('aria-valuemin', this.minValue); 'aria-valuetext': this.customTrFn(this.scope.rzSliderHigh),
this.maxH.attr('aria-valuemax', this.maxValue); 'aria-valuemin': this.minValue,
'aria-valuemax': this.maxValue
});
} }
}, },
...@@ -1117,6 +1121,16 @@ ...@@ -1117,6 +1121,16 @@
return Math.abs(offset - this.minH.rzsp) < Math.abs(offset - this.maxH.rzsp) ? this.minH : this.maxH; return Math.abs(offset - this.minH.rzsp) < Math.abs(offset - this.maxH.rzsp) ? this.minH : this.maxH;
}, },
/**
* Wrapper function to focus an angular element
*
* @param el {AngularElement} the element to focus
*/
focusElement: function(el) {
var DOM_ELEMENT = 0;
el[DOM_ELEMENT].focus();
},
/** /**
* Bind mouse and touch events to slider handles * Bind mouse and touch events to slider handles
* *
...@@ -1208,7 +1222,7 @@ ...@@ -1208,7 +1222,7 @@
pointer.addClass('rz-active'); pointer.addClass('rz-active');
if (this.options.keyboardSupport) if (this.options.keyboardSupport)
pointer[0].focus(); this.focusElement(pointer);
ehMove = angular.bind(this, this.dragging.active ? this.onDragMove : this.onMove, pointer); ehMove = angular.bind(this, this.dragging.active ? this.onDragMove : this.onMove, pointer);
ehEnd = angular.bind(this, this.onEnd, ehMove); ehEnd = angular.bind(this, this.onEnd, ehMove);
...@@ -1420,7 +1434,7 @@ ...@@ -1420,7 +1434,7 @@
this.minH.removeClass('rz-active'); this.minH.removeClass('rz-active');
this.maxH.addClass('rz-active'); this.maxH.addClass('rz-active');
if (this.options.keyboardSupport) if (this.options.keyboardSupport)
this.maxH[0].focus(); this.focusElement(this.maxH);
valueChanged = true; valueChanged = true;
} else if (this.tracking === 'rzSliderHigh' && newValue <= this.scope.rzSliderModel) { } else if (this.tracking === 'rzSliderHigh' && newValue <= this.scope.rzSliderModel) {
switched = true; switched = true;
...@@ -1431,7 +1445,7 @@ ...@@ -1431,7 +1445,7 @@
this.maxH.removeClass('rz-active'); this.maxH.removeClass('rz-active');
this.minH.addClass('rz-active'); this.minH.addClass('rz-active');
if (this.options.keyboardSupport) if (this.options.keyboardSupport)
this.minH[0].focus(); this.focusElement(this.minH);
valueChanged = true; valueChanged = true;
} }
} }
......
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