提交 48ddb1cd 编写于 作者: J jlewin

Editor: Added keyboard navigation to the scene graph explorer hosted in the sidebar

上级 58e46224
......@@ -332,6 +332,34 @@ UI.FancySelect = function () {
dom.style.padding = '0';
dom.style.cursor = 'default';
dom.style.overflow = 'auto';
dom.tabIndex = 0; // keyup event is ignored without setting tabIndex
// Broadcast for object selection after arrow navigation
var changeEvent = document.createEvent('HTMLEvents');
changeEvent.initEvent( 'change', true, true );
// Keybindings to support arrow navigation
dom.addEventListener( 'keyup', function (event) {
switch ( event.keyCode ) {
case 38: // up
case 40: // down
var index = scope.indexOf( scope.selectedValue );
index += ( event.keyCode == 38 ) ? -1 : 1;
if ( index >= 0 && index < scope.options.length ) {
// Select dom element
scope.setValue( scope.options[index].value );
// Invoke object selection logic
scope.dom.dispatchEvent( changeEvent );
}
break;
}
}, false);
this.dom = dom;
......@@ -427,6 +455,27 @@ UI.FancySelect.prototype.setValue = function ( value ) {
};
UI.FancySelect.prototype.indexOf = function ( key ) {
if ( typeof key === 'number' ) key = key.toString();
// Iterate options and return the index of the first occurrence of the key
for ( var i = 0; i < this.options.length; i++ ) {
var element = this.options[i];
if ( element.value === key ) {
test = element;
return i;
}
}
return -1
};
// Checkbox
UI.Checkbox = function ( boolean ) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册