3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
16 * @class Ext.view.BoundListKeyNav
17 * @extends Ext.util.KeyNav
18 * A specialized {@link Ext.util.KeyNav} implementation for navigating a {@link Ext.view.BoundList} using
19 * the keyboard. The up, down, pageup, pagedown, home, and end keys move the active highlight
20 * through the list. The enter key invokes the selection model's select action using the highlighted item.
22 Ext.define('Ext.view.BoundListKeyNav', {
23 extend: 'Ext.util.KeyNav',
24 requires: 'Ext.view.BoundList',
27 * @cfg {Ext.view.BoundList} boundList
29 * The {@link Ext.view.BoundList} instance for which key navigation will be managed. This is required.
32 constructor: function(el, config) {
34 me.boundList = config.boundList;
35 me.callParent([el, Ext.apply({}, config, me.defaultHandlers)]);
41 boundList = me.boundList,
42 allItems = boundList.all,
43 oldItem = boundList.highlightedItem,
44 oldItemIdx = oldItem ? boundList.indexOf(oldItem) : -1,
45 newItemIdx = oldItemIdx > 0 ? oldItemIdx - 1 : allItems.getCount() - 1; //wraps around
46 me.highlightAt(newItemIdx);
51 boundList = me.boundList,
52 allItems = boundList.all,
53 oldItem = boundList.highlightedItem,
54 oldItemIdx = oldItem ? boundList.indexOf(oldItem) : -1,
55 newItemIdx = oldItemIdx < allItems.getCount() - 1 ? oldItemIdx + 1 : 0; //wraps around
56 me.highlightAt(newItemIdx);
63 pagedown: function() {
73 me.highlightAt(me.boundList.all.getCount() - 1);
77 this.selectHighlighted(e);
82 * Highlights the item at the given index.
83 * @param {Number} index
85 highlightAt: function(index) {
86 var boundList = this.boundList,
87 item = boundList.all.item(index);
90 boundList.highlightItem(item);
91 boundList.getTargetEl().scrollChildIntoView(item, false);
96 * Triggers selection of the currently highlighted item according to the behavior of
97 * the configured SelectionModel.
99 selectHighlighted: function(e) {
101 boundList = me.boundList,
102 highlighted = boundList.highlightedItem,
103 selModel = boundList.getSelectionModel();
105 selModel.selectWithEvent(boundList.getRecord(highlighted), e);