PageRenderTime 85ms CodeModel.GetById 43ms app.highlight 6ms RepoModel.GetById 35ms app.codeStats 0ms

/timeline/ext/planning/planning-api.js

http://showslow.googlecode.com/
JavaScript | 92 lines | 67 code | 10 blank | 15 comment | 12 complexity | 7ad844b52986ba133cd7f63e0f9c990f MD5 | raw file
 1/*==================================================
 2 *  Planning Extension
 3 *
 4 *  This file will load all the Javascript files
 5 *  necessary to make the extension work.
 6 *
 7 *==================================================
 8 */
 9 
10(function() {
11    var javascriptFiles = [
12        "planning.js",
13        "units.js",
14        "ether-painters.js",
15        "labellers.js"
16    ];
17    var cssFiles = [
18    ];
19    
20    var localizedJavascriptFiles = [
21        "labellers.js"
22    ];
23    var localizedCssFiles = [
24    ];
25    
26    // ISO-639 language codes, ISO-3166 country codes (2 characters)
27    var supportedLocales = [
28        "en"        // English
29    ];
30    
31    try {
32        var includeJavascriptFile = function(filename) {
33            document.write("<script src='" + Timeline.urlPrefix + "ext/planning/scripts/" + filename + "' type='text/javascript'></script>");
34        };
35        var includeCssFile = function(filename) {
36            document.write("<link rel='stylesheet' href='" + Timeline.urlPrefix + "ext/planning/styles/" + filename + "' type='text/css'/>");
37        }
38        
39        /*
40         *  Include non-localized files
41         */
42        for (var i = 0; i < javascriptFiles.length; i++) {
43            includeJavascriptFile(javascriptFiles[i]);
44        }
45        for (var i = 0; i < cssFiles.length; i++) {
46            includeCssFile(cssFiles[i]);
47        }
48        
49        /*
50         *  Include localized files
51         */
52        var loadLocale = [];
53        var tryExactLocale = function(locale) {
54            for (var l = 0; l < supportedLocales.length; l++) {
55                if (locale == supportedLocales[l]) {
56                    loadLocale[locale] = true;
57                    return true;
58                }
59            }
60            return false;
61        }
62        var tryLocale = function(locale) {
63            if (tryExactLocale(locale)) {
64                return locale;
65            }
66            
67            var dash = locale.indexOf("-");
68            if (dash > 0 && tryExactLocale(locale.substr(0, dash))) {
69                return locale.substr(0, dash);
70            }
71            
72            return null;
73        }
74        
75        tryLocale(Timeline.serverLocale);
76        tryLocale(Timeline.clientLocale);
77        
78        for (var l = 0; l < supportedLocales.length; l++) {
79            var locale = supportedLocales[l];
80            if (loadLocale[locale]) {
81                for (var i = 0; i < localizedJavascriptFiles.length; i++) {
82                    includeJavascriptFile("l10n/" + locale + "/" + localizedJavascriptFiles[i]);
83                }
84                for (var i = 0; i < localizedCssFiles.length; i++) {
85                    includeCssFile("l10n/" + locale + "/" + localizedCssFiles[i]);
86                }
87            }
88        }
89    } catch (e) {
90        alert(e);
91    }
92})();