PageSourceSearch

https://api.simile-widgets.org/timeplot/1.1/timeplot-api.js

js simile-widgets.org collected 2026-09-24 08:40:50 UTC 6,877 bytes, 189 lines download raw bytes

1/*==================================================
2 *  Simile Timeplot API
3 *
4 *  Include Timeplot in your HTML file as follows:
5 *    <script src="http://api.simile-widgets.org/timeplot/1.1/timeplot-api.js" type="text/javascript"></script>
6 *
7 *==================================================*/
8
9(function() {
10
11    var local = false;
12
13    // obtain local mode from the document URL    
14    if (document.location.search.length > 0) {
15        var params = document.location.search.substr(1).split("&");
16        for (var i = 0; i < params.length; i++) {
17            if (params[i] == "local") {
18                local = true;
19            }
20        }
21    }
22
23    // obtain local mode from the script URL params attribute
24    if (!local) {
25        var heads = document.documentElement.getElementsByTagName("head");
26        for (var h = 0; h < heads.length; h++) {
27            var node = heads[h].firstChild;
28            while (node != null) {
29                if (node.nodeType == 1 && node.tagName.toLowerCase() == "script") {
30                    var url = node.src;
31                    if (url.indexOf("timeplot-api") >= 0) {
32                        local = (url.indexOf("local") >= 0);
33                    }
34                }
35                node = node.nextSibling;
36            }
37        }
38    }
39
40    // Load Timeplot if it's not already loaded (after SimileAjax and Timeline)
41    var loadTimeplot = function() {
42
43        if (typeof window.Timeplot != "undefined") {
44            return;
45        }
46        
47        window.Timeplot = {
48            loaded:     false,
49            params:     { bundle: true, autoCreate: true },
50            namespace:  "http://simile.mit.edu/2007/06/timeplot#",
51            importers:  {}
52        };
53    
54        var javascriptFiles = [
55            "timeplot.js",
56            "plot.js",
57            "sources.js",
58            "geometry.js",
59            "color.js",
60            "math.js",
61            "processor.js"
62        ];
63        var cssFiles = [
64            "timeplot.css"
65        ];
66        
67        var locales = [ "en" ];
68
69        var defaultClientLocales = ("language" in navigator ? navigator.language : navigator.browserLanguage).split(";");
70        for (var l = 0; l < defaultClientLocales.length; l++) {
71            var locale = defaultClientLocales[l];
72            if (locale != "en") {
73                var segments = locale.split("-");
74                if (segments.length > 1 && segments[0] != "en") {
75                    locales.push(segments[0]);
76                }
77                locales.push(locale);
78            }
79        }
80
81        var paramTypes = { bundle:Boolean, js:Array, css:Array, autoCreate:Boolean };
82        if (typeof Timeplot_urlPrefix == "string") {
83            Timeplot.urlPrefix = Timeplot_urlPrefix;
84            if ("Timeplot_parameters" in window) {
85                SimileAjax.parseURLParameters(Timeplot_parameters, Timeplot.params, paramTypes);
86            }
87        } else {
88            var url = SimileAjax.findScript(document, "/timeplot-api.js");
89            if (url == null) {
90                Timeplot.error = new Error("Failed to derive URL prefix for Simile Timeplot API code files");
91                return;
92            }
93            Timeplot.urlPrefix = url.substr(0, url.indexOf("timeplot-api.js"));
94        
95            SimileAjax.parseURLParameters(url, Timeplot.params, paramTypes);
96        }
97
98        if (Timeplot.params.locale) { // ISO-639 language codes,
99            // optional ISO-3166 country codes (2 characters)
100            if (Timeplot.params.locale != "en") {
101                var segments = Timeplot.params.locale.split("-");
102                if (segments.length > 1 && segments[0] != "en") {
103                    locales.push(segments[0]);
104                }
105                locales.push(Timeplot.params.locale);
106            }
107        }
108
109        var timeplotURLPrefix = Timeplot.urlPrefix;
110
111        if (local && !("console" in window)) {
112            var firebug = [ timeplotURLPrefix + "lib/firebug/firebug.js" ];
113            SimileAjax.includeJavascriptFiles(document, "", firebug);
114        }
115        
116        var canvas = document.createElement("canvas");
117
118        if (!canvas.getContext) {
119            var excanvas = [ timeplotURLPrefix + "lib/excanvas.js" ];
120            SimileAjax.includeJavascriptFiles(document, "", excanvas);
121        }
122        
123        var scriptURLs = Timeplot.params.js || [];
124        var cssURLs = Timeplot.params.css || [];
125
126        // Core scripts and styles
127        if (Timeplot.params.bundle && !local) {
128            scriptURLs.push(timeplotURLPrefix + "timeplot-bundle.js");
129            cssURLs.push(timeplotURLPrefix + "timeplot-bundle.css");
130        } else {
131            SimileAjax.prefixURLs(scriptURLs, timeplotURLPrefix + "scripts/", javascriptFiles);
132            SimileAjax.prefixURLs(cssURLs, timeplotURLPrefix + "styles/", cssFiles);
133        }
134        
135        // Localization
136        //for (var i = 0; i < locales.length; i++) {
137        //    scriptURLs.push(Timeplot.urlPrefix + "locales/" + locales[i] + "/locale.js");
138        //};
139        
140        window.SimileAjax_onLoad = function() {
141            if (local && window.console.open) window.console.open();
142            if (Timeplot.params.callback) {
143                eval(Timeplot.params.callback + "()");
144            }
145        }
146        
147        SimileAjax.includeJavascriptFiles(document, "", scriptURLs);
148        SimileAjax.includeCssFiles(document, "", cssURLs);
149        Timeplot.loaded = true;
150    };
151
152    // Load Timeline if it's not already loaded (after SimileAjax and before Timeplot)
153    var loadTimeline = function() {
154        if (typeof Timeline != "undefined") {
155            loadTimeplot();
156        } else {
157            var timelineURL = "http://api.simile-widgets.org/timeline/2.3.1/timeline-api.js?bundle=true";
158            window.SimileAjax_onLoad = loadTimeplot;
159            SimileAjax.includeJavascriptFile(document, timelineURL);
160        }
161    };
162    
163    // Load SimileAjax if it's not already loaded
164    if (typeof SimileAjax == "undefined") {
165        window.SimileAjax_onLoad = loadTimeline;
166        
167        var url = "http://api.simile-widgets.org/ajax/2.2.1/simile-ajax-api.js?bundle=true";
168                
169        var createScriptElement = function() {
170            var script = document.createElement("script");
171            script.type = "text/javascript";
172            script.language = "JavaScript";
173            script.src = url;
174            document.getElementsByTagName("head")[0].appendChild(script);
175        }
176        
177        if (document.body == null) {
178            try {
179                document.write("<script src='" + url + "' type='text/javascript'></script>");
180            } catch (e) {
181                createScriptElement();
182            }
183        } else {
184            createScriptElement();
185        }
186    } else {
187        loadTimeline();
188    }
189})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.