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.ns");
|
|
|
12 |
dojo.ns = {namespaces:{}, failed:{}, loading:{}, loaded:{}, register:function (name, module, resolver, noOverride) {
|
|
|
13 |
if (!noOverride || !this.namespaces[name]) {
|
|
|
14 |
this.namespaces[name] = new dojo.ns.Ns(name, module, resolver);
|
|
|
15 |
}
|
|
|
16 |
}, allow:function (name) {
|
|
|
17 |
if (this.failed[name]) {
|
|
|
18 |
return false;
|
|
|
19 |
}
|
|
|
20 |
if ((djConfig.excludeNamespace) && (dojo.lang.inArray(djConfig.excludeNamespace, name))) {
|
|
|
21 |
return false;
|
|
|
22 |
}
|
|
|
23 |
return ((name == this.dojo) || (!djConfig.includeNamespace) || (dojo.lang.inArray(djConfig.includeNamespace, name)));
|
|
|
24 |
}, get:function (name) {
|
|
|
25 |
return this.namespaces[name];
|
|
|
26 |
}, require:function (name) {
|
|
|
27 |
var ns = this.namespaces[name];
|
|
|
28 |
if ((ns) && (this.loaded[name])) {
|
|
|
29 |
return ns;
|
|
|
30 |
}
|
|
|
31 |
if (!this.allow(name)) {
|
|
|
32 |
return false;
|
|
|
33 |
}
|
|
|
34 |
if (this.loading[name]) {
|
|
|
35 |
dojo.debug("dojo.namespace.require: re-entrant request to load namespace \"" + name + "\" must fail.");
|
|
|
36 |
return false;
|
|
|
37 |
}
|
|
|
38 |
var req = dojo.require;
|
|
|
39 |
this.loading[name] = true;
|
|
|
40 |
try {
|
|
|
41 |
if (name == "dojo") {
|
|
|
42 |
req("dojo.namespaces.dojo");
|
|
|
43 |
} else {
|
|
|
44 |
if (!dojo.hostenv.moduleHasPrefix(name)) {
|
|
|
45 |
dojo.registerModulePath(name, "../" + name);
|
|
|
46 |
}
|
|
|
47 |
req([name, "manifest"].join("."), false, true);
|
|
|
48 |
}
|
|
|
49 |
if (!this.namespaces[name]) {
|
|
|
50 |
this.failed[name] = true;
|
|
|
51 |
}
|
|
|
52 |
}
|
|
|
53 |
finally {
|
|
|
54 |
this.loading[name] = false;
|
|
|
55 |
}
|
|
|
56 |
return this.namespaces[name];
|
|
|
57 |
}};
|
|
|
58 |
dojo.ns.Ns = function (name, module, resolver) {
|
|
|
59 |
this.name = name;
|
|
|
60 |
this.module = module;
|
|
|
61 |
this.resolver = resolver;
|
|
|
62 |
this._loaded = [];
|
|
|
63 |
this._failed = [];
|
|
|
64 |
};
|
|
|
65 |
dojo.ns.Ns.prototype.resolve = function (name, domain, omitModuleCheck) {
|
|
|
66 |
if (!this.resolver || djConfig["skipAutoRequire"]) {
|
|
|
67 |
return false;
|
|
|
68 |
}
|
|
|
69 |
var fullName = this.resolver(name, domain);
|
|
|
70 |
if ((fullName) && (!this._loaded[fullName]) && (!this._failed[fullName])) {
|
|
|
71 |
var req = dojo.require;
|
|
|
72 |
req(fullName, false, true);
|
|
|
73 |
if (dojo.hostenv.findModule(fullName, false)) {
|
|
|
74 |
this._loaded[fullName] = true;
|
|
|
75 |
} else {
|
|
|
76 |
if (!omitModuleCheck) {
|
|
|
77 |
dojo.raise("dojo.ns.Ns.resolve: module '" + fullName + "' not found after loading via namespace '" + this.name + "'");
|
|
|
78 |
}
|
|
|
79 |
this._failed[fullName] = true;
|
|
|
80 |
}
|
|
|
81 |
}
|
|
|
82 |
return Boolean(this._loaded[fullName]);
|
|
|
83 |
};
|
|
|
84 |
dojo.registerNamespace = function (name, module, resolver) {
|
|
|
85 |
dojo.ns.register.apply(dojo.ns, arguments);
|
|
|
86 |
};
|
|
|
87 |
dojo.registerNamespaceResolver = function (name, resolver) {
|
|
|
88 |
var n = dojo.ns.namespaces[name];
|
|
|
89 |
if (n) {
|
|
|
90 |
n.resolver = resolver;
|
|
|
91 |
}
|
|
|
92 |
};
|
|
|
93 |
dojo.registerNamespaceManifest = function (module, path, name, widgetModule, resolver) {
|
|
|
94 |
dojo.registerModulePath(name, path);
|
|
|
95 |
dojo.registerNamespace(name, widgetModule, resolver);
|
|
|
96 |
};
|
|
|
97 |
dojo.registerNamespace("dojo", "dojo.widget");
|
|
|
98 |
|