]> git.wh0rd.org Git - tt-rss.git/blob - lib/dijit/form/DataList.js.uncompressed.js
update dojo to 1.7.3
[tt-rss.git] / lib / dijit / form / DataList.js.uncompressed.js
1 define("dijit/form/DataList", [
2         "dojo/_base/declare", // declare
3         "dojo/dom", // dom.byId
4         "dojo/_base/lang", // lang.trim
5         "dojo/query", // query
6         "dojo/store/Memory", // dojo.store.Memory
7         "../registry"   // registry.add registry.remove
8 ], function(declare, dom, lang, query, MemoryStore, registry){
9
10         // module:
11         //              dijit/form/DataList
12         // summary:
13         //              Inefficient but small data store specialized for inlined data via OPTION tags
14
15         function toItem(/*DOMNode*/ option){
16                 // summary:
17                 //              Convert <option> node to hash
18                 return {
19                         id: option.value,
20                         value: option.value,
21                         name: lang.trim(option.innerText || option.textContent || '')
22                 };
23         }
24
25         return declare("dijit.form.DataList", MemoryStore, {
26                 // summary:
27                 //              Inefficient but small data store specialized for inlined data via OPTION tags
28                 //
29                 // description:
30                 //              Provides a store for inlined data like:
31                 //
32                 //      |       <datalist>
33                 //      |               <option value="AL">Alabama</option>
34                 //      |               ...
35
36                 constructor: function(/*Object?*/ params, /*DomNode|String*/ srcNodeRef){
37                         // store pointer to original DOM tree
38                         this.domNode = dom.byId(srcNodeRef);
39
40                         lang.mixin(this, params);
41                         if(this.id){
42                                 registry.add(this); // add to registry so it can be easily found by id
43                         }
44                         this.domNode.style.display = "none";
45
46                         this.inherited(arguments, [{
47                                 data: query("option", this.domNode).map(toItem)
48                         }]);
49                 },
50
51                 destroy: function(){
52                         registry.remove(this.id);
53                 },
54
55                 fetchSelectedItem: function(){
56                         // summary:
57                         //              Get the option marked as selected, like `<option selected>`.
58                         //              Not part of dojo.data API.
59                         var option = query("> option[selected]", this.domNode)[0] || query("> option", this.domNode)[0];
60                         return option && toItem(option);
61                 }
62         });
63 });