WIP: Thymoljs
[website] / dist / js / thymol.js
1 /*-------------------- Thymol - the flavour of Thymeleaf --------------------*
2
3    Thymol version 2.0.0 Copyright (C) 2012-2015 James J. Benson
4    jjbenson .AT. users.sf.net (http://www.thymoljs.org/)
5
6    Licensed under the Apache License, Version 2.0 (the "License");
7    you may not use this file except in compliance with the License.
8    You may obtain a copy of the License at
9
10        http://www.apache.org/licenses/LICENSE-2.0
11
12    Unless required by applicable law or agreed to in writing, software
13    distributed under the License is distributed on an "AS IS" basis,
14    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either expressed or implied.
15    See the License for the specific language governing permissions and
16    limitations under the License.
17
18  *---------------------------------------------------------------------------*/
19
20 (function() {
21     var thymolConfiguration = {
22         thScriptName: "thymol-full.js",
23         thJQuerySource: "http://code.jquery.com/jquery-1.11.1.min.js",
24         thDefaultPrefix: "th",
25         thDefaultDataPrefix: "data",
26         thDefaultPrecision: 10,
27         thDefaultProtocol: "file:///",
28         thDefaultLocale: "en",
29         thDefaultPrecedence: 2e4,
30         thDefaultMessagePath: "",
31         thDefaultResourcePath: "",
32         thDefaultMessagesBaseName: "Messages",
33         thDefaultRelativeRootPath: "",
34         thDefaultExtendedMapping: false,
35         thDefaultLocalMessages: true,
36         thDefaultDisableMessages: false,
37         thDefaultTemplateSuffix: ".html"
38     };
39     thymol = function(conf) {
40         conf.ready = function(func) {
41             if (typeof thymolDeferredFunctions === "undefined" || thymolDeferredFunctions === null) {
42                 thymolDeferredFunctions = [];
43             }
44             thymolDeferredFunctions.push(func);
45         };
46         return conf;
47     }(thymolConfiguration);
48     thymol.thDomParser = DOMParser;
49     thymol.thWindow = window;
50     var toc = 0;
51     var loadScript = function(script, params) {
52         var el = document.createElement("script");
53         el.async = false;
54         if (typeof script !== "undefined" && script !== null) {
55             el.src = script;
56         }
57         if (typeof params !== "undefined" && params !== null) {
58             el.src += params.charAt(0) === "?" ? params : "?" + params;
59         }
60         el.type = "text/javascript";
61         (document.getElementsByTagName("HEAD")[0] || document.body).appendChild(el);
62     };
63     var scripts = document.getElementsByTagName("script");
64     var script = document.currentScript || scripts[scripts.length - 1];
65     var scriptSrc = script.getAttribute("src");
66     var pathEnd = scriptSrc.lastIndexOf("/");
67     if (pathEnd >= 0) {
68         thymol.thLocation = scriptSrc.substring(0, 1 + pathEnd);
69     }
70     var jquerySrc = script.getAttribute("data-jquery-src");
71     if (!!jquerySrc || "" === jquerySrc) {
72         thymol.thJQuerySource = jquerySrc;
73         if ("" !== thymol.thJQuerySource) {
74             loadScript(thymol.thJQuerySource);
75         }
76     } else if (typeof thymol.thJQuerySource !== "undefined" && thymol.thJQuerySource !== null && thymol.thJQuerySource.length > 0) {
77         var hasProtocol = thymol.thJQuerySource.indexOf(":/") >= 0;
78         if (hasProtocol || thymol.thJQuerySource.charAt(0) === "/") {
79             if (!hasProtocol) {
80                 loadScript(thymol.thDefaultProtocol + thymol.thJQuerySource);
81             } else {
82                 loadScript(thymol.thJQuerySource);
83             }
84         } else {
85             loadScript(thymol.thLocation + thymol.thJQuerySource);
86         }
87     }
88     var thymolSrc = script.getAttribute("data-thymol-src");
89     if (!!thymolSrc) {
90         thymol.thScriptName = thymolSrc;
91     }
92     var parameters = null;
93     for (var i = 0, iLimit = scripts.length; i < iLimit; i++) {
94         parameters = scripts[i].getAttribute("data-thymol-parameters");
95         if (!!parameters) {
96             break;
97         }
98     }
99     loadScript(thymol.thLocation + thymol.thScriptName, parameters);
100 })();