summaryrefslogtreecommitdiffstats
path: root/WebContent/VAADIN/vaadinBootstrap.js
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2011-11-24 15:33:22 +0200
committerLeif Åstrand <leif@vaadin.com>2011-11-24 15:33:22 +0200
commit0b4297ddd24758e2a7235c5afdbcc0c94613c298 (patch)
tree7a58bcd4595d158dbd50b3ec85e49853dae8a8b0 /WebContent/VAADIN/vaadinBootstrap.js
parent181b76b3a041d061e0a8fff3fbfaf7f0e64da2da (diff)
downloadvaadin-framework-0b4297ddd24758e2a7235c5afdbcc0c94613c298.tar.gz
vaadin-framework-0b4297ddd24758e2a7235c5afdbcc0c94613c298.zip
Introduce vaadinBootstrap.js and use it to init the widgetset
Diffstat (limited to 'WebContent/VAADIN/vaadinBootstrap.js')
-rw-r--r--WebContent/VAADIN/vaadinBootstrap.js115
1 files changed, 115 insertions, 0 deletions
diff --git a/WebContent/VAADIN/vaadinBootstrap.js b/WebContent/VAADIN/vaadinBootstrap.js
new file mode 100644
index 0000000000..917aa2aa4a
--- /dev/null
+++ b/WebContent/VAADIN/vaadinBootstrap.js
@@ -0,0 +1,115 @@
+(function() {
+ var defaults;
+ var apps = {};
+ var themesLoaded = {};
+ var widgetsetsRequested = {}
+ var widgetsetApps = {};
+
+
+ var log = function() {
+ if (console && console.log) {
+ console.log(arguments);
+ }
+ }
+
+ var loadTheme = function(url) {
+ log("loadTheme", url);
+ if(!themesLoaded[url]) {
+ var stylesheet = document.createElement('link');
+ stylesheet.setAttribute('rel', 'stylesheet');
+ stylesheet.setAttribute('type', 'text/css');
+ stylesheet.setAttribute('href', url + "/styles.css");
+ document.getElementsByTagName('head')[0].appendChild(stylesheet);
+ themesLoaded[url] = true;
+ }
+ }
+
+ var isWidgetsetLoaded = function(widgetset) {
+ var className = widgetset.replace(/\./g, "_");
+ return (typeof window[className]) != "undefined";
+ }
+
+ var loadWidgetset = function(basePath, widgetset) {
+ if (widgetsetsRequested[widgetset]) {
+ //TODO Tell the widgetset to load another application
+ return;
+ }
+ log("load widgetset", basePath, widgetset)
+ setTimeout(function() {
+ if (!isWidgetsetLoaded(widgetset)) {
+ alert("Failed to load the widgetset: " + url);
+ }
+ }, 15000);
+
+ var url = basePath + widgetset + "/" + widgetset + ".nocache.js?" + new Date().getTime();
+
+ //document.write("<script type='text/javascript' src='"+url+"'></script>");
+
+ var scriptTag = document.createElement('script');
+ scriptTag.setAttribute('type', 'text/javascript');
+ scriptTag.setAttribute('src', url);
+ document.getElementsByTagName('head')[0].appendChild(scriptTag);
+
+ widgetsetsRequested[widgetset] = true;
+ }
+
+ window.vaadin = window.vaadin || {
+ setDefaults: function(d) {
+ if (defaults) {
+ throw "Defaults already defined";
+ }
+ log("Got defaults", defaults)
+ defaults = d;
+ },
+ initApplication: function(appId, config) {
+ if (apps[appId]) {
+ throw "Application " + appId + " already initialized";
+ }
+ log("init application", appId, config);
+ var getConfig = function(name) {
+ var value = config[name];
+ if (value === undefined) {
+ value = defaults[name];
+ }
+ return value;
+ }
+
+ var themeUri = getConfig('themeUri');
+ if (themeUri) {
+ loadTheme(themeUri);
+ }
+
+ var widgetsetBase = getConfig('widgetsetBase');
+ var widgetset = getConfig('widgetset');
+ if (widgetset && widgetsetBase) {
+ loadWidgetset(widgetsetBase, widgetset);
+ if (widgetsetApps[widgetset]) {
+ widgetsetApps[widgetset].push(appId);
+ } else {
+ widgetsetApps[widgetset] = [appId];
+ }
+ }
+
+ //Export public data
+ var app = {
+ 'getConfig': getConfig
+ };
+ apps[appId] = app;
+
+ return app;
+ },
+ getApp: function(appId) {
+ var app = apps[appId];
+ return app;
+ },
+ popWidgetsetApp: function(widgetset) {
+ if (widgetsetApps[widgetset]) {
+ return widgetsetApps[widgetset].pop();
+ } else {
+ return null;
+ }
+ }
+ };
+
+ log('Vaadin bootstrap loaded');
+})(); \ No newline at end of file