Subversion Repositories Applications.papyrus

Rev

Rev 1318 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1318 Rev 1422
1
/*
1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
3
	All Rights Reserved.
4
 
4
 
5
	Licensed under the Academic Free License version 2.1 or above OR the
5
	Licensed under the Academic Free License version 2.1 or above OR the
6
	modified BSD license. For more information on Dojo licensing, see:
6
	modified BSD license. For more information on Dojo licensing, see:
7
 
7
 
8
		http://dojotoolkit.org/community/licensing.shtml
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
9
*/
-
 
10
 
-
 
11
 
10
 
12
 
11
dojo.provide("dojo.widget.Widget");
13
dojo.provide("dojo.widget.Widget");
12
dojo.require("dojo.lang.func");
14
dojo.require("dojo.lang.func");
13
dojo.require("dojo.lang.array");
15
dojo.require("dojo.lang.array");
14
dojo.require("dojo.lang.extras");
16
dojo.require("dojo.lang.extras");
15
dojo.require("dojo.lang.declare");
17
dojo.require("dojo.lang.declare");
16
dojo.require("dojo.ns");
18
dojo.require("dojo.ns");
17
dojo.require("dojo.widget.Manager");
19
dojo.require("dojo.widget.Manager");
18
dojo.require("dojo.event.*");
20
dojo.require("dojo.event.*");
19
dojo.require("dojo.a11y");
21
dojo.require("dojo.a11y");
20
dojo.declare("dojo.widget.Widget", null, function () {
22
dojo.declare("dojo.widget.Widget", null, function () {
21
	this.children = [];
23
	this.children = [];
22
	this.extraArgs = {};
24
	this.extraArgs = {};
23
}, {parent:null, isTopLevel:false, disabled:false, isContainer:false, widgetId:"", widgetType:"Widget", ns:"dojo", getNamespacedType:function () {
25
}, {parent:null, isTopLevel:false, disabled:false, isContainer:false, widgetId:"", widgetType:"Widget", ns:"dojo", getNamespacedType:function () {
24
	return (this.ns ? this.ns + ":" + this.widgetType : this.widgetType).toLowerCase();
26
	return (this.ns ? this.ns + ":" + this.widgetType : this.widgetType).toLowerCase();
25
}, toString:function () {
27
}, toString:function () {
26
	return "[Widget " + this.getNamespacedType() + ", " + (this.widgetId || "NO ID") + "]";
28
	return "[Widget " + this.getNamespacedType() + ", " + (this.widgetId || "NO ID") + "]";
27
}, repr:function () {
29
}, repr:function () {
28
	return this.toString();
30
	return this.toString();
29
}, enable:function () {
31
}, enable:function () {
30
	this.disabled = false;
32
	this.disabled = false;
31
}, disable:function () {
33
}, disable:function () {
32
	this.disabled = true;
34
	this.disabled = true;
33
}, onResized:function () {
35
}, onResized:function () {
34
	this.notifyChildrenOfResize();
36
	this.notifyChildrenOfResize();
35
}, notifyChildrenOfResize:function () {
37
}, notifyChildrenOfResize:function () {
36
	for (var i = 0; i < this.children.length; i++) {
38
	for (var i = 0; i < this.children.length; i++) {
37
		var child = this.children[i];
39
		var child = this.children[i];
38
		if (child.onResized) {
40
		if (child.onResized) {
39
			child.onResized();
41
			child.onResized();
40
		}
42
		}
41
	}
43
	}
42
}, create:function (args, fragment, parent, ns) {
44
}, create:function (args, fragment, parent, ns) {
43
	if (ns) {
45
	if (ns) {
44
		this.ns = ns;
46
		this.ns = ns;
45
	}
47
	}
46
	this.satisfyPropertySets(args, fragment, parent);
48
	this.satisfyPropertySets(args, fragment, parent);
47
	this.mixInProperties(args, fragment, parent);
49
	this.mixInProperties(args, fragment, parent);
48
	this.postMixInProperties(args, fragment, parent);
50
	this.postMixInProperties(args, fragment, parent);
49
	dojo.widget.manager.add(this);
51
	dojo.widget.manager.add(this);
50
	this.buildRendering(args, fragment, parent);
52
	this.buildRendering(args, fragment, parent);
51
	this.initialize(args, fragment, parent);
53
	this.initialize(args, fragment, parent);
52
	this.postInitialize(args, fragment, parent);
54
	this.postInitialize(args, fragment, parent);
53
	this.postCreate(args, fragment, parent);
55
	this.postCreate(args, fragment, parent);
54
	return this;
56
	return this;
55
}, destroy:function (finalize) {
57
}, destroy:function (finalize) {
56
	if (this.parent) {
58
	if (this.parent) {
57
		this.parent.removeChild(this);
59
		this.parent.removeChild(this);
58
	}
60
	}
59
	this.destroyChildren();
61
	this.destroyChildren();
60
	this.uninitialize();
62
	this.uninitialize();
61
	this.destroyRendering(finalize);
63
	this.destroyRendering(finalize);
62
	dojo.widget.manager.removeById(this.widgetId);
64
	dojo.widget.manager.removeById(this.widgetId);
63
}, destroyChildren:function () {
65
}, destroyChildren:function () {
64
	var widget;
66
	var widget;
65
	var i = 0;
67
	var i = 0;
66
	while (this.children.length > i) {
68
	while (this.children.length > i) {
67
		widget = this.children[i];
69
		widget = this.children[i];
68
		if (widget instanceof dojo.widget.Widget) {
70
		if (widget instanceof dojo.widget.Widget) {
69
			this.removeChild(widget);
71
			this.removeChild(widget);
70
			widget.destroy();
72
			widget.destroy();
71
			continue;
73
			continue;
72
		}
74
		}
73
		i++;
75
		i++;
74
	}
76
	}
75
}, getChildrenOfType:function (type, recurse) {
77
}, getChildrenOfType:function (type, recurse) {
76
	var ret = [];
78
	var ret = [];
77
	var isFunc = dojo.lang.isFunction(type);
79
	var isFunc = dojo.lang.isFunction(type);
78
	if (!isFunc) {
80
	if (!isFunc) {
79
		type = type.toLowerCase();
81
		type = type.toLowerCase();
80
	}
82
	}
81
	for (var x = 0; x < this.children.length; x++) {
83
	for (var x = 0; x < this.children.length; x++) {
82
		if (isFunc) {
84
		if (isFunc) {
83
			if (this.children[x] instanceof type) {
85
			if (this.children[x] instanceof type) {
84
				ret.push(this.children[x]);
86
				ret.push(this.children[x]);
85
			}
87
			}
86
		} else {
88
		} else {
87
			if (this.children[x].widgetType.toLowerCase() == type) {
89
			if (this.children[x].widgetType.toLowerCase() == type) {
88
				ret.push(this.children[x]);
90
				ret.push(this.children[x]);
89
			}
91
			}
90
		}
92
		}
91
		if (recurse) {
93
		if (recurse) {
92
			ret = ret.concat(this.children[x].getChildrenOfType(type, recurse));
94
			ret = ret.concat(this.children[x].getChildrenOfType(type, recurse));
93
		}
95
		}
94
	}
96
	}
95
	return ret;
97
	return ret;
96
}, getDescendants:function () {
98
}, getDescendants:function () {
97
	var result = [];
99
	var result = [];
98
	var stack = [this];
100
	var stack = [this];
99
	var elem;
101
	var elem;
100
	while ((elem = stack.pop())) {
102
	while ((elem = stack.pop())) {
101
		result.push(elem);
103
		result.push(elem);
102
		if (elem.children) {
104
		if (elem.children) {
103
			dojo.lang.forEach(elem.children, function (elem) {
105
			dojo.lang.forEach(elem.children, function (elem) {
104
				stack.push(elem);
106
				stack.push(elem);
105
			});
107
			});
106
		}
108
		}
107
	}
109
	}
108
	return result;
110
	return result;
109
}, isFirstChild:function () {
111
}, isFirstChild:function () {
110
	return this === this.parent.children[0];
112
	return this === this.parent.children[0];
111
}, isLastChild:function () {
113
}, isLastChild:function () {
112
	return this === this.parent.children[this.parent.children.length - 1];
114
	return this === this.parent.children[this.parent.children.length - 1];
113
}, satisfyPropertySets:function (args) {
115
}, satisfyPropertySets:function (args) {
114
	return args;
116
	return args;
115
}, mixInProperties:function (args, frag) {
117
}, mixInProperties:function (args, frag) {
116
	if ((args["fastMixIn"]) || (frag["fastMixIn"])) {
118
	if ((args["fastMixIn"]) || (frag["fastMixIn"])) {
117
		for (var x in args) {
119
		for (var x in args) {
118
			this[x] = args[x];
120
			this[x] = args[x];
119
		}
121
		}
120
		return;
122
		return;
121
	}
123
	}
122
	var undef;
124
	var undef;
123
	var lcArgs = dojo.widget.lcArgsCache[this.widgetType];
125
	var lcArgs = dojo.widget.lcArgsCache[this.widgetType];
124
	if (lcArgs == null) {
126
	if (lcArgs == null) {
125
		lcArgs = {};
127
		lcArgs = {};
126
		for (var y in this) {
128
		for (var y in this) {
127
			lcArgs[((new String(y)).toLowerCase())] = y;
129
			lcArgs[((new String(y)).toLowerCase())] = y;
128
		}
130
		}
129
		dojo.widget.lcArgsCache[this.widgetType] = lcArgs;
131
		dojo.widget.lcArgsCache[this.widgetType] = lcArgs;
130
	}
132
	}
131
	var visited = {};
133
	var visited = {};
132
	for (var x in args) {
134
	for (var x in args) {
133
		if (!this[x]) {
135
		if (!this[x]) {
134
			var y = lcArgs[(new String(x)).toLowerCase()];
136
			var y = lcArgs[(new String(x)).toLowerCase()];
135
			if (y) {
137
			if (y) {
136
				args[y] = args[x];
138
				args[y] = args[x];
137
				x = y;
139
				x = y;
138
			}
140
			}
139
		}
141
		}
140
		if (visited[x]) {
142
		if (visited[x]) {
141
			continue;
143
			continue;
142
		}
144
		}
143
		visited[x] = true;
145
		visited[x] = true;
144
		if ((typeof this[x]) != (typeof undef)) {
146
		if ((typeof this[x]) != (typeof undef)) {
145
			if (typeof args[x] != "string") {
147
			if (typeof args[x] != "string") {
146
				this[x] = args[x];
148
				this[x] = args[x];
147
			} else {
149
			} else {
148
				if (dojo.lang.isString(this[x])) {
150
				if (dojo.lang.isString(this[x])) {
149
					this[x] = args[x];
151
					this[x] = args[x];
150
				} else {
152
				} else {
151
					if (dojo.lang.isNumber(this[x])) {
153
					if (dojo.lang.isNumber(this[x])) {
152
						this[x] = new Number(args[x]);
154
						this[x] = new Number(args[x]);
153
					} else {
155
					} else {
154
						if (dojo.lang.isBoolean(this[x])) {
156
						if (dojo.lang.isBoolean(this[x])) {
155
							this[x] = (args[x].toLowerCase() == "false") ? false : true;
157
							this[x] = (args[x].toLowerCase() == "false") ? false : true;
156
						} else {
158
						} else {
157
							if (dojo.lang.isFunction(this[x])) {
159
							if (dojo.lang.isFunction(this[x])) {
158
								if (args[x].search(/[^\w\.]+/i) == -1) {
160
								if (args[x].search(/[^\w\.]+/i) == -1) {
159
									this[x] = dojo.evalObjPath(args[x], false);
161
									this[x] = dojo.evalObjPath(args[x], false);
160
								} else {
162
								} else {
161
									var tn = dojo.lang.nameAnonFunc(new Function(args[x]), this);
163
									var tn = dojo.lang.nameAnonFunc(new Function(args[x]), this);
162
									dojo.event.kwConnect({srcObj:this, srcFunc:x, adviceObj:this, adviceFunc:tn});
164
									dojo.event.kwConnect({srcObj:this, srcFunc:x, adviceObj:this, adviceFunc:tn});
163
								}
165
								}
164
							} else {
166
							} else {
165
								if (dojo.lang.isArray(this[x])) {
167
								if (dojo.lang.isArray(this[x])) {
166
									this[x] = args[x].split(";");
168
									this[x] = args[x].split(";");
167
								} else {
169
								} else {
168
									if (this[x] instanceof Date) {
170
									if (this[x] instanceof Date) {
169
										this[x] = new Date(Number(args[x]));
171
										this[x] = new Date(Number(args[x]));
170
									} else {
172
									} else {
171
										if (typeof this[x] == "object") {
173
										if (typeof this[x] == "object") {
172
											if (this[x] instanceof dojo.uri.Uri) {
174
											if (this[x] instanceof dojo.uri.Uri) {
173
												this[x] = dojo.uri.dojoUri(args[x]);
175
												this[x] = dojo.uri.dojoUri(args[x]);
174
											} else {
176
											} else {
175
												var pairs = args[x].split(";");
177
												var pairs = args[x].split(";");
176
												for (var y = 0; y < pairs.length; y++) {
178
												for (var y = 0; y < pairs.length; y++) {
177
													var si = pairs[y].indexOf(":");
179
													var si = pairs[y].indexOf(":");
178
													if ((si != -1) && (pairs[y].length > si)) {
180
													if ((si != -1) && (pairs[y].length > si)) {
179
														this[x][pairs[y].substr(0, si).replace(/^\s+|\s+$/g, "")] = pairs[y].substr(si + 1);
181
														this[x][pairs[y].substr(0, si).replace(/^\s+|\s+$/g, "")] = pairs[y].substr(si + 1);
180
													}
182
													}
181
												}
183
												}
182
											}
184
											}
183
										} else {
185
										} else {
184
											this[x] = args[x];
186
											this[x] = args[x];
185
										}
187
										}
186
									}
188
									}
187
								}
189
								}
188
							}
190
							}
189
						}
191
						}
190
					}
192
					}
191
				}
193
				}
192
			}
194
			}
193
		} else {
195
		} else {
194
			this.extraArgs[x.toLowerCase()] = args[x];
196
			this.extraArgs[x.toLowerCase()] = args[x];
195
		}
197
		}
196
	}
198
	}
197
}, postMixInProperties:function (args, frag, parent) {
199
}, postMixInProperties:function (args, frag, parent) {
198
}, initialize:function (args, frag, parent) {
200
}, initialize:function (args, frag, parent) {
199
	return false;
201
	return false;
200
}, postInitialize:function (args, frag, parent) {
202
}, postInitialize:function (args, frag, parent) {
201
	return false;
203
	return false;
202
}, postCreate:function (args, frag, parent) {
204
}, postCreate:function (args, frag, parent) {
203
	return false;
205
	return false;
204
}, uninitialize:function () {
206
}, uninitialize:function () {
205
	return false;
207
	return false;
206
}, buildRendering:function (args, frag, parent) {
208
}, buildRendering:function (args, frag, parent) {
207
	dojo.unimplemented("dojo.widget.Widget.buildRendering, on " + this.toString() + ", ");
209
	dojo.unimplemented("dojo.widget.Widget.buildRendering, on " + this.toString() + ", ");
208
	return false;
210
	return false;
209
}, destroyRendering:function () {
211
}, destroyRendering:function () {
210
	dojo.unimplemented("dojo.widget.Widget.destroyRendering");
212
	dojo.unimplemented("dojo.widget.Widget.destroyRendering");
211
	return false;
213
	return false;
212
}, addedTo:function (parent) {
214
}, addedTo:function (parent) {
213
}, addChild:function (child) {
215
}, addChild:function (child) {
214
	dojo.unimplemented("dojo.widget.Widget.addChild");
216
	dojo.unimplemented("dojo.widget.Widget.addChild");
215
	return false;
217
	return false;
216
}, removeChild:function (widget) {
218
}, removeChild:function (widget) {
217
	for (var x = 0; x < this.children.length; x++) {
219
	for (var x = 0; x < this.children.length; x++) {
218
		if (this.children[x] === widget) {
220
		if (this.children[x] === widget) {
219
			this.children.splice(x, 1);
221
			this.children.splice(x, 1);
220
			widget.parent = null;
222
			widget.parent = null;
221
			break;
223
			break;
222
		}
224
		}
223
	}
225
	}
224
	return widget;
226
	return widget;
225
}, getPreviousSibling:function () {
227
}, getPreviousSibling:function () {
226
	var idx = this.getParentIndex();
228
	var idx = this.getParentIndex();
227
	if (idx <= 0) {
229
	if (idx <= 0) {
228
		return null;
230
		return null;
229
	}
231
	}
230
	return this.parent.children[idx - 1];
232
	return this.parent.children[idx - 1];
231
}, getSiblings:function () {
233
}, getSiblings:function () {
232
	return this.parent.children;
234
	return this.parent.children;
233
}, getParentIndex:function () {
235
}, getParentIndex:function () {
234
	return dojo.lang.indexOf(this.parent.children, this, true);
236
	return dojo.lang.indexOf(this.parent.children, this, true);
235
}, getNextSibling:function () {
237
}, getNextSibling:function () {
236
	var idx = this.getParentIndex();
238
	var idx = this.getParentIndex();
237
	if (idx == this.parent.children.length - 1) {
239
	if (idx == this.parent.children.length - 1) {
238
		return null;
240
		return null;
239
	}
241
	}
240
	if (idx < 0) {
242
	if (idx < 0) {
241
		return null;
243
		return null;
242
	}
244
	}
243
	return this.parent.children[idx + 1];
245
	return this.parent.children[idx + 1];
244
}});
246
}});
245
dojo.widget.lcArgsCache = {};
247
dojo.widget.lcArgsCache = {};
246
dojo.widget.tags = {};
248
dojo.widget.tags = {};
247
dojo.widget.tags.addParseTreeHandler = function (type) {
249
dojo.widget.tags.addParseTreeHandler = function (type) {
248
	dojo.deprecated("addParseTreeHandler", ". ParseTreeHandlers are now reserved for components. Any unfiltered DojoML tag without a ParseTreeHandler is assumed to be a widget", "0.5");
250
	dojo.deprecated("addParseTreeHandler", ". ParseTreeHandlers are now reserved for components. Any unfiltered DojoML tag without a ParseTreeHandler is assumed to be a widget", "0.5");
249
};
251
};
250
dojo.widget.tags["dojo:propertyset"] = function (fragment, widgetParser, parentComp) {
252
dojo.widget.tags["dojo:propertyset"] = function (fragment, widgetParser, parentComp) {
251
	var properties = widgetParser.parseProperties(fragment["dojo:propertyset"]);
253
	var properties = widgetParser.parseProperties(fragment["dojo:propertyset"]);
252
};
254
};
253
dojo.widget.tags["dojo:connect"] = function (fragment, widgetParser, parentComp) {
255
dojo.widget.tags["dojo:connect"] = function (fragment, widgetParser, parentComp) {
254
	var properties = widgetParser.parseProperties(fragment["dojo:connect"]);
256
	var properties = widgetParser.parseProperties(fragment["dojo:connect"]);
255
};
257
};
256
dojo.widget.buildWidgetFromParseTree = function (type, frag, parser, parentComp, insertionIndex, localProps) {
258
dojo.widget.buildWidgetFromParseTree = function (type, frag, parser, parentComp, insertionIndex, localProps) {
257
	dojo.a11y.setAccessibleMode();
259
	dojo.a11y.setAccessibleMode();
258
	var stype = type.split(":");
260
	var stype = type.split(":");
259
	stype = (stype.length == 2) ? stype[1] : type;
261
	stype = (stype.length == 2) ? stype[1] : type;
260
	var localProperties = localProps || parser.parseProperties(frag[frag["ns"] + ":" + stype]);
262
	var localProperties = localProps || parser.parseProperties(frag[frag["ns"] + ":" + stype]);
261
	var twidget = dojo.widget.manager.getImplementation(stype, null, null, frag["ns"]);
263
	var twidget = dojo.widget.manager.getImplementation(stype, null, null, frag["ns"]);
262
	if (!twidget) {
264
	if (!twidget) {
263
		throw new Error("cannot find \"" + type + "\" widget");
265
		throw new Error("cannot find \"" + type + "\" widget");
264
	} else {
266
	} else {
265
		if (!twidget.create) {
267
		if (!twidget.create) {
266
			throw new Error("\"" + type + "\" widget object has no \"create\" method and does not appear to implement *Widget");
268
			throw new Error("\"" + type + "\" widget object has no \"create\" method and does not appear to implement *Widget");
267
		}
269
		}
268
	}
270
	}
269
	localProperties["dojoinsertionindex"] = insertionIndex;
271
	localProperties["dojoinsertionindex"] = insertionIndex;
270
	var ret = twidget.create(localProperties, frag, parentComp, frag["ns"]);
272
	var ret = twidget.create(localProperties, frag, parentComp, frag["ns"]);
271
	return ret;
273
	return ret;
272
};
274
};
273
dojo.widget.defineWidget = function (widgetClass, renderer, superclasses, init, props) {
275
dojo.widget.defineWidget = function (widgetClass, renderer, superclasses, init, props) {
274
	if (dojo.lang.isString(arguments[3])) {
276
	if (dojo.lang.isString(arguments[3])) {
275
		dojo.widget._defineWidget(arguments[0], arguments[3], arguments[1], arguments[4], arguments[2]);
277
		dojo.widget._defineWidget(arguments[0], arguments[3], arguments[1], arguments[4], arguments[2]);
276
	} else {
278
	} else {
277
		var args = [arguments[0]], p = 3;
279
		var args = [arguments[0]], p = 3;
278
		if (dojo.lang.isString(arguments[1])) {
280
		if (dojo.lang.isString(arguments[1])) {
279
			args.push(arguments[1], arguments[2]);
281
			args.push(arguments[1], arguments[2]);
280
		} else {
282
		} else {
281
			args.push("", arguments[1]);
283
			args.push("", arguments[1]);
282
			p = 2;
284
			p = 2;
283
		}
285
		}
284
		if (dojo.lang.isFunction(arguments[p])) {
286
		if (dojo.lang.isFunction(arguments[p])) {
285
			args.push(arguments[p], arguments[p + 1]);
287
			args.push(arguments[p], arguments[p + 1]);
286
		} else {
288
		} else {
287
			args.push(null, arguments[p]);
289
			args.push(null, arguments[p]);
288
		}
290
		}
289
		dojo.widget._defineWidget.apply(this, args);
291
		dojo.widget._defineWidget.apply(this, args);
290
	}
292
	}
291
};
293
};
292
dojo.widget.defineWidget.renderers = "html|svg|vml";
294
dojo.widget.defineWidget.renderers = "html|svg|vml";
293
dojo.widget._defineWidget = function (widgetClass, renderer, superclasses, init, props) {
295
dojo.widget._defineWidget = function (widgetClass, renderer, superclasses, init, props) {
294
	var module = widgetClass.split(".");
296
	var module = widgetClass.split(".");
295
	var type = module.pop();
297
	var type = module.pop();
296
	var regx = "\\.(" + (renderer ? renderer + "|" : "") + dojo.widget.defineWidget.renderers + ")\\.";
298
	var regx = "\\.(" + (renderer ? renderer + "|" : "") + dojo.widget.defineWidget.renderers + ")\\.";
297
	var r = widgetClass.search(new RegExp(regx));
299
	var r = widgetClass.search(new RegExp(regx));
298
	module = (r < 0 ? module.join(".") : widgetClass.substr(0, r));
300
	module = (r < 0 ? module.join(".") : widgetClass.substr(0, r));
299
	dojo.widget.manager.registerWidgetPackage(module);
301
	dojo.widget.manager.registerWidgetPackage(module);
300
	var pos = module.indexOf(".");
302
	var pos = module.indexOf(".");
301
	var nsName = (pos > -1) ? module.substring(0, pos) : module;
303
	var nsName = (pos > -1) ? module.substring(0, pos) : module;
302
	props = (props) || {};
304
	props = (props) || {};
303
	props.widgetType = type;
305
	props.widgetType = type;
304
	if ((!init) && (props["classConstructor"])) {
306
	if ((!init) && (props["classConstructor"])) {
305
		init = props.classConstructor;
307
		init = props.classConstructor;
306
		delete props.classConstructor;
308
		delete props.classConstructor;
307
	}
309
	}
308
	dojo.declare(widgetClass, superclasses, init, props);
310
	dojo.declare(widgetClass, superclasses, init, props);
309
};
311
};
310
 
312