1 var namespace = (function() {
2 var namespace = function(nsString, callback) {
3 var nsParts = nsString.split(namespace.namespaceDelimiter);
5 var ns = namespace.root;
7 var len = nsParts.length;
8 for(var i=0; i<len; ++i)
11 ns[nsParts[i]] = {__namespaceAutoCreated: true};
18 var nsExt = callback.call(ns, ns);
29 ns.__namespaceAutoCreated = false;
31 else if( namespace.loadNamespace && ns.__namespaceAutoCreated )
35 var len = namespace.namespaceLocations.length;
36 for(var i=0; i<len; ++i)
38 var entry = namespace.namespaceLocations[i];
39 if( nsString.indexOf(entry.namespace) === 0 )
46 url += "/"+ nsString +".js";
52 success: function(res) {
55 var script = window.document.createElement("script");
56 script.type = "text/javascript";
58 window.document.body.appendChild(script);
61 error: function(xhr, textStatus, errorThrown) {
62 alert(textStatus +": "+ errorThrown);
73 window.namespaceRoot = {};
74 namespace.root = window.namespaceRoot;
75 namespace.namespaceDelimiter = ".";
76 namespace.namespaceLocations = [{namespace: "", location: "js"}];
77 namespace.loadNamespace = true;