diff options
author | Leif Åstrand <leif@vaadin.com> | 2011-11-25 16:04:20 +0200 |
---|---|---|
committer | Leif Åstrand <leif@vaadin.com> | 2011-11-25 16:04:20 +0200 |
commit | 55948aefe8ead5054a83ec84d2e3624ffc1e7427 (patch) | |
tree | 7847a0bc9a16048fc5fca60eb6d13dc138afee96 /WebContent/VAADIN/vaadinBootstrap.js | |
parent | d4057da1cd46f78d17a2ed678fe01ad1e04c5306 (diff) | |
download | vaadin-framework-55948aefe8ead5054a83ec84d2e3624ffc1e7427.tar.gz vaadin-framework-55948aefe8ead5054a83ec84d2e3624ffc1e7427.zip |
Initial support for lazy root creation
Diffstat (limited to 'WebContent/VAADIN/vaadinBootstrap.js')
-rw-r--r-- | WebContent/VAADIN/vaadinBootstrap.js | 90 |
1 files changed, 67 insertions, 23 deletions
diff --git a/WebContent/VAADIN/vaadinBootstrap.js b/WebContent/VAADIN/vaadinBootstrap.js index 0aec37efe7..2178e2abe2 100644 --- a/WebContent/VAADIN/vaadinBootstrap.js +++ b/WebContent/VAADIN/vaadinBootstrap.js @@ -43,8 +43,6 @@ 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); @@ -58,7 +56,7 @@ if (defaults) { throw "Defaults already defined"; } - log("Got defaults", defaults) + log("Got defaults", d) defaults = d; }, initApplication: function(appId, config) { @@ -73,27 +71,45 @@ } 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]; - } - } - if (getConfig("debug")) { - // TODO debug state is now global for the entire page, but should somehow only be set for the current application - window.vaadin.debug = true; - } + var fetchRootConfig = function() { + log('Fetching root config'); + var url = getConfig('appUri'); + // Root id + url += ((/\?/).test(url) ? "&" : "?") + "browserDetails"; + url += '&rootId=' + getConfig('rootId'); + // Uri fragment + url += '&f=' + encodeURIComponent(location.hash); + // Timestamp to avoid caching + url += '&' + (new Date()).getTime(); + + var r = new XMLHttpRequest(); + r.open('POST', url, true); + r.onreadystatechange = function (aEvt) { + if (r.readyState == 4) { + if (r.status == 200){ + log(r.responseText); + // TODO Does this work in all supported browsers? + var updatedConfig = JSON.parse(r.responseText); + + // Copy new properties to the config object + for (var property in updatedConfig) { + if (updatedConfig.hasOwnProperty(property)) { + config[property] = updatedConfig[property]; + } + } + + // Try bootstrapping again, this time without fetching missing info + bootstrapApp(false); + } else { + log('Error', r.statusText); + } + } + }; + r.send(null); + + log('sending request to ', url); + }; //Export public data var app = { @@ -101,6 +117,34 @@ }; apps[appId] = app; + var bootstrapApp = function(mayDefer) { + 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]; + } + } else if (mayDefer) { + fetchRootConfig(); + } else { + throw "Widgetset not defined"; + } + } + bootstrapApp(true); + + if (getConfig("debug")) { + // TODO debug state is now global for the entire page, but should somehow only be set for the current application + window.vaadin.debug = true; + } + return app; }, getApp: function(appId) { |