protected void appendMainScriptTagContents(BootstrapContext context, StringBuilder builder) throws IOException { JsonObject appConfig = context.getApplicationParameters(); boolean isDebug = !context.getSession().getConfiguration() .isProductionMode(); if (isDebug) { /* * Add tracking needed for getting bootstrap metrics to the client * side Profiler if another implementation hasn't already been * added. */ builder.append( "if (typeof window.__gwtStatsEvent != 'function') {\n"); builder.append("vaadin.gwtStatsEvents = [];\n"); builder.append( "window.__gwtStatsEvent = function(event) {vaadin.gwtStatsEvents.push(event); return true;};\n"); builder.append("}\n"); } builder.append("vaadin.initApplication(\""); builder.append(context.getAppId()); builder.append("\","); appendJsonObject(builder, appConfig, isDebug); builder.append(");\n"); }
mainDiv.attr("id", context.getAppId()); mainDiv.addClass("v-app"); mainDiv.addClass(context.getThemeName());
private static String getBootstrapJS(JsonValue initialUIDL, BootstrapContext context) { boolean productionMode = context.getSession().getConfiguration() .isProductionMode(); String result = getBootstrapJS(); JsonObject appConfig = context.getApplicationParameters(); int indent = 0; if (!productionMode) { indent = 4; } String appConfigString = JsonUtil.stringify(appConfig, indent); String initialUIDLString = JsonUtil.stringify(initialUIDL, indent); // Browser interpret </script> as end of script no matter if it is // inside a string or not so we must escape it initialUIDLString = scriptEndTagPattern.matcher(initialUIDLString) .replaceAll("<\\\\x2F$1"); if (!productionMode) { // only used in debug mode by profiler result = result.replace("{{GWT_STAT_EVENTS}}", GWT_STAT_EVENTS_JS); } else { result = result.replace("{{GWT_STAT_EVENTS}}", ""); } result = result.replace("{{APP_ID}}", context.getAppId()); result = result.replace("{{INITIAL_UIDL}}", initialUIDLString); result = result.replace("{{CONFIG_JSON}}", appConfigString); return result; }