Search in sources :

Example 1 with JavaScriptModuleConfiguration

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));
    }
}
Also used : Locale(java.util.Locale) MessageCatalogResource(org.apache.tapestry5.internal.util.MessageCatalogResource) JavaScriptModuleConfiguration(org.apache.tapestry5.services.javascript.JavaScriptModuleConfiguration) Contribute(org.apache.tapestry5.ioc.annotations.Contribute)

Example 2 with JavaScriptModuleConfiguration

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));
}
Also used : JavaScriptModuleConfiguration(org.apache.tapestry5.services.javascript.JavaScriptModuleConfiguration) AMDWrapper(org.apache.tapestry5.services.javascript.AMDWrapper) MessageCatalogResource(org.apache.tapestry5.internal.util.MessageCatalogResource) Resource(org.apache.tapestry5.commons.Resource) Contribute(org.apache.tapestry5.ioc.annotations.Contribute)

Example 3 with JavaScriptModuleConfiguration

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;
}
Also used : JavaScriptModuleConfiguration(org.apache.tapestry5.services.javascript.JavaScriptModuleConfiguration) JSONObject(org.apache.tapestry5.json.JSONObject)

Example 4 with JavaScriptModuleConfiguration

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);
        }
    }
}
Also used : JSONObject(org.apache.tapestry5.json.JSONObject) JSONLiteral(org.apache.tapestry5.json.JSONLiteral)

Aggregations

JavaScriptModuleConfiguration (org.apache.tapestry5.services.javascript.JavaScriptModuleConfiguration)3 MessageCatalogResource (org.apache.tapestry5.internal.util.MessageCatalogResource)2 Contribute (org.apache.tapestry5.ioc.annotations.Contribute)2 JSONObject (org.apache.tapestry5.json.JSONObject)2 Locale (java.util.Locale)1 Resource (org.apache.tapestry5.commons.Resource)1 JSONLiteral (org.apache.tapestry5.json.JSONLiteral)1 AMDWrapper (org.apache.tapestry5.services.javascript.AMDWrapper)1