|
1014 | 1014 | * @returns {number}
|
1015 | 1015 | */
|
1016 | 1016 | valueToOffset: function(val) {
|
1017 |
| - return (this.sanitizeOffsetValue(val) - this.minValue) * this.maxPos / this.valueRange || 0; |
| 1017 | + return (this.sanitizeValue(val) - this.minValue) * this.maxPos / this.valueRange || 0; |
1018 | 1018 | },
|
1019 | 1019 |
|
1020 | 1020 | /**
|
1021 |
| - * Ensure that the position rendered is within the slider bounds, even if the value is not |
| 1021 | + * Returns a value that is within slider range |
1022 | 1022 | *
|
1023 | 1023 | * @param {number} val
|
1024 | 1024 | * @returns {number}
|
1025 | 1025 | */
|
1026 |
| - sanitizeOffsetValue: function(val) { |
| 1026 | + sanitizeValue: function(val) { |
1027 | 1027 | return Math.min(Math.max(val, this.minValue), this.maxValue);
|
1028 | 1028 | },
|
1029 | 1029 |
|
|
1126 | 1126 | this.selBar.on('touchstart', angular.bind(this, barMove, this.selBar));
|
1127 | 1127 | this.ticks.on('touchstart', angular.bind(this, this.onStart, null, null));
|
1128 | 1128 | this.ticks.on('touchstart', angular.bind(this, this.onMove, this.ticks));
|
| 1129 | + |
| 1130 | + this.minH.on('focus', angular.bind(this, this.onPointerFocus, this.minH, 'rzSliderModel')) |
| 1131 | + if (this.range) { |
| 1132 | + this.maxH.on('focus', angular.bind(this, this.onPointerFocus, this.maxH, 'rzSliderHigh')); |
| 1133 | + } |
1129 | 1134 | },
|
1130 | 1135 |
|
1131 | 1136 | /**
|
|
1156 | 1161 | event.stopPropagation();
|
1157 | 1162 | event.preventDefault();
|
1158 | 1163 |
|
1159 |
| - if (this.tracking !== '') { |
1160 |
| - return; |
1161 |
| - } |
1162 |
| - |
1163 | 1164 | // We have to do this in case the HTML where the sliders are on
|
1164 | 1165 | // have been animated into view.
|
1165 | 1166 | this.calcViewDimensions();
|
|
1210 | 1211 | this.positionTrackingHandle(newValue, newOffset);
|
1211 | 1212 | },
|
1212 | 1213 |
|
| 1214 | + onPointerFocus: function(pointer, ref, event) { |
| 1215 | + this.tracking = ref; |
| 1216 | + pointer.one('blur', angular.bind(this, this.onPointerBlur, pointer)); |
| 1217 | + pointer.on('keydown', angular.bind(this, this.onKeyboardEvent)); |
| 1218 | + pointer.addClass('rz-active'); |
| 1219 | + }, |
| 1220 | + |
| 1221 | + onPointerBlur: function(pointer, event) { |
| 1222 | + this.tracking = ''; |
| 1223 | + pointer.off('keydown'); |
| 1224 | + pointer.removeClass('rz-active'); |
| 1225 | + }, |
| 1226 | + |
| 1227 | + onKeyboardEvent: function(event) { |
| 1228 | + var keyCode = event.keyCode || event.which, |
| 1229 | + keys = { |
| 1230 | + 38: 'UP', |
| 1231 | + 40: 'DOWN', |
| 1232 | + 37: 'LEFT', |
| 1233 | + 39: 'RIGHT' |
| 1234 | + }, |
| 1235 | + actions = { |
| 1236 | + UP: 5, |
| 1237 | + DOWN: -5, |
| 1238 | + LEFT: -1, |
| 1239 | + RIGHT: 1 |
| 1240 | + }, |
| 1241 | + key = keys[keyCode], |
| 1242 | + action = actions[key]; |
| 1243 | + |
| 1244 | + if (!key || !this.tracking) return; |
| 1245 | + event.preventDefault(); |
| 1246 | + |
| 1247 | + var value = this.scope[this.tracking], |
| 1248 | + newValue = this.roundStep(this.sanitizeValue(value + action)), |
| 1249 | + newOffset = this.valueToOffset(newValue); |
| 1250 | + var switched = this.positionTrackingHandle(newValue, newOffset); |
| 1251 | + if (switched) { |
| 1252 | + var pointer = this.tracking === 'rzSliderModel' ? this.minH : this.maxH; |
| 1253 | + pointer[0].focus(); //to focus the correct pointer |
| 1254 | + } |
| 1255 | + }, |
| 1256 | + |
1213 | 1257 | /**
|
1214 | 1258 | * onDragStart event handler
|
1215 | 1259 | *
|
|
1302 | 1346 | */
|
1303 | 1347 | positionTrackingHandle: function(newValue, newOffset) {
|
1304 | 1348 | var valueChanged = false;
|
| 1349 | + var switched = false; |
1305 | 1350 |
|
1306 | 1351 | if (this.range) {
|
1307 | 1352 | /* This is to check if we need to switch the min and max handles*/
|
1308 | 1353 | if (this.tracking === 'rzSliderModel' && newValue >= this.scope.rzSliderHigh) {
|
| 1354 | + switched = true; |
1309 | 1355 | this.scope[this.tracking] = this.scope.rzSliderHigh;
|
1310 | 1356 | this.updateHandles(this.tracking, this.maxH.rzsp);
|
1311 | 1357 | this.tracking = 'rzSliderHigh';
|
1312 | 1358 | this.minH.removeClass('rz-active');
|
1313 | 1359 | this.maxH.addClass('rz-active');
|
1314 | 1360 | valueChanged = true;
|
1315 | 1361 | } else if (this.tracking === 'rzSliderHigh' && newValue <= this.scope.rzSliderModel) {
|
| 1362 | + switched = true; |
1316 | 1363 | this.scope[this.tracking] = this.scope.rzSliderModel;
|
1317 | 1364 | this.updateHandles(this.tracking, this.minH.rzsp);
|
1318 | 1365 | this.tracking = 'rzSliderModel';
|
|
1332 | 1379 | this.scope.$apply();
|
1333 | 1380 | this.callOnChange();
|
1334 | 1381 | }
|
| 1382 | + return switched; |
1335 | 1383 | },
|
1336 | 1384 |
|
1337 | 1385 | /**
|
|
0 commit comments