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