1 if(!dojo._hasResource["dijit._base.manager"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dijit._base.manager"] = true;
3 dojo.provide("dijit._base.manager");
5 dojo.declare("dijit.WidgetSet", null, {
7 // A set of widgets indexed by id
9 constructor: function(){
13 add: function(/*Widget*/ widget){
14 if(this._hash[widget.id]){
15 throw new Error("Tried to register widget with id==" + widget.id + " but that id is already registered");
17 this._hash[widget.id]=widget;
20 remove: function(/*String*/ id){
21 delete this._hash[id];
24 forEach: function(/*Function*/ func){
25 for(var id in this._hash){
30 filter: function(/*Function*/ filter){
31 var res = new dijit.WidgetSet();
32 this.forEach(function(widget){
33 if(filter(widget)){ res.add(widget); }
35 return res; // dijit.WidgetSet
38 byId: function(/*String*/ id){
39 return this._hash[id];
42 byClass: function(/*String*/ cls){
43 return this.filter(function(widget){ return widget.declaredClass==cls; }); // dijit.WidgetSet
49 // summary: A list of widgets on a page.
50 // description: Is an instance of dijit.WidgetSet
53 dijit.registry = new dijit.WidgetSet();
55 dijit._widgetTypeCtr = {};
57 dijit.getUniqueId = function(/*String*/widgetType){
59 // Generates a unique id for a given widgetType
63 id = widgetType + "_" +
64 (widgetType in dijit._widgetTypeCtr ?
65 ++dijit._widgetTypeCtr[widgetType] : dijit._widgetTypeCtr[widgetType] = 0);
66 }while(dijit.byId(id));
72 // Only run this for IE because we think it's only necessary in that case,
73 // and because it causes problems on FF. See bug #3531 for details.
74 dojo.addOnUnload(function(){
75 dijit.registry.forEach(function(widget){ widget.destroy(); });
79 dijit.byId = function(/*String|Widget*/id){
81 // Returns a widget by its id, or if passed a widget, no-op (like dojo.byId())
82 return (dojo.isString(id)) ? dijit.registry.byId(id) : id; // Widget
85 dijit.byNode = function(/* DOMNode */ node){
87 // Returns the widget as referenced by node
88 return dijit.registry.byId(node.getAttribute("widgetId")); // Widget
91 dijit.getEnclosingWidget = function(/* DOMNode */ node){
93 // Returns the widget whose dom tree contains node or null if
94 // the node is not contained within the dom tree of any widget
96 if(node.getAttribute && node.getAttribute("widgetId")){
97 return dijit.registry.byId(node.getAttribute("widgetId"));
99 node = node.parentNode;
104 // elements that are tab-navigable if they have no tabindex value set
105 // (except for "a", which must have an href attribute)
106 dijit._tabElements = {
115 dijit._isElementShown = function(/*Element*/elem){
116 var style = dojo.style(elem);
117 return (style.visibility != "hidden")
118 && (style.visibility != "collapsed")
119 && (style.display != "none");
122 dijit.isTabNavigable = function(/*Element*/elem){
124 // Tests if an element is tab-navigable
125 if(dojo.hasAttr(elem, "disabled")){ return false; }
126 var hasTabindex = dojo.hasAttr(elem, "tabindex");
127 var tabindex = dojo.attr(elem, "tabindex");
128 if(hasTabindex && tabindex >= 0) {
129 return true; // boolean
131 var name = elem.nodeName.toLowerCase();
132 if(((name == "a" && dojo.hasAttr(elem, "href"))
133 || dijit._tabElements[name])
134 && (!hasTabindex || tabindex >= 0)){
135 return true; // boolean
137 return false; // boolean
140 dijit._getTabNavigable = function(/*DOMNode*/root){
142 // Finds the following descendants of the specified root node:
143 // * the first tab-navigable element in document order
144 // without a tabindex or with tabindex="0"
145 // * the last tab-navigable element in document order
146 // without a tabindex or with tabindex="0"
147 // * the first element in document order with the lowest
148 // positive tabindex value
149 // * the last element in document order with the highest
150 // positive tabindex value
151 var first, last, lowest, lowestTabindex, highest, highestTabindex;
152 var walkTree = function(/*DOMNode*/parent){
153 dojo.query("> *", parent).forEach(function(child){
154 var isShown = dijit._isElementShown(child);
155 if(isShown && dijit.isTabNavigable(child)){
156 var tabindex = dojo.attr(child, "tabindex");
157 if(!dojo.hasAttr(child, "tabindex") || tabindex == 0){
158 if(!first){ first = child; }
160 }else if(tabindex > 0){
161 if(!lowest || tabindex < lowestTabindex){
162 lowestTabindex = tabindex;
165 if(!highest || tabindex >= highestTabindex){
166 highestTabindex = tabindex;
171 if(isShown){ walkTree(child) }
174 if(dijit._isElementShown(root)){ walkTree(root) }
175 return { first: first, last: last, lowest: lowest, highest: highest };
178 dijit.getFirstInTabbingOrder = function(/*String|DOMNode*/root){
180 // Finds the descendant of the specified root node
181 // that is first in the tabbing order
182 var elems = dijit._getTabNavigable(dojo.byId(root));
183 return elems.lowest ? elems.lowest : elems.first; // Element
186 dijit.getLastInTabbingOrder = function(/*String|DOMNode*/root){
188 // Finds the descendant of the specified root node
189 // that is last in the tabbing order
190 var elems = dijit._getTabNavigable(dojo.byId(root));
191 return elems.last ? elems.last : elems.highest; // Element