Search in sources :

Example 1 with AMDWrapper

use of org.apache.tapestry5.services.javascript.AMDWrapper in project tapestry-5 by apache.

the class JavaScriptModule method addBootstrap3Modules.

private static void addBootstrap3Modules(MappedConfiguration<String, Object> configuration, Resource transition, final String[] modules) {
    configuration.add("bootstrap/transition", new AMDWrapper(transition).require("jquery", "$").asJavaScriptModuleConfiguration());
    for (String name : modules) {
        Resource lib = transition.forFile(name + ".js");
        configuration.add("bootstrap/" + name, new AMDWrapper(lib).require("bootstrap/transition").asJavaScriptModuleConfiguration());
    }
}
Also used : AMDWrapper(org.apache.tapestry5.services.javascript.AMDWrapper) MessageCatalogResource(org.apache.tapestry5.internal.util.MessageCatalogResource) Resource(org.apache.tapestry5.commons.Resource)

Example 2 with AMDWrapper

use of org.apache.tapestry5.services.javascript.AMDWrapper 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)

Aggregations

Resource (org.apache.tapestry5.commons.Resource)2 MessageCatalogResource (org.apache.tapestry5.internal.util.MessageCatalogResource)2 AMDWrapper (org.apache.tapestry5.services.javascript.AMDWrapper)2 Contribute (org.apache.tapestry5.ioc.annotations.Contribute)1 JavaScriptModuleConfiguration (org.apache.tapestry5.services.javascript.JavaScriptModuleConfiguration)1