Subversion Repositories Applications.papyrus

Rev

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
 
1422 alexandre_ 11
 
12
 
1318 alexandre_ 13
(function () {
14
	var _addHostEnv = {pkgFileName:"__package__", loading_modules_:{}, loaded_modules_:{}, addedToLoadingCount:[], removedFromLoadingCount:[], inFlightCount:0, modulePrefixes_:{dojo:{name:"dojo", value:"src"}}, setModulePrefix:function (module, prefix) {
15
		this.modulePrefixes_[module] = {name:module, value:prefix};
16
	}, moduleHasPrefix:function (module) {
17
		var mp = this.modulePrefixes_;
18
		return Boolean(mp[module] && mp[module].value);
19
	}, getModulePrefix:function (module) {
20
		if (this.moduleHasPrefix(module)) {
21
			return this.modulePrefixes_[module].value;
22
		}
23
		return module;
24
	}, getTextStack:[], loadUriStack:[], loadedUris:[], post_load_:false, modulesLoadedListeners:[], unloadListeners:[], loadNotifying:false};
25
	for (var param in _addHostEnv) {
26
		dojo.hostenv[param] = _addHostEnv[param];
27
	}
28
})();
29
dojo.hostenv.loadPath = function (relpath, module, cb) {
30
	var uri;
31
	if (relpath.charAt(0) == "/" || relpath.match(/^\w+:/)) {
32
		uri = relpath;
33
	} else {
34
		uri = this.getBaseScriptUri() + relpath;
35
	}
36
	if (djConfig.cacheBust && dojo.render.html.capable) {
37
		uri += "?" + String(djConfig.cacheBust).replace(/\W+/g, "");
38
	}
39
	try {
40
		return !module ? this.loadUri(uri, cb) : this.loadUriAndCheck(uri, module, cb);
41
	}
42
	catch (e) {
43
		dojo.debug(e);
44
		return false;
45
	}
46
};
47
dojo.hostenv.loadUri = function (uri, cb) {
48
	if (this.loadedUris[uri]) {
49
		return true;
50
	}
51
	var contents = this.getText(uri, null, true);
52
	if (!contents) {
53
		return false;
54
	}
55
	this.loadedUris[uri] = true;
56
	if (cb) {
57
		contents = "(" + contents + ")";
58
	}
59
	var value = dj_eval(contents);
60
	if (cb) {
61
		cb(value);
62
	}
63
	return true;
64
};
65
dojo.hostenv.loadUriAndCheck = function (uri, moduleName, cb) {
66
	var ok = true;
67
	try {
68
		ok = this.loadUri(uri, cb);
69
	}
70
	catch (e) {
71
		dojo.debug("failed loading ", uri, " with error: ", e);
72
	}
73
	return Boolean(ok && this.findModule(moduleName, false));
74
};
75
dojo.loaded = function () {
76
};
77
dojo.unloaded = function () {
78
};
79
dojo.hostenv.loaded = function () {
80
	this.loadNotifying = true;
81
	this.post_load_ = true;
82
	var mll = this.modulesLoadedListeners;
83
	for (var x = 0; x < mll.length; x++) {
84
		mll[x]();
85
	}
86
	this.modulesLoadedListeners = [];
87
	this.loadNotifying = false;
88
	dojo.loaded();
89
};
90
dojo.hostenv.unloaded = function () {
91
	var mll = this.unloadListeners;
92
	while (mll.length) {
93
		(mll.pop())();
94
	}
95
	dojo.unloaded();
96
};
97
dojo.addOnLoad = function (obj, functionName) {
98
	var dh = dojo.hostenv;
99
	if (arguments.length == 1) {
100
		dh.modulesLoadedListeners.push(obj);
101
	} else {
102
		if (arguments.length > 1) {
103
			dh.modulesLoadedListeners.push(function () {
104
				obj[functionName]();
105
			});
106
		}
107
	}
108
	if (dh.post_load_ && dh.inFlightCount == 0 && !dh.loadNotifying) {
109
		dh.callLoaded();
110
	}
111
};
112
dojo.addOnUnload = function (obj, functionName) {
113
	var dh = dojo.hostenv;
114
	if (arguments.length == 1) {
115
		dh.unloadListeners.push(obj);
116
	} else {
117
		if (arguments.length > 1) {
118
			dh.unloadListeners.push(function () {
119
				obj[functionName]();
120
			});
121
		}
122
	}
123
};
124
dojo.hostenv.modulesLoaded = function () {
125
	if (this.post_load_) {
126
		return;
127
	}
128
	if (this.loadUriStack.length == 0 && this.getTextStack.length == 0) {
129
		if (this.inFlightCount > 0) {
130
			dojo.debug("files still in flight!");
131
			return;
132
		}
133
		dojo.hostenv.callLoaded();
134
	}
135
};
136
dojo.hostenv.callLoaded = function () {
137
	if (typeof setTimeout == "object" || (djConfig["useXDomain"] && dojo.render.html.opera)) {
138
		setTimeout("dojo.hostenv.loaded();", 0);
139
	} else {
140
		dojo.hostenv.loaded();
141
	}
142
};
143
dojo.hostenv.getModuleSymbols = function (modulename) {
144
	var syms = modulename.split(".");
145
	for (var i = syms.length; i > 0; i--) {
146
		var parentModule = syms.slice(0, i).join(".");
147
		if ((i == 1) && !this.moduleHasPrefix(parentModule)) {
148
			syms[0] = "../" + syms[0];
149
		} else {
150
			var parentModulePath = this.getModulePrefix(parentModule);
151
			if (parentModulePath != parentModule) {
152
				syms.splice(0, i, parentModulePath);
153
				break;
154
			}
155
		}
156
	}
157
	return syms;
158
};
159
dojo.hostenv._global_omit_module_check = false;
160
dojo.hostenv.loadModule = function (moduleName, exactOnly, omitModuleCheck) {
161
	if (!moduleName) {
162
		return;
163
	}
164
	omitModuleCheck = this._global_omit_module_check || omitModuleCheck;
165
	var module = this.findModule(moduleName, false);
166
	if (module) {
167
		return module;
168
	}
169
	if (dj_undef(moduleName, this.loading_modules_)) {
170
		this.addedToLoadingCount.push(moduleName);
171
	}
172
	this.loading_modules_[moduleName] = 1;
173
	var relpath = moduleName.replace(/\./g, "/") + ".js";
174
	var nsyms = moduleName.split(".");
175
	var syms = this.getModuleSymbols(moduleName);
176
	var startedRelative = ((syms[0].charAt(0) != "/") && !syms[0].match(/^\w+:/));
177
	var last = syms[syms.length - 1];
178
	var ok;
179
	if (last == "*") {
180
		moduleName = nsyms.slice(0, -1).join(".");
181
		while (syms.length) {
182
			syms.pop();
183
			syms.push(this.pkgFileName);
184
			relpath = syms.join("/") + ".js";
185
			if (startedRelative && relpath.charAt(0) == "/") {
186
				relpath = relpath.slice(1);
187
			}
188
			ok = this.loadPath(relpath, !omitModuleCheck ? moduleName : null);
189
			if (ok) {
190
				break;
191
			}
192
			syms.pop();
193
		}
194
	} else {
195
		relpath = syms.join("/") + ".js";
196
		moduleName = nsyms.join(".");
197
		var modArg = !omitModuleCheck ? moduleName : null;
198
		ok = this.loadPath(relpath, modArg);
199
		if (!ok && !exactOnly) {
200
			syms.pop();
201
			while (syms.length) {
202
				relpath = syms.join("/") + ".js";
203
				ok = this.loadPath(relpath, modArg);
204
				if (ok) {
205
					break;
206
				}
207
				syms.pop();
208
				relpath = syms.join("/") + "/" + this.pkgFileName + ".js";
209
				if (startedRelative && relpath.charAt(0) == "/") {
210
					relpath = relpath.slice(1);
211
				}
212
				ok = this.loadPath(relpath, modArg);
213
				if (ok) {
214
					break;
215
				}
216
			}
217
		}
218
		if (!ok && !omitModuleCheck) {
219
			dojo.raise("Could not load '" + moduleName + "'; last tried '" + relpath + "'");
220
		}
221
	}
222
	if (!omitModuleCheck && !this["isXDomain"]) {
223
		module = this.findModule(moduleName, false);
224
		if (!module) {
225
			dojo.raise("symbol '" + moduleName + "' is not defined after loading '" + relpath + "'");
226
		}
227
	}
228
	return module;
229
};
230
dojo.hostenv.startPackage = function (packageName) {
231
	var fullPkgName = String(packageName);
232
	var strippedPkgName = fullPkgName;
233
	var syms = packageName.split(/\./);
234
	if (syms[syms.length - 1] == "*") {
235
		syms.pop();
236
		strippedPkgName = syms.join(".");
237
	}
238
	var evaledPkg = dojo.evalObjPath(strippedPkgName, true);
239
	this.loaded_modules_[fullPkgName] = evaledPkg;
240
	this.loaded_modules_[strippedPkgName] = evaledPkg;
241
	return evaledPkg;
242
};
243
dojo.hostenv.findModule = function (moduleName, mustExist) {
244
	var lmn = String(moduleName);
245
	if (this.loaded_modules_[lmn]) {
246
		return this.loaded_modules_[lmn];
247
	}
248
	if (mustExist) {
249
		dojo.raise("no loaded module named '" + moduleName + "'");
250
	}
251
	return null;
252
};
253
dojo.kwCompoundRequire = function (modMap) {
254
	var common = modMap["common"] || [];
255
	var result = modMap[dojo.hostenv.name_] ? common.concat(modMap[dojo.hostenv.name_] || []) : common.concat(modMap["default"] || []);
256
	for (var x = 0; x < result.length; x++) {
257
		var curr = result[x];
258
		if (curr.constructor == Array) {
259
			dojo.hostenv.loadModule.apply(dojo.hostenv, curr);
260
		} else {
261
			dojo.hostenv.loadModule(curr);
262
		}
263
	}
264
};
265
dojo.require = function (resourceName) {
266
	dojo.hostenv.loadModule.apply(dojo.hostenv, arguments);
267
};
268
dojo.requireIf = function (condition, resourceName) {
269
	var arg0 = arguments[0];
270
	if ((arg0 === true) || (arg0 == "common") || (arg0 && dojo.render[arg0].capable)) {
271
		var args = [];
272
		for (var i = 1; i < arguments.length; i++) {
273
			args.push(arguments[i]);
274
		}
275
		dojo.require.apply(dojo, args);
276
	}
277
};
278
dojo.requireAfterIf = dojo.requireIf;
279
dojo.provide = function (resourceName) {
280
	return dojo.hostenv.startPackage.apply(dojo.hostenv, arguments);
281
};
282
dojo.registerModulePath = function (module, prefix) {
283
	return dojo.hostenv.setModulePrefix(module, prefix);
284
};
285
if (djConfig["modulePaths"]) {
286
	for (var param in djConfig["modulePaths"]) {
287
		dojo.registerModulePath(param, djConfig["modulePaths"][param]);
288
	}
289
}
290
dojo.setModulePrefix = function (module, prefix) {
291
	dojo.deprecated("dojo.setModulePrefix(\"" + module + "\", \"" + prefix + "\")", "replaced by dojo.registerModulePath", "0.5");
292
	return dojo.registerModulePath(module, prefix);
293
};
294
dojo.exists = function (obj, name) {
295
	var p = name.split(".");
296
	for (var i = 0; i < p.length; i++) {
297
		if (!obj[p[i]]) {
298
			return false;
299
		}
300
		obj = obj[p[i]];
301
	}
302
	return true;
303
};
304
dojo.hostenv.normalizeLocale = function (locale) {
305
	var result = locale ? locale.toLowerCase() : dojo.locale;
306
	if (result == "root") {
307
		result = "ROOT";
308
	}
309
	return result;
310
};
311
dojo.hostenv.searchLocalePath = function (locale, down, searchFunc) {
312
	locale = dojo.hostenv.normalizeLocale(locale);
313
	var elements = locale.split("-");
314
	var searchlist = [];
315
	for (var i = elements.length; i > 0; i--) {
316
		searchlist.push(elements.slice(0, i).join("-"));
317
	}
318
	searchlist.push(false);
319
	if (down) {
320
		searchlist.reverse();
321
	}
322
	for (var j = searchlist.length - 1; j >= 0; j--) {
323
		var loc = searchlist[j] || "ROOT";
324
		var stop = searchFunc(loc);
325
		if (stop) {
326
			break;
327
		}
328
	}
329
};
330
dojo.hostenv.localesGenerated;
331
dojo.hostenv.registerNlsPrefix = function () {
332
	dojo.registerModulePath("nls", "nls");
333
};
334
dojo.hostenv.preloadLocalizations = function () {
335
	if (dojo.hostenv.localesGenerated) {
336
		dojo.hostenv.registerNlsPrefix();
337
		function preload(locale) {
338
			locale = dojo.hostenv.normalizeLocale(locale);
339
			dojo.hostenv.searchLocalePath(locale, true, function (loc) {
340
				for (var i = 0; i < dojo.hostenv.localesGenerated.length; i++) {
341
					if (dojo.hostenv.localesGenerated[i] == loc) {
342
						dojo["require"]("nls.dojo_" + loc);
343
						return true;
344
					}
345
				}
346
				return false;
347
			});
348
		}
349
		preload();
350
		var extra = djConfig.extraLocale || [];
351
		for (var i = 0; i < extra.length; i++) {
352
			preload(extra[i]);
353
		}
354
	}
355
	dojo.hostenv.preloadLocalizations = function () {
356
	};
357
};
358
dojo.requireLocalization = function (moduleName, bundleName, locale, availableFlatLocales) {
359
	dojo.hostenv.preloadLocalizations();
360
	var targetLocale = dojo.hostenv.normalizeLocale(locale);
361
	var bundlePackage = [moduleName, "nls", bundleName].join(".");
362
	var bestLocale = "";
363
	if (availableFlatLocales) {
364
		var flatLocales = availableFlatLocales.split(",");
365
		for (var i = 0; i < flatLocales.length; i++) {
366
			if (targetLocale.indexOf(flatLocales[i]) == 0) {
367
				if (flatLocales[i].length > bestLocale.length) {
368
					bestLocale = flatLocales[i];
369
				}
370
			}
371
		}
372
		if (!bestLocale) {
373
			bestLocale = "ROOT";
374
		}
375
	}
376
	var tempLocale = availableFlatLocales ? bestLocale : targetLocale;
377
	var bundle = dojo.hostenv.findModule(bundlePackage);
378
	var localizedBundle = null;
379
	if (bundle) {
380
		if (djConfig.localizationComplete && bundle._built) {
381
			return;
382
		}
383
		var jsLoc = tempLocale.replace("-", "_");
384
		var translationPackage = bundlePackage + "." + jsLoc;
385
		localizedBundle = dojo.hostenv.findModule(translationPackage);
386
	}
387
	if (!localizedBundle) {
388
		bundle = dojo.hostenv.startPackage(bundlePackage);
389
		var syms = dojo.hostenv.getModuleSymbols(moduleName);
390
		var modpath = syms.concat("nls").join("/");
391
		var parent;
392
		dojo.hostenv.searchLocalePath(tempLocale, availableFlatLocales, function (loc) {
393
			var jsLoc = loc.replace("-", "_");
394
			var translationPackage = bundlePackage + "." + jsLoc;
395
			var loaded = false;
396
			if (!dojo.hostenv.findModule(translationPackage)) {
397
				dojo.hostenv.startPackage(translationPackage);
398
				var module = [modpath];
399
				if (loc != "ROOT") {
400
					module.push(loc);
401
				}
402
				module.push(bundleName);
403
				var filespec = module.join("/") + ".js";
404
				loaded = dojo.hostenv.loadPath(filespec, null, function (hash) {
405
					var clazz = function () {
406
					};
407
					clazz.prototype = parent;
408
					bundle[jsLoc] = new clazz();
409
					for (var j in hash) {
410
						bundle[jsLoc][j] = hash[j];
411
					}
412
				});
413
			} else {
414
				loaded = true;
415
			}
416
			if (loaded && bundle[jsLoc]) {
417
				parent = bundle[jsLoc];
418
			} else {
419
				bundle[jsLoc] = parent;
420
			}
421
			if (availableFlatLocales) {
422
				return true;
423
			}
424
		});
425
	}
426
	if (availableFlatLocales && targetLocale != bestLocale) {
427
		bundle[targetLocale.replace("-", "_")] = bundle[bestLocale.replace("-", "_")];
428
	}
429
};
430
(function () {
431
	var extra = djConfig.extraLocale;
432
	if (extra) {
433
		if (!extra instanceof Array) {
434
			extra = [extra];
435
		}
436
		var req = dojo.requireLocalization;
437
		dojo.requireLocalization = function (m, b, locale, availableFlatLocales) {
438
			req(m, b, locale, availableFlatLocales);
439
			if (locale) {
440
				return;
441
			}
442
			for (var i = 0; i < extra.length; i++) {
443
				req(m, b, extra[i], availableFlatLocales);
444
			}
445
		};
446
	}
447
})();
448