Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2150 mathias 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");
4
 
5
dojo.declare("dijit.WidgetSet", null, {
6
	constructor: function(){
7
		// summary:
8
		//	A set of widgets indexed by id
9
		this._hash={};
10
	},
11
 
12
	add: function(/*Widget*/ widget){
13
		if(this._hash[widget.id]){
14
			throw new Error("Tried to register widget with id==" + widget.id + " but that id is already registered");
15
		}
16
		this._hash[widget.id]=widget;
17
	},
18
 
19
	remove: function(/*String*/ id){
20
		delete this._hash[id];
21
	},
22
 
23
	forEach: function(/*Function*/ func){
24
		for(var id in this._hash){
25
			func(this._hash[id]);
26
		}
27
	},
28
 
29
	filter: function(/*Function*/ filter){
30
		var res = new dijit.WidgetSet();
31
		this.forEach(function(widget){
32
			if(filter(widget)){ res.add(widget); }
33
		});
34
		return res;		// dijit.WidgetSet
35
	},
36
 
37
	byId: function(/*String*/ id){
38
		return this._hash[id];
39
	},
40
 
41
	byClass: function(/*String*/ cls){
42
		return this.filter(function(widget){ return widget.declaredClass==cls; });	// dijit.WidgetSet
43
	}
44
	});
45
 
46
// registry: list of all widgets on page
47
dijit.registry = new dijit.WidgetSet();
48
 
49
dijit._widgetTypeCtr = {};
50
 
51
dijit.getUniqueId = function(/*String*/widgetType){
52
	// summary
53
	//	Generates a unique id for a given widgetType
54
 
55
	var id;
56
	do{
57
		id = widgetType + "_" +
58
			(dijit._widgetTypeCtr[widgetType] !== undefined ?
59
				++dijit._widgetTypeCtr[widgetType] : dijit._widgetTypeCtr[widgetType] = 0);
60
	}while(dijit.byId(id));
61
	return id; // String
62
};
63
 
64
 
65
if(dojo.isIE){
66
	// Only run this for IE because we think it's only necessary in that case,
67
	// and because it causes problems on FF.  See bug #3531 for details.
68
	dojo.addOnUnload(function(){
69
		dijit.registry.forEach(function(widget){ widget.destroy(); });
70
	});
71
}
72
 
73
dijit.byId = function(/*String|Widget*/id){
74
	// summary:
75
	//		Returns a widget by its id, or if passed a widget, no-op (like dojo.byId())
76
	return (dojo.isString(id)) ? dijit.registry.byId(id) : id; // Widget
77
};
78
 
79
dijit.byNode = function(/* DOMNode */ node){
80
	// summary:
81
	//		Returns the widget as referenced by node
82
	return dijit.registry.byId(node.getAttribute("widgetId")); // Widget
83
};
84
 
85
dijit.getEnclosingWidget = function(/* DOMNode */ node){
86
	// summary:
87
	//		Returns the widget whose dom tree contains node or null if
88
	//		the node is not contained within the dom tree of any widget
89
	while(node){
90
		if(node.getAttribute && node.getAttribute("widgetId")){
91
			return dijit.registry.byId(node.getAttribute("widgetId"));
92
		}
93
		node = node.parentNode;
94
	}
95
	return null;
96
};
97
 
98
}