BoundListKeyNav.html
3.72 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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The source code</title>
<link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../resources/prettify/prettify.js"></script>
<style type="text/css">
.highlight { display: block; background-color: #ddd; }
</style>
<script type="text/javascript">
function highlight() {
document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
}
</script>
</head>
<body onload="prettyPrint(); highlight();">
<pre class="prettyprint lang-js"><span id='Ext-view-BoundListKeyNav'>/**
</span> * A specialized {@link Ext.util.KeyNav} implementation for navigating a {@link Ext.view.BoundList} using
* the keyboard. The up, down, pageup, pagedown, home, and end keys move the active highlight
* through the list. The enter key invokes the selection model's select action using the highlighted item.
*/
Ext.define('Ext.view.BoundListKeyNav', {
extend: 'Ext.util.KeyNav',
requires: 'Ext.view.BoundList',
<span id='Ext-view-BoundListKeyNav-cfg-boundList'> /**
</span> * @cfg {Ext.view.BoundList} boundList (required)
* The {@link Ext.view.BoundList} instance for which key navigation will be managed.
*/
constructor: function(el, config) {
var me = this;
me.boundList = config.boundList;
me.callParent([el, Ext.apply({}, config, me.defaultHandlers)]);
},
defaultHandlers: {
up: function() {
var me = this,
boundList = me.boundList,
allItems = boundList.all,
oldItem = boundList.highlightedItem,
oldItemIdx = oldItem ? boundList.indexOf(oldItem) : -1,
newItemIdx = oldItemIdx > 0 ? oldItemIdx - 1 : allItems.getCount() - 1; //wraps around
me.highlightAt(newItemIdx);
},
down: function() {
var me = this,
boundList = me.boundList,
allItems = boundList.all,
oldItem = boundList.highlightedItem,
oldItemIdx = oldItem ? boundList.indexOf(oldItem) : -1,
newItemIdx = oldItemIdx < allItems.getCount() - 1 ? oldItemIdx + 1 : 0; //wraps around
me.highlightAt(newItemIdx);
},
pageup: function() {
//TODO
},
pagedown: function() {
//TODO
},
home: function() {
this.highlightAt(0);
},
end: function() {
var me = this;
me.highlightAt(me.boundList.all.getCount() - 1);
},
enter: function(e) {
this.selectHighlighted(e);
}
},
<span id='Ext-view-BoundListKeyNav-method-highlightAt'> /**
</span> * Highlights the item at the given index.
* @param {Number} index
*/
highlightAt: function(index) {
var boundList = this.boundList,
item = boundList.all.item(index);
if (item) {
item = item.dom;
boundList.highlightItem(item);
boundList.getTargetEl().scrollChildIntoView(item, false);
}
},
<span id='Ext-view-BoundListKeyNav-method-selectHighlighted'> /**
</span> * Triggers selection of the currently highlighted item according to the behavior of
* the configured SelectionModel.
*/
selectHighlighted: function(e) {
var me = this,
boundList = me.boundList,
highlighted = boundList.highlightedItem,
selModel = boundList.getSelectionModel();
if (highlighted) {
selModel.selectWithEvent(boundList.getRecord(highlighted), e);
}
}
});</pre>
</body>
</html>