Subversion Repositories Applications.papyrus

Rev

Rev 1318 | Details | Compare with Previous | 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
 
1422 alexandre_ 11
 
12
 
1318 alexandre_ 13
dojo.provide("dojo.browser_debug");
14
dojo.hostenv.loadedUris.push("../src/bootstrap1.js");
15
dojo.hostenv.loadedUris.push("../src/loader.js");
16
dojo.hostenv.loadedUris.push("../src/hostenv_browser.js");
17
dojo.hostenv._loadedUrisListStart = dojo.hostenv.loadedUris.length;
18
function removeComments(contents) {
19
	contents = new String((!contents) ? "" : contents);
20
	contents = contents.replace(/^(.*?)\/\/(.*)$/mg, "$1");
21
	contents = contents.replace(/(\n)/mg, "__DOJONEWLINE");
22
	contents = contents.replace(/\/\*(.*?)\*\//g, "");
23
	return contents.replace(/__DOJONEWLINE/mg, "\n");
24
}
25
dojo.hostenv.getRequiresAndProvides = function (contents) {
26
	if (!contents) {
27
		return [];
28
	}
29
	var deps = [];
30
	var tmp;
31
	RegExp.lastIndex = 0;
32
	var testExp = /dojo.(hostenv.loadModule|hostenv.require|require|requireIf|kwCompoundRequire|hostenv.conditionalLoadModule|hostenv.startPackage|provide)\([\w\W]*?\)/mg;
33
	while ((tmp = testExp.exec(contents)) != null) {
34
		deps.push(tmp[0]);
35
	}
36
	return deps;
37
};
38
dojo.hostenv.getDelayRequiresAndProvides = function (contents) {
39
	if (!contents) {
40
		return [];
41
	}
42
	var deps = [];
43
	var tmp;
44
	RegExp.lastIndex = 0;
45
	var testExp = /dojo.(requireAfterIf)\([\w\W]*?\)/mg;
46
	while ((tmp = testExp.exec(contents)) != null) {
47
		deps.push(tmp[0]);
48
	}
49
	return deps;
50
};
51
dojo.clobberLastObject = function (objpath) {
52
	if (objpath.indexOf(".") == -1) {
53
		if (!dj_undef(objpath, dj_global)) {
54
			delete dj_global[objpath];
55
		}
56
		return true;
57
	}
58
	var syms = objpath.split(/\./);
59
	var base = dojo.evalObjPath(syms.slice(0, -1).join("."), false);
60
	var child = syms[syms.length - 1];
61
	if (!dj_undef(child, base)) {
62
		delete base[child];
63
		return true;
64
	}
65
	return false;
66
};
67
var removals = [];
68
function zip(arr) {
69
	var ret = [];
70
	var seen = {};
71
	for (var x = 0; x < arr.length; x++) {
72
		if (!seen[arr[x]]) {
73
			ret.push(arr[x]);
74
			seen[arr[x]] = true;
75
		}
76
	}
77
	return ret;
78
}
79
var old_dj_eval = dj_eval;
80
dj_eval = function () {
81
	return true;
82
};
83
dojo.hostenv.oldLoadUri = dojo.hostenv.loadUri;
84
dojo.hostenv.loadUri = function (uri, cb) {
85
	if (dojo.hostenv.loadedUris[uri]) {
86
		return true;
87
	}
88
	try {
89
		var text = this.getText(uri, null, true);
90
		if (!text) {
91
			return false;
92
		}
93
		if (cb) {
94
			var expr = old_dj_eval("(" + text + ")");
95
			cb(expr);
96
		} else {
97
			var requires = dojo.hostenv.getRequiresAndProvides(text);
98
			eval(requires.join(";"));
99
			dojo.hostenv.loadedUris.push(uri);
100
			dojo.hostenv.loadedUris[uri] = true;
101
			var delayRequires = dojo.hostenv.getDelayRequiresAndProvides(text);
102
			eval(delayRequires.join(";"));
103
		}
104
	}
105
	catch (e) {
106
		alert(e);
107
	}
108
	return true;
109
};
110
dojo.hostenv._writtenIncludes = {};
111
dojo.hostenv.writeIncludes = function (willCallAgain) {
112
	for (var x = removals.length - 1; x >= 0; x--) {
113
		dojo.clobberLastObject(removals[x]);
114
	}
115
	var depList = [];
116
	var seen = dojo.hostenv._writtenIncludes;
117
	for (var x = 0; x < dojo.hostenv.loadedUris.length; x++) {
118
		var curi = dojo.hostenv.loadedUris[x];
119
		if (!seen[curi]) {
120
			seen[curi] = true;
121
			depList.push(curi);
122
		}
123
	}
124
	dojo.hostenv._global_omit_module_check = true;
125
	for (var x = dojo.hostenv._loadedUrisListStart; x < depList.length; x++) {
126
		document.write("<script type='text/javascript' src='" + depList[x] + "'></script>");
127
	}
128
	document.write("<script type='text/javascript'>dojo.hostenv._global_omit_module_check = false;</script>");
129
	dojo.hostenv._loadedUrisListStart = 0;
130
	if (!willCallAgain) {
131
		dj_eval = old_dj_eval;
132
		dojo.hostenv.loadUri = dojo.hostenv.oldLoadUri;
133
	}
134
};
135