mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-08 02:10:24 +00:00
Add keyboard up/down handler for dropdown
This commit is contained in:
@@ -51,6 +51,7 @@ define([
|
|||||||
|
|
||||||
initialize: function(options) {
|
initialize: function(options) {
|
||||||
this.$el.on('click', '.dropdown-toggle', _.bind(this.toggleDropdown, this));
|
this.$el.on('click', '.dropdown-toggle', _.bind(this.toggleDropdown, this));
|
||||||
|
this.$el.on('keydown', _.bind(this.handleKeydown, this));
|
||||||
this.options = {};
|
this.options = {};
|
||||||
_.extend(this.options, this.defaultOptions, options);
|
_.extend(this.options, this.defaultOptions, options);
|
||||||
},
|
},
|
||||||
@@ -83,6 +84,31 @@ define([
|
|||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
},
|
||||||
|
|
||||||
|
handleKeydown: function(event) {
|
||||||
|
if (!/(38|40)/.test(event.which)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
|
||||||
|
var items = $.makeArray(this.$el.find('li a'));
|
||||||
|
|
||||||
|
if (!items.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var index = items.indexOf(event.target);
|
||||||
|
if (event.which === 38 && index > 0) { // up
|
||||||
|
index--;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.which === 40 && index < items.length - 1) { // down
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
items[index].focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user