]>
git.wh0rd.org - tt-rss.git/blob - 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
){
11 // dijit/form/_ComboBoxMenuMixin
13 // Focus-less menu for internal use in `dijit.form.ComboBox`
15 return declare( "dijit.form._ComboBoxMenuMixin", null, {
17 // Focus-less menu for internal use in `dijit.form.ComboBox`
22 // Holds "next" and "previous" text for paging buttons on drop down
25 postMixInProperties: function(){
26 this.inherited(arguments
);
27 this._messages
= i18n
.getLocalization("dijit.form", "ComboBox", this.lang
);
30 buildRendering: function(){
31 this.inherited(arguments
);
33 // fill in template with i18n messages
34 this.previousButton
.innerHTML
= this._messages
["previousMessage"];
35 this.nextButton
.innerHTML
= this._messages
["nextMessage"];
38 _setValueAttr: function(/*Object*/ value
){
43 onClick: function(/*DomNode*/ node
){
44 if(node
== this.previousButton
){
45 this._setSelectedAttr(null);
47 }else if(node
== this.nextButton
){
48 this._setSelectedAttr(null);
56 onChange: function(/*Number*/ /*===== direction =====*/){
58 // Notifies ComboBox/FilteringSelect that user selected an option.
63 onPage: function(/*Number*/ /*===== direction =====*/){
65 // Notifies ComboBox/FilteringSelect that user clicked to advance to next/previous page.
72 // Callback from dijit.popup code to this widget, notifying it that it closed
75 this._setSelectedAttr(null);
78 _createOption: function(/*Object*/ item
, labelFunc
){
80 // Creates an option to appear on the popup menu subclassed by
81 // `dijit.form.FilteringSelect`.
83 var menuitem
= this._createMenuItem();
84 var labelObject
= labelFunc(item
);
86 menuitem
.innerHTML
= labelObject
.label
;
89 win
.doc
.createTextNode(labelObject
.label
)
92 // #3250: in blank options, assign a normal height
93 if(menuitem
.innerHTML
== ""){
94 menuitem
.innerHTML
= " "; //
97 // update menuitem.dir if BidiSupport was required
98 this.applyTextDir(menuitem
, (menuitem
.innerText
|| menuitem
.textContent
|| ""));
104 createOptions: function(results
, options
, labelFunc
){
106 // Fills in the items in the drop down list
110 // The options to the query function of the store
113 // Function to produce a label in the drop down list from a dojo.data item
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
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
);
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
){
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
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.
145 this.nextButton
.style
.display
= displayMore
? "" : "none";
146 domAttr
.set(this.nextButton
,"id", this.id
+ "_next");
147 return this.containerNode
.childNodes
;
150 clearResultList: function(){
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]);
157 this._setSelectedAttr(null);
160 highlightFirstOption: function(){
162 // Highlight the first real item in the list (not Previous Choices).
163 this.selectFirstNode();
166 highlightLastOption: function(){
168 // Highlight the last real item in the list (not More Choices).
169 this.selectLastNode();
172 selectFirstNode: function(){
173 this.inherited(arguments
);
174 if(this.getHighlightedOption() == this.previousButton
){
175 this.selectNextNode();
179 selectLastNode: function(){
180 this.inherited(arguments
);
181 if(this.getHighlightedOption() == this.nextButton
){
182 this.selectPreviousNode();
186 getHighlightedOption: function(){
187 return this._getSelectedAttr();