Massive improvements to keyboard nav
This commit is contained in:
@@ -1,29 +1,34 @@
|
||||
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="DropDown.ascx.cs" Inherits="Swarmops.Frontend.Controls.v5.Base.DropDown" %>
|
||||
|
||||
<script language="javascript" type="text/javascript">
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function () {
|
||||
$('#<%=this.DropControl.ClientID %>').combobox({
|
||||
animate: true,
|
||||
height: 30
|
||||
});
|
||||
$(document).ready(function () {
|
||||
$('#<%=this.DropControl.ClientID %>').combobox({
|
||||
editable: false,
|
||||
height: 30,
|
||||
width: 300
|
||||
});
|
||||
$('#<%=this.DropControl.ClientID %>').combobox('setValue', '<%=this.DropControl.SelectedValue%>');
|
||||
|
||||
$('#<%=this.DropControl.ClientID %> span.combo input.combo-text').click(function () {
|
||||
$('#<%=this.DropControl.ClientID %> span.combo span span.combo-arrow').click();
|
||||
});
|
||||
$('#<%=this.DropControl.ClientID %> + span.combo > input.combo-text').click(function () {
|
||||
$('#<%=this.DropControl.ClientID %> + span.combo > span > span.combo-arrow').click();
|
||||
});
|
||||
|
||||
$('#<%=this.DropControl.ClientID %>_SpanBudgets span.combo input.combo-text').keydown(function (e) {
|
||||
switch (e.which) {
|
||||
case 40: // down
|
||||
$('#<%=this.DropControl.ClientID %>_SpanBudgets span.combo span span.combo-arrow').click();
|
||||
break;
|
||||
$('#<%=this.DropControl.ClientID %> + span.combo > input.combo-text').keydown(function (e) {
|
||||
switch (e.which) {
|
||||
case 40: // down
|
||||
var panel = $('#<%=this.DropControl.ClientID %>').combo('panel');
|
||||
if (!panel.is(':visible')) {
|
||||
$('#<%=this.DropControl.ClientID %> + span.combo > span > span.combo-arrow').click();
|
||||
panel.focus();
|
||||
}
|
||||
break;
|
||||
|
||||
default: return; // exit this handler for other keys
|
||||
}
|
||||
e.preventDefault(); // prevent the default action (scroll / move caret)
|
||||
default: return; // exit this handler for other keys
|
||||
}
|
||||
e.preventDefault(); // prevent the default action (scroll / move caret)
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</script>
|
||||
|
||||
|
||||
<asp:DropDownList ID="DropControl" runat="server" />
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Swarmops.Frontend.Controls.v5.Base
|
||||
|
||||
public string SelectedValue
|
||||
{
|
||||
get { return this.SelectedValue; }
|
||||
get { return this.DropControl.SelectedValue; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,11 @@
|
||||
$('#<%=this.ClientID %>_SpanBudgets span.combo input.combo-text').keydown(function (e) {
|
||||
switch (e.which) {
|
||||
case 40: // down
|
||||
$('#<%=this.ClientID %>_SpanBudgets span.combo span span.combo-arrow').click();
|
||||
var panel = $('#<%=this.ClientID %>_DropBudgets').combotree('panel');
|
||||
if (!panel.is(':visible')) {
|
||||
$('#<%=this.ClientID %>_SpanBudgets span.combo span span.combo-arrow').click();
|
||||
panel.focus();
|
||||
}
|
||||
break;
|
||||
|
||||
default: return; // exit this handler for other keys
|
||||
@@ -32,6 +36,67 @@
|
||||
e.preventDefault(); // prevent the default action (scroll / move caret)
|
||||
});
|
||||
});
|
||||
|
||||
// below code from http://doc.javake.cn/jeasyui/www.jeasyui.com/forum/index.php-topic=1972.0.htm, understood to be in public domain
|
||||
|
||||
(function () {
|
||||
$.extend($.fn.combotree.methods, {
|
||||
nav: function (jq, dir) {
|
||||
return jq.each(function () {
|
||||
var opts = $(this).combotree('options');
|
||||
var t = $(this).combotree('tree');
|
||||
var nodes = t.tree('getChildren');
|
||||
if (!nodes.length) { return }
|
||||
var node = t.tree('getSelected');
|
||||
if (!node) {
|
||||
t.tree('select', dir > 0 ? nodes[0].target : nodes[nodes.length - 1].target);
|
||||
} else {
|
||||
var index = 0;
|
||||
for (var i = 0; i < nodes.length; i++) {
|
||||
if (nodes[i].target == node.target) {
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (dir > 0) {
|
||||
while (index < nodes.length - 1) {
|
||||
index++;
|
||||
if ($(nodes[index].target).is(':visible')) { break }
|
||||
}
|
||||
} else {
|
||||
while (index > 0) {
|
||||
index--;
|
||||
if ($(nodes[index].target).is(':visible')) { break }
|
||||
}
|
||||
}
|
||||
t.tree('select', nodes[index].target);
|
||||
}
|
||||
if (opts.selectOnNavigation) {
|
||||
var node = t.tree('getSelected');
|
||||
$(node.target).trigger('click');
|
||||
$(this).combotree('showPanel');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
$.extend($.fn.combotree.defaults.keyHandler, {
|
||||
up: function () {
|
||||
$(this).combotree('nav', -1);
|
||||
},
|
||||
down: function () {
|
||||
$(this).combotree('nav', 1);
|
||||
},
|
||||
enter: function () {
|
||||
var t = $(this).combotree('tree');
|
||||
var node = t.tree('getSelected');
|
||||
if (node) {
|
||||
$(node.target).trigger('click');
|
||||
}
|
||||
$(this).combotree('hidePanel');
|
||||
}
|
||||
});
|
||||
})(jQuery);
|
||||
|
||||
</script>
|
||||
|
||||
<span id="<%=this.ClientID %>_SpanBudgets"><select class="easyui-combotree" url="<%=this.DataUrl %>" name="DropBudgets" id="<%=this.ClientID %>_DropBudgets" animate="true" style="width:300px"></select></span>
|
||||
Reference in New Issue
Block a user