Skip to content

Commit 8197e82

Browse files
author
Valentin Hervieu
committed
Clean code for keyboardSupport and ignore test coverage files
1 parent a65063e commit 8197e82

File tree

4 files changed

+53
-24
lines changed

4 files changed

+53
-24
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
node_modules/
22
.idea/
33
bower_components/
4-
temp/
4+
temp/
5+
tests/coverage/

dist/rzslider.js

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -644,15 +644,19 @@
644644
* Updates aria attributes according to current values
645645
*/
646646
updateAriaAttributes: function() {
647-
this.minH.attr('aria-valuenow', this.scope.rzSliderModel);
648-
this.minH.attr('aria-valuetext', this.customTrFn(this.scope.rzSliderModel));
649-
this.minH.attr('aria-valuemin', this.minValue);
650-
this.minH.attr('aria-valuemax', this.maxValue);
647+
this.minH.attr({
648+
'aria-valuenow': this.scope.rzSliderModel,
649+
'aria-valuetext': this.customTrFn(this.scope.rzSliderModel),
650+
'aria-valuemin': this.minValue,
651+
'aria-valuemax': this.maxValue
652+
});
651653
if (this.range) {
652-
this.maxH.attr('aria-valuenow', this.scope.rzSliderHigh);
653-
this.maxH.attr('aria-valuetext', this.customTrFn(this.scope.rzSliderHigh));
654-
this.maxH.attr('aria-valuemin', this.minValue);
655-
this.maxH.attr('aria-valuemax', this.maxValue);
654+
this.maxH.attr({
655+
'aria-valuenow': this.scope.rzSliderHigh,
656+
'aria-valuetext': this.customTrFn(this.scope.rzSliderHigh),
657+
'aria-valuemin': this.minValue,
658+
'aria-valuemax': this.maxValue
659+
});
656660
}
657661
},
658662

@@ -1117,6 +1121,16 @@
11171121
return Math.abs(offset - this.minH.rzsp) < Math.abs(offset - this.maxH.rzsp) ? this.minH : this.maxH;
11181122
},
11191123

1124+
/**
1125+
* Wrapper function to focus an angular element
1126+
*
1127+
* @param el {AngularElement} the element to focus
1128+
*/
1129+
focusElement: function(el) {
1130+
var DOM_ELEMENT = 0;
1131+
el[DOM_ELEMENT].focus();
1132+
},
1133+
11201134
/**
11211135
* Bind mouse and touch events to slider handles
11221136
*
@@ -1208,7 +1222,7 @@
12081222
pointer.addClass('rz-active');
12091223

12101224
if (this.options.keyboardSupport)
1211-
pointer[0].focus();
1225+
this.focusElement(pointer);
12121226

12131227
ehMove = angular.bind(this, this.dragging.active ? this.onDragMove : this.onMove, pointer);
12141228
ehEnd = angular.bind(this, this.onEnd, ehMove);
@@ -1420,7 +1434,7 @@
14201434
this.minH.removeClass('rz-active');
14211435
this.maxH.addClass('rz-active');
14221436
if (this.options.keyboardSupport)
1423-
this.maxH[0].focus();
1437+
this.focusElement(this.maxH);
14241438
valueChanged = true;
14251439
} else if (this.tracking === 'rzSliderHigh' && newValue <= this.scope.rzSliderModel) {
14261440
switched = true;
@@ -1431,7 +1445,7 @@
14311445
this.maxH.removeClass('rz-active');
14321446
this.minH.addClass('rz-active');
14331447
if (this.options.keyboardSupport)
1434-
this.minH[0].focus();
1448+
this.focusElement(this.minH);
14351449
valueChanged = true;
14361450
}
14371451
}

0 commit comments

Comments
 (0)