use of org.apache.tapestry5.services.javascript.JavaScriptModuleConfiguration in project tapestry-5 by apache.
the class JavaScriptModule method setupApplicationCatalogModules.
@Contribute(ModuleManager.class)
public static void setupApplicationCatalogModules(MappedConfiguration<String, Object> configuration, LocalizationSetter localizationSetter, ComponentMessagesSource messagesSource, ResourceChangeTracker resourceChangeTracker, @Symbol(SymbolConstants.COMPACT_JSON) boolean compactJSON) {
for (Locale locale : localizationSetter.getSupportedLocales()) {
MessageCatalogResource resource = new MessageCatalogResource(locale, messagesSource, resourceChangeTracker, compactJSON);
configuration.add("t5/core/messages/" + locale.toString(), new JavaScriptModuleConfiguration(resource));
}
}
use of org.apache.tapestry5.services.javascript.JavaScriptModuleConfiguration in project tapestry-5 by apache.
the class JavaScriptModule method setupBaseModules.
@Contribute(ModuleManager.class)
public static void setupBaseModules(MappedConfiguration<String, Object> configuration, @Path("${tapestry.asset.root}/underscore-shim.js") Resource underscoreShim, @Path("${tapestry.asset.root}/jquery-shim.js") Resource jqueryShim, @Path("${tapestry.asset.root}/typeahead.js") Resource typeahead, @Path("${tapestry.asset.root}/moment-2.15.1.js") Resource moment, @Path("${tapestry.asset.root}/bootstrap/js/transition.js") Resource transition, @Path("${tapestry.asset.root}/bootstrap4/js/bootstrap-util.js") Resource bootstrapUtil, Compatibility compatibility) {
// The underscore shim module allows Underscore to be injected
configuration.add("underscore", new JavaScriptModuleConfiguration(underscoreShim));
configuration.add("jquery", new JavaScriptModuleConfiguration(jqueryShim));
if (compatibility.enabled(Trait.BOOTSTRAP_3)) {
final String[] modules = new String[] { "affix", "alert", "button", "carousel", "collapse", "dropdown", "modal", "scrollspy", "tab", "tooltip" };
addBootstrap3Modules(configuration, transition, modules);
Resource popover = transition.forFile("popover.js");
configuration.add("bootstrap/popover", new AMDWrapper(popover).require("bootstrap/tooltip").asJavaScriptModuleConfiguration());
}
if (compatibility.enabled(Trait.BOOTSTRAP_4)) {
configuration.add("bootstrap/bootstrap-util", new JavaScriptModuleConfiguration(bootstrapUtil));
configuration.add("bootstrap/popper", new JavaScriptModuleConfiguration(bootstrapUtil.forFile("popper.js")));
for (String name : new String[] { "alert", "button", "carousel", "collapse", "dropdown", "modal", "scrollspy", "tab", "tooltip" }) {
Resource lib = bootstrapUtil.forFile(name + ".js");
if (lib.exists()) {
configuration.add("bootstrap/" + name, new JavaScriptModuleConfiguration(lib).dependsOn("bootstrap/bootstrap-util").dependsOn("bootstrap/popper"));
}
}
}
// is completely disabled
if (!compatibility.enabled(Trait.BOOTSTRAP_3) && !compatibility.enabled(Trait.BOOTSTRAP_4)) {
final String[] modules = new String[] { "alert", "dropdown", "collapse" };
addBootstrap3Modules(configuration, transition, modules);
}
configuration.add("t5/core/typeahead", new JavaScriptModuleConfiguration(typeahead).dependsOn("jquery"));
configuration.add("moment", new JavaScriptModuleConfiguration(moment));
}
use of org.apache.tapestry5.services.javascript.JavaScriptModuleConfiguration in project tapestry-5 by apache.
the class ModuleManagerImpl method buildBaseConfig.
private JSONObject buildBaseConfig(Map<String, JavaScriptModuleConfiguration> configuration, boolean devMode) {
JSONObject config = new JSONObject();
// In DevMode, wait up to five minutes for a script, as the developer may be using the debugger.
if (devMode) {
config.put("waitSeconds", 300);
}
for (String name : configuration.keySet()) {
JavaScriptModuleConfiguration module = configuration.get(name);
shimModuleNameToResource.put(name, module.resource);
// on the server.
if (module.getNeedsConfiguration()) {
// Others are libraries being shimmed as AMD modules, and need some configuration
// to ensure that everything hooks up properly on the client.
addModuleToConfig(config, name, module);
}
}
return config;
}
use of org.apache.tapestry5.services.javascript.JavaScriptModuleConfiguration in project tapestry-5 by apache.
the class ModuleManagerImpl method addModuleToConfig.
private void addModuleToConfig(JSONObject config, String name, JavaScriptModuleConfiguration module) {
JSONObject shimConfig = config.in("shim");
boolean nestDependencies = false;
String exports = module.getExports();
if (exports != null) {
shimConfig.in(name).put("exports", exports);
nestDependencies = true;
}
String initExpression = module.getInitExpression();
if (initExpression != null) {
String function = String.format("function() { return %s; }", initExpression);
shimConfig.in(name).put("init", new JSONLiteral(function));
nestDependencies = true;
}
List<String> dependencies = module.getDependencies();
if (dependencies != null) {
JSONObject container = nestDependencies ? shimConfig.in(name) : shimConfig;
String key = nestDependencies ? "deps" : name;
for (String dep : dependencies) {
container.append(key, dep);
}
}
}
Aggregations