forked from cocoo/easyui-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu.html
318 lines (299 loc) · 13.2 KB
/
menu.html
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>menu</title>
<link rel="stylesheet" type="text/css" href="css/main.css" />
<link rel="stylesheet" type="text/css" href="css/SyntaxHighlighter.css" />
<script type="text/javascript" src="js/shCore.js"></script>
<script type="text/javascript" src="js/shBrushJScript.js"></script>
<script type="text/javascript" src="js/shBrushXml.js"></script>
</head>
<body style="text-align:left">
<div style="padding:10px">
<h3>Menu</h3>
<p>Override defaults with $.fn.menu.defaults.</p>
<p>
The menu is usually used for context menus. It is the base component for building other menu component such as menubutton and splitbutton.
It also can be used for both navigation and executing commands.
</p>
<img src="images/menu.png">
<h4>Usage Example</h4>
<h5>Create Menu</h5>
<p>
Create menu via markup should add 'easyui-menu' class to <div/> markup.
Each menu item is created via <div/> markup.
We can add 'iconCls' attribute to menu item to define a icon that will display on left of menu item.
Add 'menu-sep' class to menu item will generate a menu seperator.
</p>
<div class="dp-highlighter"><div class="bar"><div class="tools"></div></div><ol start="1" class="dp-xml"><li class="alt"><span><span class="tag"><</span><span class="tag-name">div</span><span> </span><span class="attribute">id</span><span>=</span><span class="attribute-value">"mm"</span><span> </span><span class="attribute">class</span><span>=</span><span class="attribute-value">"easyui-menu"</span><span> </span><span class="attribute">style</span><span>=</span><span class="attribute-value">"width:120px;"</span><span class="tag">></span><span> </span></span></li><li class=""><span> <span class="tag"><</span><span class="tag-name">div</span><span class="tag">></span><span>New</span><span class="tag"></</span><span class="tag-name">div</span><span class="tag">></span><span> </span></span></li><li class="alt"><span> <span class="tag"><</span><span class="tag-name">div</span><span class="tag">></span><span> </span></span></li><li class=""><span> <span class="tag"><</span><span class="tag-name">span</span><span class="tag">></span><span>Open</span><span class="tag"></</span><span class="tag-name">span</span><span class="tag">></span><span> </span></span></li><li class="alt"><span> <span class="tag"><</span><span class="tag-name">div</span><span> </span><span class="attribute">style</span><span>=</span><span class="attribute-value">"width:150px;"</span><span class="tag">></span><span> </span></span></li><li class=""><span> <span class="tag"><</span><span class="tag-name">div</span><span class="tag">></span><span class="tag"><</span><span class="tag-name">b</span><span class="tag">></span><span>Word</span><span class="tag"></</span><span class="tag-name">b</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">div</span><span class="tag">></span><span> </span></span></li><li class="alt"><span> <span class="tag"><</span><span class="tag-name">div</span><span class="tag">></span><span>Excel</span><span class="tag"></</span><span class="tag-name">div</span><span class="tag">></span><span> </span></span></li><li class=""><span> <span class="tag"><</span><span class="tag-name">div</span><span class="tag">></span><span>PowerPoint</span><span class="tag"></</span><span class="tag-name">div</span><span class="tag">></span><span> </span></span></li><li class="alt"><span> <span class="tag"></</span><span class="tag-name">div</span><span class="tag">></span><span> </span></span></li><li class=""><span> <span class="tag"></</span><span class="tag-name">div</span><span class="tag">></span><span> </span></span></li><li class="alt"><span> <span class="tag"><</span><span class="tag-name">div</span><span> </span><span class="attribute">data-options</span><span>=</span><span class="attribute-value">"iconCls:'icon-save'"</span><span class="tag">></span><span>Save</span><span class="tag"></</span><span class="tag-name">div</span><span class="tag">></span><span> </span></span></li><li class=""><span> <span class="tag"><</span><span class="tag-name">div</span><span> </span><span class="attribute">class</span><span>=</span><span class="attribute-value">"menu-sep"</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">div</span><span class="tag">></span><span> </span></span></li><li class="alt"><span> <span class="tag"><</span><span class="tag-name">div</span><span class="tag">></span><span>Exit</span><span class="tag"></</span><span class="tag-name">div</span><span class="tag">></span><span> </span></span></li><li class=""><span><span class="tag"></</span><span class="tag-name">div</span><span class="tag">></span><span> </span></span></li></ol></div><textarea class="html" name="code-menu" style="display: none;"> <div id="mm" class="easyui-menu" style="width:120px;">
<div>New</div>
<div>
<span>Open</span>
<div style="width:150px;">
<div><b>Word</b></div>
<div>Excel</div>
<div>PowerPoint</div>
</div>
</div>
<div data-options="iconCls:'icon-save'">Save</div>
<div class="menu-sep"></div>
<div>Exit</div>
</div>
</textarea>
<p>Create menu programatically and listening the 'onClick' event.</p>
<div class="dp-highlighter"><div class="bar"><div class="tools"></div></div><ol start="1" class="dp-c"><li class="alt"><span><span>$(</span><span class="string">'#mm'</span><span>).menu({ </span></span></li><li class=""><span> onClick:<span class="keyword">function</span><span>(item){ </span></span></li><li class="alt"><span> <span class="comment">//...</span><span> </span></span></li><li class=""><span> } </span></li><li class="alt"><span>}); </span></li></ol></div><textarea class="js" name="code-menu" style="display: none;"> $('#mm').menu({
onClick:function(item){
//...
}
});
</textarea>
<br>
<h5>Show Menu</h5>
<p>When menu is created, it's hidden and not visible. Call 'show' method to display menu.</p>
<div class="dp-highlighter"><div class="bar"><div class="tools"></div></div><ol start="1" class="dp-c"><li class="alt"><span><span>$(</span><span class="string">'#mm'</span><span>).menu(</span><span class="string">'show'</span><span>, { </span></span></li><li class=""><span> left: 200, </span></li><li class="alt"><span> top: 100 </span></li><li class=""><span>}); </span></li></ol></div><textarea class="js" name="code-menu" style="display: none;"> $('#mm').menu('show', {
left: 200,
top: 100
});
</textarea>
<p> </p>
<h4>Menu Item</h4>
<p>
The menu item represents an individual item that is displayed within a menu.
It contains the following properties:
</p>
<table class="doc-table">
<tbody><tr>
<th><strong>Name</strong></th>
<th><strong>Type</strong></th>
<th><strong>Description</strong></th>
<th><strong>Default</strong></th>
</tr>
<tr>
<td>id</td>
<td>string</td>
<td>The id attribute of menu item.</td>
<td></td>
</tr>
<tr>
<td>text</td>
<td>string</td>
<td>The item text.</td>
<td></td>
</tr>
<tr>
<td>iconCls</td>
<td>string</td>
<td>A CSS class to display a 16x16 icon on item left.</td>
<td></td>
</tr>
<tr>
<td>href</td>
<td>string</td>
<td>Set page location while clicking the menu item.</td>
<td></td>
</tr>
<tr>
<td>disabled</td>
<td>boolean</td>
<td>Defines if to disable the menu item.</td>
<td>false</td>
</tr>
<tr>
<td>onclick</td>
<td>function</td>
<td>The function to be called while clicking the menu item.</td>
<td></td>
</tr>
</tbody></table>
<h4>Menu Properties</h4>
<table class="doc-table">
<tbody><tr>
<th><strong>Name</strong></th>
<th><strong>Type</strong></th>
<th><strong>Description</strong></th>
<th><strong>Default</strong></th>
</tr>
<tr>
<td>zIndex</td>
<td>number</td>
<td>Menu z-index style,increase from it.</td>
<td>110000</td>
</tr>
<tr>
<td>left</td>
<td>number</td>
<td>Menu left position.</td>
<td>0</td>
</tr>
<tr>
<td>top</td>
<td>number</td>
<td>Menu top position.</td>
<td>0</td>
</tr>
</tbody></table>
<h4>Menu Events</h4>
<table class="doc-table">
<tbody><tr>
<th><strong>Name</strong></th>
<th><strong>Parameters</strong></th>
<th><strong>Description</strong></th>
</tr>
<tr>
<td>onShow</td>
<td>none</td>
<td>Fires after menu is showed.</td>
</tr>
<tr>
<td>onHide</td>
<td>none</td>
<td>Fires after menu is hidden.</td>
</tr>
<tr>
<td>onClick</td>
<td>item</td>
<td>
Fires when the menu item is clicked.
The example below shows how to process all menu item clicking:
<pre><div class="easyui-menu" data-options="onClick:menuHandler" style="width:120px;">
<div data-options="name:'new'">New</div>
<div data-options="name:'save',iconCls:'icon-save'">Save</div>
<div data-options="name:'print',iconCls:'icon-print'">Print</div>
<div class="menu-sep"></div>
<div data-options="name:'exit'">Exit</div>
</div>
<script type="text/javascript">
function menuHandler(item){
alert(item.name)
}
</script>
</pre>
</td>
</tr>
</tbody></table>
<h4>Menu Methods</h4>
<table class="doc-table">
<tbody><tr>
<th><strong>Name</strong></th>
<th><strong>Parameter</strong></th>
<th><strong>Description</strong></th>
</tr>
<tr>
<td>show</td>
<td>pos</td>
<td>Show a menu on specified position.<br>
pos parameter have two properties:<br>
left: the new left position.<br>
top: the new top position.<br></td>
</tr>
<tr>
<td>hide</td>
<td>none</td>
<td>Hide a menu.</td>
</tr>
<tr>
<td>getItem</td>
<td>itemEl</td>
<td>
Get the menu item properties that include a 'target' property indicating the item DOM element.
The example below shows how to get the specified item by id:
<pre><div id="mm" class="easyui-menu" style="width:120px">
<div>New</div>
<div id="m-open">Open</div>
<div>Save</div>
</div>
</pre>
<pre>var itemEl = $('#m-open')[0]; // the menu item element
var item = $('#mm').menu('getItem', itemEl);
console.log(item);
</pre>
</td>
</tr>
<tr>
<td>setText</td>
<td>param</td>
<td>
Set the specified menu item text. The 'param' parameter contains two properties:<br>
target: DOM object, the menu item to be setted.<br>
text: string, the new text value.
<p>Code example:</p>
<pre>var item = $('#mm').menu('findItem', 'Save');
$('#mm').menu('setText', {
target: item.target,
text: 'Saving'
});
</pre>
</td>
</tr>
<tr>
<td>setIcon</td>
<td>param</td>
<td>
Set the specified menu item icon. The 'param' parameter contains two properties:<br>
target: DOM object, the menu item.<br>
iconCls: the new icon class.
<p>Code example:</p>
<pre>$('#mm').menu('setIcon', {
target: $('#m-open')[0],
iconCls: 'icon-closed'
});
</pre>
</td>
</tr>
<tr>
<td>findItem</td>
<td>text</td>
<td>
Find the specified menu item, the return object is same as the getItem method.
<p>Code example:</p>
<pre>// find 'Open' item and disable it
var item = $('#mm').menu('findItem', 'Open');
$('#mm').menu('disableItem', item.target);
</pre>
</td>
</tr>
<tr>
<td>appendItem</td>
<td>options</td>
<td>
Append a new menu item, the 'options' parameter indicate the new item properties.
By default the added item will become a top menu item.
To append a sub menu item, a 'parent' property should be set to specify the parent item element that already has sub items.
<p>Code example:</p>
<pre>// append a top menu item
$('#mm').menu('appendItem', {
text: 'New Item',
iconCls: 'icon-ok',
onclick: function(){alert('New Item')}
});
</pre>
<pre>// append a sub menu item
var item = $('#mm').menu('findItem', 'Open'); // find 'Open' item
$('#mm').menu('appendItem', {
parent: item.target, // the parent item element
text: 'Open Excel',
iconCls: 'icon-excel',
onclick: function(){alert('Open Excel')}
});
</pre>
</td>
</tr>
<tr>
<td>removeItem</td>
<td>itemEl</td>
<td>Remove the specified menu item.</td>
</tr>
<tr>
<td>enableItem</td>
<td>itemEl</td>
<td>Enable the menu item.</td>
</tr>
<tr>
<td>disableItem</td>
<td>itemEl</td>
<td>Disable the menu item.</td>
</tr>
</tbody></table>
</div>
</body>
</html>