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