]> git.wh0rd.org - tt-rss.git/blob - lib/dijit/form/_ComboBoxMenuMixin.js.uncompressed.js
update dojo to 1.7.3
[tt-rss.git] / lib / dijit / form / _ComboBoxMenuMixin.js.uncompressed.js
1 define("dijit/form/_ComboBoxMenuMixin", [
2 "dojo/_base/array", // array.forEach
3 "dojo/_base/declare", // declare
4 "dojo/dom-attr", // domAttr.set
5 "dojo/i18n", // i18n.getLocalization
6 "dojo/_base/window", // win.doc.createTextNode
7 "dojo/i18n!./nls/ComboBox"
8 ], function(array, declare, domAttr, i18n, win){
9
10 // module:
11 // dijit/form/_ComboBoxMenuMixin
12 // summary:
13 // Focus-less menu for internal use in `dijit.form.ComboBox`
14
15 return declare( "dijit.form._ComboBoxMenuMixin", null, {
16 // summary:
17 // Focus-less menu for internal use in `dijit.form.ComboBox`
18 // tags:
19 // private
20
21 // _messages: Object
22 // Holds "next" and "previous" text for paging buttons on drop down
23 _messages: null,
24
25 postMixInProperties: function(){
26 this.inherited(arguments);
27 this._messages = i18n.getLocalization("dijit.form", "ComboBox", this.lang);
28 },
29
30 buildRendering: function(){
31 this.inherited(arguments);
32
33 // fill in template with i18n messages
34 this.previousButton.innerHTML = this._messages["previousMessage"];
35 this.nextButton.innerHTML = this._messages["nextMessage"];
36 },
37
38 _setValueAttr: function(/*Object*/ value){
39 this.value = value;
40 this.onChange(value);
41 },
42
43 onClick: function(/*DomNode*/ node){
44 if(node == this.previousButton){
45 this._setSelectedAttr(null);
46 this.onPage(-1);
47 }else if(node == this.nextButton){
48 this._setSelectedAttr(null);
49 this.onPage(1);
50 }else{
51 this.onChange(node);
52 }
53 },
54
55 // stubs
56 onChange: function(/*Number*/ /*===== direction =====*/){
57 // summary:
58 // Notifies ComboBox/FilteringSelect that user selected an option.
59 // tags:
60 // callback
61 },
62
63 onPage: function(/*Number*/ /*===== direction =====*/){
64 // summary:
65 // Notifies ComboBox/FilteringSelect that user clicked to advance to next/previous page.
66 // tags:
67 // callback
68 },
69
70 onClose: function(){
71 // summary:
72 // Callback from dijit.popup code to this widget, notifying it that it closed
73 // tags:
74 // private
75 this._setSelectedAttr(null);
76 },
77
78 _createOption: function(/*Object*/ item, labelFunc){
79 // summary:
80 // Creates an option to appear on the popup menu subclassed by
81 // `dijit.form.FilteringSelect`.
82
83 var menuitem = this._createMenuItem();
84 var labelObject = labelFunc(item);
85 if(labelObject.html){
86 menuitem.innerHTML = labelObject.label;
87 }else{
88 menuitem.appendChild(
89 win.doc.createTextNode(labelObject.label)
90 );
91 }
92 // #3250: in blank options, assign a normal height
93 if(menuitem.innerHTML == ""){
94 menuitem.innerHTML = " "; //  
95 }
96
97 // update menuitem.dir if BidiSupport was required
98 this.applyTextDir(menuitem, (menuitem.innerText || menuitem.textContent || ""));
99
100 menuitem.item=item;
101 return menuitem;
102 },
103
104 createOptions: function(results, options, labelFunc){
105 // summary:
106 // Fills in the items in the drop down list
107 // results:
108 // Array of items
109 // options:
110 // The options to the query function of the store
111 //
112 // labelFunc:
113 // Function to produce a label in the drop down list from a dojo.data item
114
115 // display "Previous . . ." button
116 this.previousButton.style.display = (options.start == 0) ? "none" : "";
117 domAttr.set(this.previousButton, "id", this.id + "_prev");
118 // create options using _createOption function defined by parent
119 // ComboBox (or FilteringSelect) class
120 // #2309:
121 // iterate over cache nondestructively
122 array.forEach(results, function(item, i){
123 var menuitem = this._createOption(item, labelFunc);
124 domAttr.set(menuitem, "id", this.id + i);
125 this.nextButton.parentNode.insertBefore(menuitem, this.nextButton);
126 }, this);
127 // display "Next . . ." button
128 var displayMore = false;
129 // Try to determine if we should show 'more'...
130 if(results.total && !results.total.then && results.total != -1){
131 if((options.start + options.count) < results.total){
132 displayMore = true;
133 }else if((options.start + options.count) > results.total && options.count == results.length){
134 // Weird return from a data store, where a start + count > maxOptions
135 // implies maxOptions isn't really valid and we have to go into faking it.
136 // And more or less assume more if count == results.length
137 displayMore = true;
138 }
139 }else if(options.count == results.length){
140 //Don't know the size, so we do the best we can based off count alone.
141 //So, if we have an exact match to count, assume more.
142 displayMore = true;
143 }
144
145 this.nextButton.style.display = displayMore ? "" : "none";
146 domAttr.set(this.nextButton,"id", this.id + "_next");
147 return this.containerNode.childNodes;
148 },
149
150 clearResultList: function(){
151 // summary:
152 // Clears the entries in the drop down list, but of course keeps the previous and next buttons.
153 var container = this.containerNode;
154 while(container.childNodes.length > 2){
155 container.removeChild(container.childNodes[container.childNodes.length-2]);
156 }
157 this._setSelectedAttr(null);
158 },
159
160 highlightFirstOption: function(){
161 // summary:
162 // Highlight the first real item in the list (not Previous Choices).
163 this.selectFirstNode();
164 },
165
166 highlightLastOption: function(){
167 // summary:
168 // Highlight the last real item in the list (not More Choices).
169 this.selectLastNode();
170 },
171
172 selectFirstNode: function(){
173 this.inherited(arguments);
174 if(this.getHighlightedOption() == this.previousButton){
175 this.selectNextNode();
176 }
177 },
178
179 selectLastNode: function(){
180 this.inherited(arguments);
181 if(this.getHighlightedOption() == this.nextButton){
182 this.selectPreviousNode();
183 }
184 },
185
186 getHighlightedOption: function(){
187 return this._getSelectedAttr();
188 }
189 });
190
191 });