Debian Codegraph @

dijit/form/_ListBase.js

raw symbols SCIP
1 define([
2 "dojo/_base/declare", // declare
3 "dojo/on",
4 "dojo/window" // winUtils.scrollIntoView
5 ], function(declare, on, winUtils){
6
7 // module:
8 // dijit/form/_ListBase
9
10 return declare("dijit.form._ListBase", null, {
11 // summary:
12 // Focus-less menu to handle UI events consistently.
13 // Abstract methods that must be defined externally:
14 //
15 // - onSelect: item is active (mousedown but not yet mouseup, or keyboard arrow selected but no Enter)
16 // - onDeselect: cancels onSelect
17 // tags:
18 // private
19
20 // selected: DOMNode
21 // currently selected node
22 selected: null,
23
24 _listConnect: function(/*String|Function*/ eventType, /*String*/ callbackFuncName){
25 // summary:
26 // Connects 'containerNode' to specified method of this object
27 // and automatically registers for 'disconnect' on widget destroy.
28 // description:
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.
33 // returns:
34 // A handle that can be passed to `disconnect` in order to disconnect
35 // before the widget is destroyed.
36 // tags:
37 // private
38
39 var self = this;
40 return self.own(on(self.containerNode,
41 on.selector(
42 function(eventTarget, selector, target){
43 return eventTarget.parentNode == target;
44 },
45 eventType
46 ),
47 function(evt){
48 self[callbackFuncName](evt, this);
49 }
50 ));
51 },
52
53 selectFirstNode: function(){
54 // summary:
55 // Select the first displayed item in the list.
56 var first = this.containerNode.firstChild;
57 while(first && first.style.display == "none"){
58 first = first.nextSibling;
59 }
60 this._setSelectedAttr(first, true);
61 },
62
63 selectLastNode: function(){
64 // summary:
65 // Select the last displayed item in the list
66 var last = this.containerNode.lastChild;
67 while(last && last.style.display == "none"){
68 last = last.previousSibling;
69 }
70 this._setSelectedAttr(last, true);
71 },
72
73 selectNextNode: function(){
74 // summary:
75 // Select the item just below the current selection.
76 // If nothing selected, select first node.
77 var selectedNode = this.selected;
78 if(!selectedNode){
79 this.selectFirstNode();
80 }else{
81 var next = selectedNode.nextSibling;
82 while(next && next.style.display == "none"){
83 next = next.nextSibling;
84 }
85 if(!next){
86 this.selectFirstNode();
87 }else{
88 this._setSelectedAttr(next, true);
89 }
90 }
91 },
92
93 selectPreviousNode: function(){
94 // summary:
95 // Select the item just above the current selection.
96 // If nothing selected, select last node (if
97 // you select Previous and try to keep scrolling up the list).
98 var selectedNode = this.selected;
99 if(!selectedNode){
100 this.selectLastNode();
101 }else{
102 var prev = selectedNode.previousSibling;
103 while(prev && prev.style.display == "none"){
104 prev = prev.previousSibling;
105 }
106 if(!prev){
107 this.selectLastNode();
108 }else{
109 this._setSelectedAttr(prev, true);
110 }
111 }
112 },
113
114 _setSelectedAttr: function(/*DomNode*/ node, /*Boolean*/ scroll){
115 // summary:
116 // Does the actual select.
117 // node:
118 // The option to select
119 // scroll:
120 // If necessary, scroll node into view. Set to false for mouse/touch to
121 // avoid jumping problems on mobile/RTL, see https://bugs.dojotoolkit.org/ticket/17739.
122 if(this.selected != node){
123 var selectedNode = this.selected;
124 if(selectedNode){
125 this.onDeselect(selectedNode);
126 }
127 if(node){
128 if(scroll){
129 winUtils.scrollIntoView(node);
130 }
131 this.onSelect(node);
132 }
133 this._set("selected", node);
134 }else if(node){
135 this.onSelect(node);
136 }
137 }
138 });
139 });