Skip to content

Commit a6ae35b

Browse files
author
Valentin Hervieu
committed
Add more keys and improve switched between keyboard and mouse
1 parent 1d2354e commit a6ae35b

File tree

3 files changed

+89
-67
lines changed

3 files changed

+89
-67
lines changed

dist/rzslider.js

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,7 @@
11731173
}
11741174

11751175
pointer.addClass('rz-active');
1176+
pointer[0].focus();
11761177

11771178
ehMove = angular.bind(this, this.dragging.active ? this.onDragMove : this.onMove, pointer);
11781179
ehEnd = angular.bind(this, this.onEnd, ehMove);
@@ -1211,41 +1212,73 @@
12111212
this.positionTrackingHandle(newValue, newOffset);
12121213
},
12131214

1215+
/**
1216+
* onEnd event handler
1217+
*
1218+
* @param {Event} event The event
1219+
* @param {Function} ehMove The the bound move event handler
1220+
* @returns {undefined}
1221+
*/
1222+
onEnd: function(ehMove, event) {
1223+
var moveEventName = this.getEventNames(event).moveEvent;
1224+
1225+
//this.minH.removeClass('rz-active');
1226+
//this.maxH.removeClass('rz-active');
1227+
1228+
$document.off(moveEventName, ehMove);
1229+
1230+
this.scope.$emit('slideEnded');
1231+
//this.tracking = '';
1232+
1233+
this.dragging.active = false;
1234+
this.callOnEnd();
1235+
},
1236+
12141237
onPointerFocus: function(pointer, ref, event) {
1238+
//if (this.tracking === ref) return;
12151239
this.tracking = ref;
1240+
console.info('focused', ref);
12161241
pointer.one('blur', angular.bind(this, this.onPointerBlur, pointer));
12171242
pointer.on('keydown', angular.bind(this, this.onKeyboardEvent));
12181243
pointer.addClass('rz-active');
12191244
},
12201245

12211246
onPointerBlur: function(pointer, event) {
1222-
this.tracking = '';
1247+
console.info('focused', this.tracking);
12231248
pointer.off('keydown');
1249+
this.tracking = '';
12241250
pointer.removeClass('rz-active');
12251251
},
12261252

12271253
onKeyboardEvent: function(event) {
1228-
var keyCode = event.keyCode || event.which,
1254+
var currentValue = this.scope[this.tracking],
1255+
keyCode = event.keyCode || event.which,
12291256
keys = {
12301257
38: 'UP',
12311258
40: 'DOWN',
12321259
37: 'LEFT',
1233-
39: 'RIGHT'
1260+
39: 'RIGHT',
1261+
33: 'PAGEUP',
1262+
34: 'PAGEDOWN',
1263+
36: 'HOME',
1264+
35: 'END'
12341265
},
12351266
actions = {
1236-
UP: 5,
1237-
DOWN: -5,
1238-
LEFT: -1,
1239-
RIGHT: 1
1267+
UP: currentValue + this.step,
1268+
DOWN: currentValue - this.step,
1269+
LEFT: currentValue - this.step,
1270+
RIGHT: currentValue + this.step,
1271+
PAGEUP: currentValue + this.valueRange / 10,
1272+
PAGEDOWN: currentValue - this.valueRange / 10,
1273+
HOME: this.minValue,
1274+
END: this.maxValue
12401275
},
12411276
key = keys[keyCode],
12421277
action = actions[key];
1243-
1244-
if (!key || !this.tracking) return;
1278+
if (action == null || this.tracking === '') return;
12451279
event.preventDefault();
12461280

1247-
var value = this.scope[this.tracking],
1248-
newValue = this.roundStep(this.sanitizeValue(value + action)),
1281+
var newValue = this.roundStep(this.sanitizeValue(action)),
12491282
newOffset = this.valueToOffset(newValue);
12501283
var switched = this.positionTrackingHandle(newValue, newOffset);
12511284
if (switched) {
@@ -1382,28 +1415,6 @@
13821415
return switched;
13831416
},
13841417

1385-
/**
1386-
* onEnd event handler
1387-
*
1388-
* @param {Event} event The event
1389-
* @param {Function} ehMove The the bound move event handler
1390-
* @returns {undefined}
1391-
*/
1392-
onEnd: function(ehMove, event) {
1393-
var moveEventName = this.getEventNames(event).moveEvent;
1394-
1395-
this.minH.removeClass('rz-active');
1396-
this.maxH.removeClass('rz-active');
1397-
1398-
$document.off(moveEventName, ehMove);
1399-
1400-
this.scope.$emit('slideEnded');
1401-
this.tracking = '';
1402-
1403-
this.dragging.active = false;
1404-
this.callOnEnd();
1405-
},
1406-
14071418
/**
14081419
* Get event names for move and event end
14091420
*

0 commit comments

Comments
 (0)