nav.html
5.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Keyboard Navigation in MenuButton - jQuery EasyUI Demo</title>
<link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="../../themes/icon.css">
<link rel="stylesheet" type="text/css" href="../demo.css">
<script type="text/javascript" src="../../jquery.min.js"></script>
<script type="text/javascript" src="../../jquery.easyui.min.js"></script>
</head>
<body>
<h2>Keyboard Navigation in MenuButton</h2>
<p>Press Alt+W to focus the menubutton. Once the menubutton get focus, you will be able to navigate menubutton using keyboard keys.</p>
<div style="margin:20px 0;"></div>
<div class="easyui-panel" style="padding:5px;">
<a id="btn-home" href="#" class="easyui-linkbutton" data-options="plain:true">Home</a>
<a href="#" class="easyui-menubutton" data-options="menu:'#mm1',iconCls:'icon-edit'">Edit</a>
<a href="#" class="easyui-menubutton" data-options="menu:'#mm2',iconCls:'icon-help'">Help</a>
<a href="#" class="easyui-menubutton" data-options="menu:'#mm3'">About</a>
</div>
<div id="mm1" style="width:150px;">
<div data-options="iconCls:'icon-undo'">Undo</div>
<div data-options="iconCls:'icon-redo'">Redo</div>
<div class="menu-sep"></div>
<div>Cut</div>
<div>Copy</div>
<div>Paste</div>
<div class="menu-sep"></div>
<div>
<span>Toolbar</span>
<div>
<div>Address</div>
<div>Link</div>
<div>Navigation Toolbar</div>
<div>Bookmark Toolbar</div>
<div class="menu-sep"></div>
<div>New Toolbar...</div>
</div>
</div>
<div data-options="iconCls:'icon-remove'">Delete</div>
<div>Select All</div>
</div>
<div id="mm2" style="width:100px;">
<div>Help</div>
<div>Update</div>
<div>About</div>
</div>
<div id="mm3" class="menu-content" style="background:#f0f0f0;padding:10px;text-align:left">
<img src="http://www.jeasyui.com/images/logo1.png" style="width:150px;height:50px">
<p style="font-size:14px;color:#444;">Try jQuery EasyUI to build your modern, interactive, javascript applications.</p>
</div>
<script type="text/javascript">
(function($){
function getParentMenu(rootMenu, menu){
return findParent(rootMenu);
function findParent(pmenu){
var p = undefined;
$(pmenu).find('.menu-item').each(function(){
if (!p && this.submenu){
if ($(this.submenu)[0] == $(menu)[0]){
p = pmenu;
} else {
p = findParent(this.submenu);
}
}
});
return p;
}
}
function getParentItem(pmenu, menu){
var item = undefined;
$(pmenu).find('.menu-item').each(function(){
if ($(this.submenu)[0] == $(menu)[0]){
item = $(this);
return false;
}
});
return item;
}
$.extend($.fn.menubutton.methods, {
enableNav: function(enabled){
var curr;
$(document).unbind('.menubutton');
if (enabled == undefined){enabled = true;}
if (enabled){
$(document).bind('keydown.menubutton', function(e){
var currButton = $(this).find('.m-btn-active,.m-btn-plain-active,.l-btn:focus');
if (!currButton.length){
return;
}
if (!curr || curr.button != currButton[0]){
curr = {
menu: currButton.data('menubutton') ? $(currButton.menubutton('options').menu) : $(),
button: currButton[0]
};
}
var item = curr.menu.find('.menu-active');
switch(e.keyCode){
case 13: // enter
item.trigger('click');
break;
case 27: // esc
currButton.trigger('mouseleave');
break;
case 38: // up
var prev = !item.length ? curr.menu.find('.menu-item:last') : item.prevAll('.menu-item:first');
prev.trigger('mouseenter');
return false;
case 40: // down
var next = !item.length ? curr.menu.find('.menu-item:first') : item.nextAll('.menu-item:first');
next.trigger('mouseenter');
return false;
case 37: // left
var pmenu = getParentMenu(currButton.data('menubutton') ? $(currButton.menubutton('options').menu) : $(), curr.menu);
if (pmenu){
item.trigger('mouseleave');
var pitem = getParentItem(pmenu, curr.menu);
if (pitem){
pitem.trigger('mouseenter');
}
curr.menu = pmenu;
} else {
var prev = currButton.prevAll('.l-btn:first');
if (prev.length){
currButton.trigger('mouseleave');
prev.focus();
}
}
return false;
case 39: // right
if (item.length && item[0].submenu){
curr.menu = $(item[0].submenu);
curr.button = currButton[0];
curr.menu.find('.menu-item:first').trigger('mouseenter');
} else {
var next = currButton.nextAll('.l-btn:first');
if (next.length){
currButton.trigger('mouseleave');
next.focus();
}
}
return false;
}
});
}
}
});
})(jQuery);
$(function(){
$.fn.menubutton.methods.enableNav();
$(document).keydown(function(e){
if (e.altKey && e.keyCode == 87){
$('#btn-home').focus();
}
})
});
</script>
</body>
</html>