Subversion Repositories Applications.papyrus

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1318 alexandre_ 1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
4
 
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:
7
 
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
10
 
11
dojo.provide("dojo.widget.html.loader");
12
dojo.require("dojo.widget.HtmlWidget");
13
dojo.require("dojo.io.*");
14
dojo.require("dojo.lang.common");
15
dojo.require("dojo.lang.extras");
16
dojo.require("dojo.experimental");
17
dojo.experimental("dojo.widget.html.loader");
18
dojo.widget.html.loader = new (function () {
19
	this.toString = function () {
20
		return "dojo.widget.html.loader";
21
	};
22
	var _loader = this;
23
	dojo.addOnLoad(function () {
24
		dojo.experimental(_loader.toString());
25
		var undo = dojo.evalObjPath("dojo.undo.browser");
26
		if (djConfig["preventBackButtonFix"] && undo && !undo.initialState) {
27
			undo.setInitialState(new trackerObj);
28
		}
29
	});
30
	var logger = {};
31
	var trackerObj = function (id, data) {
32
		this.id = id;
33
		this.data = data;
34
	};
35
	trackerObj.prototype.handle = function (type) {
36
		if (typeof dojo == "undefined") {
37
			return;
38
		}
39
		var wg = dojo.widget.byId(this.id);
40
		if (wg) {
41
			wg.setContent(this.data, true);
42
		}
43
	};
44
	this._log = function (widget, data) {
45
		if (widget.trackHistory) {
46
			if (!logger[widget.widgetId]) {
47
				logger[widget.widgetId] = {childrenIds:[], stack:[data]};
48
			}
49
			var children = logger[widget.widgetId].childrenIds;
50
			while (children && children.length) {
51
				delete logger[children.pop()];
52
			}
53
			for (var child in widget.children) {
54
				logger[widget.widgetId].childrenIds = child.widgetId;
55
			}
56
			dojo.undo.browser.addToHistory(new trackerObj(widget.widgetId, dojo.lang.shallowCopy(data, true)));
57
		}
58
	};
59
	var undef = dojo.lang.isUndefined;
60
	var isFunc = dojo.lang.isFunction;
61
	function handleDefaults(e, handler, useAlert) {
62
		if (!handler) {
63
			handler = "onContentError";
64
		}
65
		if (dojo.lang.isString(e)) {
66
			e = {_text:e};
67
		}
68
		if (!e._text) {
69
			e._text = e.toString();
70
		}
71
		e.toString = function () {
72
			return this._text;
73
		};
74
		if (typeof e.returnValue != "boolean") {
75
			e.returnValue = true;
76
		}
77
		if (typeof e.preventDefault != "function") {
78
			e.preventDefault = function () {
79
				this.returnValue = false;
80
			};
81
		}
82
		this[handler](e);
83
		if (e.returnValue) {
84
			if (useAlert) {
85
				alert(e.toString());
86
			} else {
87
				this.loader.callOnUnLoad.call(this, false);
88
				this.onSetContent(e.toString());
89
			}
90
		}
91
	}
92
	function downloader(bindArgs) {
93
		for (var x in this.bindArgs) {
94
			bindArgs[x] = (undef(bindArgs[x]) ? this.bindArgs[x] : undefined);
95
		}
96
		var cache = this.cacheContent;
97
		if (undef(bindArgs.useCache)) {
98
			bindArgs.useCache = cache;
99
		}
100
		if (undef(bindArgs.preventCache)) {
101
			bindArgs.preventCache = !cache;
102
		}
103
		if (undef(bindArgs.mimetype)) {
104
			bindArgs.mimetype = "text/html";
105
		}
106
		this.loader.bindObj = dojo.io.bind(bindArgs);
107
	}
108
	function stackRunner(st) {
109
		var err = "", func = null;
110
		var scope = this.scriptScope || dojo.global();
111
		while (st.length) {
112
			func = st.shift();
113
			try {
114
				func.call(scope);
115
			}
116
			catch (e) {
117
				err += "\n" + func + " failed: " + e;
118
			}
119
		}
120
		if (err.length) {
121
			var name = (st == this.loader.addOnLoads) ? "addOnLoad" : "addOnUnLoad";
122
			handleDefaults.call(this, name + " failure\n " + err, "onExecError", true);
123
		}
124
	}
125
	function stackPusher(st, obj, func) {
126
		if (typeof func == "undefined") {
127
			st.push(obj);
128
		} else {
129
			st.push(function () {
130
				obj[func]();
131
			});
132
		}
133
	}
134
	function refreshed() {
135
		this.onResized();
136
		this.onLoad();
137
		this.isLoaded = true;
138
	}
139
	function asyncParse(data) {
140
		if (this.executeScripts) {
141
			this.onExecScript.call(this, data.scripts);
142
		}
143
		if (this.parseContent) {
144
			this.onContentParse.call(this);
145
		}
146
		refreshed.call(this);
147
	}
148
	function runHandler() {
149
		if (dojo.lang.isFunction(this.handler)) {
150
			this.handler(this, this.containerNode || this.domNode);
151
			refreshed.call(this);
152
			return false;
153
		}
154
		return true;
155
	}
156
	this.htmlContentBasicFix = function (s, url) {
157
		var titles = [], styles = [];
158
		var regex = /<title[^>]*>([\s\S]*?)<\/title>/i;
159
		var match, attr;
160
		while (match = regex.exec(s)) {
161
			titles.push(match[1]);
162
			s = s.substring(0, match.index) + s.substr(match.index + match[0].length);
163
		}
164
		regex = /(?:<(style)[^>]*>([\s\S]*?)<\/style>|<link ([^>]*rel=['"]?stylesheet['"]?[^>]*)>)/i;
165
		while (match = regex.exec(s)) {
166
			if (match[1] && match[1].toLowerCase() == "style") {
167
				styles.push(dojo.html.fixPathsInCssText(match[2], url));
168
			} else {
169
				if (attr = match[3].match(/href=(['"]?)([^'">]*)\1/i)) {
170
					styles.push({path:attr[2]});
171
				}
172
			}
173
			s = s.substring(0, match.index) + s.substr(match.index + match[0].length);
174
		}
175
		return {"s":s, "titles":titles, "styles":styles};
176
	};
177
	this.htmlContentAdjustPaths = function (s, url) {
178
		var tag = "", str = "", tagFix = "", path = "";
179
		var attr = [], origPath = "", fix = "";
180
		var regexFindTag = /<[a-z][a-z0-9]*[^>]*\s(?:(?:src|href|style)=[^>])+[^>]*>/i;
181
		var regexFindAttr = /\s(src|href|style)=(['"]?)([\w()\[\]\/.,\\'"-:;#=&?\s@]+?)\2/i;
182
		var regexProtocols = /^(?:[#]|(?:(?:https?|ftps?|file|javascript|mailto|news):))/;
183
		while (tag = regexFindTag.exec(s)) {
184
			str += s.substring(0, tag.index);
185
			s = s.substring((tag.index + tag[0].length), s.length);
186
			tag = tag[0];
187
			tagFix = "";
188
			while (attr = regexFindAttr.exec(tag)) {
189
				path = "";
190
				origPath = attr[3];
191
				switch (attr[1].toLowerCase()) {
192
				  case "src":
193
				  case "href":
194
					if (regexProtocols.exec(origPath)) {
195
						path = origPath;
196
					} else {
197
						path = (new dojo.uri.Uri(url, origPath).toString());
198
					}
199
					break;
200
				  case "style":
201
					path = dojo.html.fixPathsInCssText(origPath, url);
202
					break;
203
				  default:
204
					path = origPath;
205
				}
206
				fix = " " + attr[1] + "=" + attr[2] + path + attr[2];
207
				tagFix += tag.substring(0, attr.index) + fix;
208
				tag = tag.substring((attr.index + attr[0].length), tag.length);
209
			}
210
			str += tagFix + tag;
211
		}
212
		return str + s;
213
	};
214
	this.htmlContentScripts = function (s, collectScripts) {
215
		var scripts = [], requires = [], match = [];
216
		var attr = "", tmp = null, tag = "", sc = "", str = "";
217
		var regex = /<script([^>]*)>([\s\S]*?)<\/script>/i;
218
		var regexSrc = /src=(['"]?)([^"']*)\1/i;
219
		var regexDojoJs = /.*(\bdojo\b\.js(?:\.uncompressed\.js)?)$/;
220
		var regexInvalid = /(?:var )?\bdjConfig\b(?:[\s]*=[\s]*\{[^}]+\}|\.[\w]*[\s]*=[\s]*[^;\n]*)?;?|dojo\.hostenv\.writeIncludes\(\s*\);?/g;
221
		var regexRequires = /dojo\.(?:(?:require(?:After)?(?:If)?)|(?:widget\.(?:manager\.)?registerWidgetPackage)|(?:(?:hostenv\.)?setModulePrefix)|defineNamespace)\((['"]).*?\1\)\s*;?/;
222
		while (match = regex.exec(s)) {
223
			if (this.executeScripts && match[1]) {
224
				if (attr = regexSrc.exec(match[1])) {
225
					if (regexDojoJs.exec(attr[2])) {
226
						dojo.debug("Security note! inhibit:" + attr[2] + " from  beeing loaded again.");
227
					} else {
228
						scripts.push({path:attr[2]});
229
					}
230
				}
231
			}
232
			if (match[2]) {
233
				sc = match[2].replace(regexInvalid, "");
234
				if (!sc) {
235
					continue;
236
				}
237
				while (tmp = regexRequires.exec(sc)) {
238
					requires.push(tmp[0]);
239
					sc = sc.substring(0, tmp.index) + sc.substr(tmp.index + tmp[0].length);
240
				}
241
				if (collectScripts) {
242
					scripts.push(sc);
243
				}
244
			}
245
			s = s.substr(0, match.index) + s.substr(match.index + match[0].length);
246
		}
247
		if (collectScripts) {
248
			var regex = /(<[a-zA-Z][a-zA-Z0-9]*\s[^>]*\S=(['"])[^>]*[^\.\]])scriptScope([^>]*>)/;
249
			str = "";
250
			while (tag = regex.exec(s)) {
251
				tmp = ((tag[2] == "'") ? "\"" : "'");
252
				str += s.substring(0, tag.index);
253
				s = s.substr(tag.index).replace(regex, "$1dojo.widget.byId(" + tmp + this.widgetId + tmp + ").scriptScope$3");
254
			}
255
			s = str + s;
256
		}
257
		return {"s":s, "requires":requires, "scripts":scripts};
258
	};
259
	this.splitAndFixPaths = function (args) {
260
		if (!args.url) {
261
			args.url = "./";
262
		}
263
		url = new dojo.uri.Uri(location, args.url).toString();
264
		var ret = {"xml":"", "styles":[], "titles":[], "requires":[], "scripts":[], "url":url};
265
		if (args.content) {
266
			var tmp = null, content = args.content;
267
			if (args.adjustPaths) {
268
				content = _loader.htmlContentAdjustPaths.call(this, content, url);
269
			}
270
			tmp = _loader.htmlContentBasicFix.call(this, content, url);
271
			content = tmp.s;
272
			ret.styles = tmp.styles;
273
			ret.titles = tmp.titles;
274
			if (args.collectRequires || args.collectScripts) {
275
				tmp = _loader.htmlContentScripts.call(this, content, args.collectScripts);
276
				content = tmp.s;
277
				ret.requires = tmp.requires;
278
				ret.scripts = tmp.scripts;
279
			}
280
			var match = [];
281
			if (args.bodyExtract) {
282
				match = content.match(/<body[^>]*>\s*([\s\S]+)\s*<\/body>/im);
283
				if (match) {
284
					content = match[1];
285
				}
286
			}
287
			ret.xml = content;
288
		}
289
		return ret;
290
	};
291
	this.hookUp = function (args) {
292
		var widget = args.widget;
293
		if (dojo.lang.isString(widget)) {
294
			if (args.mixin) {
295
				dojo.raise(this.toString() + ", cant use mixin when widget is a string");
296
			}
297
			widget = dojo.evalObjPath(widget);
298
		}
299
		if (!widget || !(widget instanceof dojo.widget.HtmlWidget)) {
300
			dojo.raise(this.toString() + " Widget isn't defined or isn't a HtmlWidget instance");
301
		}
302
		if (widget.loader && widget.setUrl) {
303
			return;
304
		}
305
		var widgetProto = (args.mixin) ? widget : widget.constructor.prototype;
306
		widget.loader = {isLoaded:false, styleNodes:[], addOnLoads:[], addOnUnLoads:[], callOnUnLoad:(function (canCall) {
307
			return function (after) {
308
				this.abort();
309
				if (canCall) {
310
					this.onUnLoad();
311
				}
312
				canCall = after;
313
			};
314
		})(false), bindObj:null, unHook:(function (w, wg) {
315
			var oldProps = {isContainer:w.isContainer, adjustPats:w.adjustPaths, href:w.href, extractContent:w.extractContent, parseContent:w.parseContent, cacheContent:w.cacheContent, bindArgs:w.bindArgs, preload:w.preload, refreshOnShow:w.refreshOnShow, handler:w.handler, trackHistory:w.trackHistory, executeScripts:w.executeScripts, scriptScope:w.scriptScope, postCreate:w.postCreate, show:w.show, refresh:w.refresh, loadContents:w.loadContents, abort:w.abort, destroy:w.destroy, onLoad:w.onLoad, onUnLoad:w.onUnLoad, addOnLoad:w.addOnLoad, addOnUnLoad:w.addOnUnLoad, onDownloadStart:w.onDownloadStart, onDownloadEnd:w.onDownloadEnd, onDownloadError:w.onDownloadError, onContentError:w.onContentError, onExecError:w.onExecError, onSetContent:w.onSetContent, setUrl:w.setUrl, setContent:w.setContent, onContentParse:w.onContentParse, onExecScript:w.onExecScript, setHandler:w.setHandler};
316
			return function () {
317
				if (wg.abort) {
318
					wg.abort();
319
				}
320
				if ((w != wg) && (dojo.widget.byType(wg.widgetType).length > 1)) {
321
					return;
322
				}
323
				for (var x in oldProps) {
324
					if (oldProps[x] === undefined) {
325
						delete w[x];
326
						continue;
327
					}
328
					w[x] = oldProps[x];
329
				}
330
				delete wg._loader_defined;
331
				delete wg.loader;
332
			};
333
		})(widgetProto, widget)};
334
		if (widgetProto._loader_defined || widget._loader_defined) {
335
			return;
336
		}
337
		dojo.mixin(widgetProto, {isContainer:true, adjustPaths:undef(widgetProto.adjustPaths) ? true : widgetProto.adjustPaths, href:undef(widgetProto.href) ? "" : widgetProto.href, extractContent:undef(widgetProto.extractContent) ? true : widgetProto.extractContent, parseContent:undef(widgetProto.parseContent) ? true : widgetProto.parseContent, cacheContent:undef(widgetProto.cacheContent) ? true : widgetProto.cacheContent, bindArgs:undef(widgetProto.bindArgs) ? {} : widgetProto.bindArgs, preload:undef(widgetProto.preload) ? false : widgetProto.preload, refreshOnShow:undef(widgetProto.refreshOnShow) ? false : widgetProto.refreshOnShow, handler:undef(widgetProto.handler) ? "" : widgetProto.handler, executeScripts:undef(widgetProto.executeScripts) ? false : widgetProto.executeScripts, trackHistory:undef(widgetProto.tracHistory) ? false : widgetProto.trackHistory, scriptScope:null});
338
		widgetProto.postCreate = (function (postCreate) {
339
			return function () {
340
				if (widgetProto.constructor.superclass.postCreate != postCreate) {
341
					postCreate.apply(this, arguments);
342
				} else {
343
					widgetProto.constructor.superclass.postCreate.apply(this, arguments);
344
				}
345
				if (this.handler !== "") {
346
					this.setHandler(this.handler);
347
				}
348
				if (this.isShowing() || this.preload) {
349
					this.loadContents();
350
					if (!this.href) {
351
						_loader._log(this, (this.domNode || this.containerNode).innerHTML);
352
					}
353
				}
354
			};
355
		})(widgetProto.postCreate);
356
		widgetProto.show = (function (show) {
357
			return function () {
358
				if (this.refreshOnShow) {
359
					this.refresh();
360
				} else {
361
					this.loadContents();
362
				}
363
				if ((widgetProto.constructor.superclass.show == show) || !isFunc(show)) {
364
					widgetProto.constructor.superclass.show.apply(this, arguments);
365
				} else {
366
					show.apply(this, arguments);
367
				}
368
			};
369
		})(widgetProto.show);
370
		widgetProto.destroy = (function (destroy) {
371
			return function (destroy) {
372
				this.onUnLoad();
373
				this.abort();
374
				this.loader.unHook();
375
				if ((widgetProto.constructor.superclass.destroy != destroy) && isFunc(destroy)) {
376
					destroy.apply(this, arguments);
377
				} else {
378
					widgetProto.constructor.superclass.destroy.apply(this, arguments);
379
				}
380
			};
381
		})(widgetProto.destroy);
382
		if (!widgetProto.refresh) {
383
			widgetProto.refresh = function () {
384
				this.loader.isLoaded = false;
385
				this.loadContents();
386
			};
387
		}
388
		if (!widgetProto.loadContents) {
389
			widgetProto.loadContents = function () {
390
				if (this.loader.isLoaded) {
391
					return;
392
				}
393
				if (isFunc(this.handler)) {
394
					runHandler.call(this);
395
				} else {
396
					if (this.href !== "") {
397
						handleDefaults.call(this, "Loading...", "onDownloadStart");
398
						var self = this, url = this.href;
399
						downloader.call(this, {url:url, load:function (type, data, xhr) {
400
							self.onDownloadEnd.call(self, url, data);
401
						}, error:function (type, err, xhr) {
402
							var e = {responseText:xhr.responseText, status:xhr.status, statusText:xhr.statusText, responseHeaders:(xhr.getAllResponseHeaders) ? xhr.getAllResponseHeaders() : [], _text:"Error loading '" + url + "' (" + xhr.status + " " + xhr.statusText + ")"};
403
							handleDefaults.call(self, e, "onDownloadError");
404
							self.onLoad();
405
						}});
406
					}
407
				}
408
			};
409
		}
410
		if (!widgetProto.abort) {
411
			widgetProto.abort = function () {
412
				if (!this.loader || !this.loader.bindObj || !this.loader.bindObj.abort) {
413
					return;
414
				}
415
				this.loader.bindObj.abort();
416
				this.loader.bindObj = null;
417
			};
418
		}
419
		if (!widgetProto.onLoad) {
420
			widgetProto.onLoad = function () {
421
				stackRunner.call(this, this.loader.addOnLoads);
422
				this.loader.isLoaded = true;
423
			};
424
		}
425
		if (!widgetProto.onUnLoad) {
426
			widgetProto.onUnLoad = function () {
427
				stackRunner.call(this, this.loader.addOnUnLoads);
428
				delete this.scriptScope;
429
			};
430
		}
431
		if (!widgetProto.addOnLoad) {
432
			widgetProto.addOnLoad = function (obj, func) {
433
				stackPusher.call(this, this.loader.addOnLoads, obj, func);
434
			};
435
		}
436
		if (!widgetProto.addOnUnLoad) {
437
			widgetProto.addOnUnLoad = function (obj, func) {
438
				stackPusher.call(this, this.loader.addOnUnLoads, obj, func);
439
			};
440
		}
441
		if (!widgetProto.onExecError) {
442
			widgetProto.onExecError = function () {
443
			};
444
		}
445
		if (!widgetProto.onContentError) {
446
			widgetProto.onContentError = function () {
447
			};
448
		}
449
		if (!widgetProto.onDownloadError) {
450
			widgetProto.onDownloadError = function () {
451
			};
452
		}
453
		if (!widgetProto.onDownloadStart) {
454
			widgetProto.onDownloadStart = function (onDownloadStart) {
455
			};
456
		}
457
		if (!widgetProto.onDownloadEnd) {
458
			widgetProto.onDownloadEnd = function (url, data) {
459
				var args = {content:data, url:url, adjustPaths:this.adjustPaths, collectScripts:this.executeScripts, collectRequires:this.parseContent, bodyExtract:this.extractContent};
460
				data = _loader.splitAndFixPaths.call(this, args);
461
				this.setContent(data);
462
			};
463
		}
464
		if (!widgetProto.onSetContent) {
465
			widgetProto.onSetContent = function (cont) {
466
				this.destroyChildren();
467
				var styleNodes = this.loader.styleNodes;
468
				while (styleNodes.length) {
469
					var st = styleNodes.pop();
470
					if (st && st.parentNode) {
471
						st.parentNode.removeChild(st);
472
					}
473
				}
474
				var node = this.containerNode || this.domNode;
475
				while (node.firstChild) {
476
					try {
477
						dojo.event.browser.clean(node.firstChild);
478
					}
479
					catch (e) {
480
					}
481
					node.removeChild(node.firstChild);
482
				}
483
				try {
484
					if (typeof cont != "string") {
485
						node.appendChild(cont);
486
					} else {
487
						try {
488
							node.innerHTML = cont;
489
						}
490
						catch (e) {
491
							var tmp;
492
							(tmp = dojo.doc().createElement("div")).innerHTML = cont;
493
							while (tmp.firstChild) {
494
								node.appendChild(tmp.removeChild(tmp.firstChild));
495
							}
496
						}
497
					}
498
				}
499
				catch (e) {
500
					e._text = "Could'nt load content: " + e;
501
					var useAlert = (this.loader._onSetContent_err == e._text);
502
					this.loader._onSetContent_err = e._text;
503
					handleDefaults.call(this, e, "onContentError", useAlert);
504
				}
505
			};
506
		}
507
		if (!widgetProto.setUrl) {
508
			widgetProto.setUrl = function (url) {
509
				this.href = url;
510
				this.loader.isLoaded = false;
511
				if (this.preload || this.isShowing()) {
512
					this.loadContents();
513
				}
514
			};
515
		}
516
		if (!widgetProto.setContent) {
517
			widgetProto.setContent = function (data, dontLog) {
518
				this.loader.callOnUnLoad.call(this, true);
519
				if (!data || dojo.html.isNode(data)) {
520
					this.onSetContent(data);
521
					refreshed.call(this);
522
				} else {
523
					if (typeof data.xml != "string") {
524
						this.href = "";
525
						var args = {content:data, url:this.href, adjustPaths:this.adjustPaths, collectScripts:this.executeScripts, collectRequires:this.parseContent, bodyExtract:this.extractContent};
526
						data = _loader.splitAndFixPaths.call(this, args);
527
					} else {
528
						if (data.url != "./") {
529
							this.url = data.url;
530
						}
531
					}
532
					this.onSetContent(data.xml);
533
					for (var i = 0, styles = data.styles; i < styles.length; i++) {
534
						if (styles[i].path) {
535
							this.loader.styleNodes.push(dojo.html.insertCssFile(styles[i].path));
536
						} else {
537
							this.loader.styleNodes.push(dojo.html.insertCssText(styles[i]));
538
						}
539
					}
540
					if (this.parseContent) {
541
						for (var i = 0, requires = data.requires; i < requires.length; i++) {
542
							try {
543
								eval(requires[i]);
544
							}
545
							catch (e) {
546
								e._text = "dojo.widget.html.loader.hookUp: error in package loading calls, " + (e.description || e);
547
								handleDefaults.call(this, e, "onContentError", true);
548
							}
549
						}
550
					}
551
					if (dojo.hostenv.isXDomain && data.requires.length) {
552
						dojo.addOnLoad(function () {
553
							asyncParse.call(this, data);
554
							if (!dontLog) {
555
								_loader._log(this, data);
556
							}
557
						});
558
						dontLog = true;
559
					} else {
560
						asyncParse.call(this, data);
561
					}
562
				}
563
				if (!dontLog) {
564
				}
565
			};
566
		}
567
		if (!widgetProto.onContentParse) {
568
			widgetProto.onContentParse = function () {
569
				var node = this.containerNode || this.domNode;
570
				var parser = new dojo.xml.Parse();
571
				var frag = parser.parseElement(node, null, true);
572
				dojo.widget.getParser().createSubComponents(frag, this);
573
			};
574
		}
575
		if (!widgetProto.onExecScript) {
576
			widgetProto.onExecScript = function (scripts) {
577
				var self = this, tmp = "", code = "";
578
				for (var i = 0; i < scripts.length; i++) {
579
					if (scripts[i].path) {
580
						var url = scripts[i].path;
581
						downloader.call(this, {"url":url, "load":function (type, scriptStr) {
582
							(function () {
583
								tmp = scriptStr;
584
								scripts[i] = scriptStr;
585
							}).call(self);
586
						}, "error":function (type, error) {
587
							error._text = type + " downloading remote script";
588
							handleDefaults.call(self, error, "onExecError", true);
589
						}, "mimetype":"text/plain", "sync":true});
590
						code += tmp;
591
					} else {
592
						code += scripts[i];
593
					}
594
				}
595
				try {
596
					delete this.scriptScope;
597
					this.scriptScope = new (new Function("_container_", code + "; return this;"))(self);
598
				}
599
				catch (e) {
600
					e._text = "Error running scripts from content:\n" + (e.description || e.toString());
601
					handleDefaults.call(this, e, "onExecError", true);
602
				}
603
			};
604
		}
605
		if (!widgetProto.setHandler) {
606
			widgetProto.setHandler = function (handler) {
607
				var fcn = dojo.lang.isFunction(handler) ? handler : window[handler];
608
				if (!isFunc(fcn)) {
609
					handleDefaults.call(this, "Unable to set handler, '" + handler + "' not a function.", "onExecError", true);
610
					return;
611
				}
612
				this.handler = function () {
613
					return fcn.apply(this, arguments);
614
				};
615
			};
616
		}
617
		widgetProto._loader_defined = true;
618
	};
619
})();
620