use of org.apache.wicket.markup.head.JavaScriptReferenceHeaderItem in project wicket by apache.
the class ResourceBundles method addJavaScriptBundle.
/**
* Adds a javascript bundle that is automatically generated by concatenating the given package
* resources. If the given resources depend on each other, you should make sure that the
* resources are provided in the order they need to be concatenated. If the resources depend on
* other resources, that are not part of the bundle, the bundle will inherit these dependencies.
*
* This method is equivalent to {@link #addBundle(HeaderItem)} with a
* {@link JavaScriptHeaderItem} for a {@link ConcatResourceBundleReference}.
*
* @param scope
* The {@linkplain ResourceReference#getScope() scope} of the bundle
* @param defer
* specifies that the execution of a script should be deferred (delayed) until after
* the page has been loaded.
* @param name
* The name of the resource. This will show up as the filename in the markup.
* @param references
* The resources this bundle will consist of.
* @return the newly created bundle
*/
public JavaScriptReferenceHeaderItem addJavaScriptBundle(Class<?> scope, String name, boolean defer, JavaScriptResourceReference... references) {
List<JavaScriptReferenceHeaderItem> items = new ArrayList<>();
for (JavaScriptResourceReference curReference : references) {
items.add(JavaScriptHeaderItem.forReference(curReference));
}
ConcatResourceBundleReference<JavaScriptReferenceHeaderItem> bundleReference = newBundleResourceReference(scope, name, items);
if (Application.exists()) {
IJavaScriptCompressor javaScriptCompressor = Application.get().getResourceSettings().getJavaScriptCompressor();
bundleReference.setCompressor(javaScriptCompressor);
}
if (defer) {
return addBundle(JavaScriptHeaderItem.forReference(bundleReference, defer));
} else {
return addBundle(JavaScriptHeaderItem.forReference(bundleReference));
}
}
use of org.apache.wicket.markup.head.JavaScriptReferenceHeaderItem in project webanno by webanno.
the class BootstrapAwareJQueryUIJavaScriptResourceReference method getDependencies.
@Override
public List<HeaderItem> getDependencies() {
IBootstrapSettings settings = Bootstrap.getSettings();
final JavaScriptReferenceHeaderItem jsReference = JavaScriptHeaderItem.forReference(settings.getJsResourceReference(), new PageParameters(), "bootstrap-js", settings.deferJavascript());
return Dependencies.combine(super.getDependencies(), jsReference);
}
use of org.apache.wicket.markup.head.JavaScriptReferenceHeaderItem in project wicket by apache.
the class DecoratingHeaderResponseTest method decoratedStringPrepend.
/**
* Basic IHeaderResponseDecorator, just prepending the DECORATED string to resource name.
*
* @throws IOException
* @throws ResourceStreamNotFoundException
* @throws ParseException
*/
@Test
public void decoratedStringPrepend() throws IOException, ResourceStreamNotFoundException, ParseException {
tester.getApplication().setHeaderResponseDecorator(new IHeaderResponseDecorator() {
@Override
public IHeaderResponse decorate(IHeaderResponse response) {
return new ResourceAggregator(new DecoratingHeaderResponse(response) {
@Override
public void render(HeaderItem item) {
if (item instanceof JavaScriptReferenceHeaderItem) {
JavaScriptReferenceHeaderItem original = (JavaScriptReferenceHeaderItem) item;
item = JavaScriptHeaderItem.forReference(new PackageResourceReference("DECORATED-" + original.getReference().getName()), original.getId());
}
super.render(item);
}
});
}
});
tester.startPage(TestPage.class);
XmlPullParser parser = new XmlPullParser();
parser.parse(tester.getLastResponseAsString());
XmlTag tag = parser.nextTag();
boolean isDecorated = false;
do {
if (tag.isOpen() && "script".equals(tag.getName())) {
isDecorated = tag.getAttribute("src").toString().contains("DECORATED");
if (!isDecorated) {
fail();
}
break;
}
} while ((tag = parser.nextTag()) != null);
assertTrue(isDecorated);
}
Aggregations