1 define("dijit/form/_ListBase", [
2 "dojo/_base/declare", // declare
4 "dojo/window" // winUtils.scrollIntoView
5 ], function(declare, on, winUtils){
8 // dijit/form/_ListBase
10 return declare( "dijit.form._ListBase", null, {
12 // Focus-less menu to handle UI events consistently
13 // Abstract methods that must be defined externally:
15 // - onSelect: item is active (mousedown but not yet mouseup, or keyboard arrow selected but no Enter)
16 // - onDeselect: cancels onSelect
21 // currently selected node
24 _listConnect: function(/*String|Function*/ eventType, /*String*/ callbackFuncName){
26 // Connects 'containerNode' to specified method of this object
27 // and automatically registers for 'disconnect' on widget destroy.
29 // Provide widget-specific analog to 'connect'.
30 // The callback function is called with the normal event object,
31 // but also a second parameter is passed that indicates which list item
32 // actually received the event.
34 // A handle that can be passed to `disconnect` in order to disconnect
35 // before the widget is destroyed.
40 return self.own(on(self.containerNode,
42 function(eventTarget, selector, target){
43 return eventTarget.parentNode == target;
49 self[callbackFuncName](evt, this);
54 selectFirstNode: function(){
56 // Select the first displayed item in the list.
57 var first = this.containerNode.firstChild;
58 while(first && first.style.display == "none"){
59 first = first.nextSibling;
61 this._setSelectedAttr(first);
64 selectLastNode: function(){
66 // Select the last displayed item in the list
67 var last = this.containerNode.lastChild;
68 while(last && last.style.display == "none"){
69 last = last.previousSibling;
71 this._setSelectedAttr(last);
74 selectNextNode: function(){
76 // Select the item just below the current selection.
77 // If nothing selected, select first node.
78 var selectedNode = this.selected;
80 this.selectFirstNode();
82 var next = selectedNode.nextSibling;
83 while(next && next.style.display == "none"){
84 next = next.nextSibling;
87 this.selectFirstNode();
89 this._setSelectedAttr(next);
94 selectPreviousNode: function(){
96 // Select the item just above the current selection.
97 // If nothing selected, select last node (if
98 // you select Previous and try to keep scrolling up the list).
99 var selectedNode = this.selected;
101 this.selectLastNode();
103 var prev = selectedNode.previousSibling;
104 while(prev && prev.style.display == "none"){
105 prev = prev.previousSibling;
108 this.selectLastNode();
110 this._setSelectedAttr(prev);
115 _setSelectedAttr: function(/*DomNode*/ node){
117 // Does the actual select.
118 if(this.selected != node){
119 var selectedNode = this.selected;
121 this.onDeselect(selectedNode);
122 this.selected = null;
125 this.selected = node;
126 winUtils.scrollIntoView(node);