@Target(value=TYPE) @Inherited @Retention(value=RUNTIME) public @interface JavaScript
source() or sources() when you have
multiple files. The path could be declared as filesystem lookup or classpath.
The classpath lookup also supports wildcards. For example the declaration of
JQuery, vani will look for a classpath resource with the name
jquery-2.2.1.js:
@JavaScript(source = "classpath:jquery-2.2.1.js")
public interface JQuery{
...
}
The following declaration shows using multiple sources. The file
my.js, which path starts in the current working directory, will be
appended to the classpath resource jquery-2.2.1.js:
@JavaScript(sources = {"classpath:org/vani/javascript/jquery-2.2.1.js","website/scripts/my.js"})
public interface JQuery{
...
}
DetectionScript). This will be executed to check whether
the source must be injected or not.
After the execution in the browser (see JavascriptExecutor for more
details), the return value will be converted. If you need a custom handling
of this value, you can define a @TypeHandler with
@JsTypeHandler.
The call of your javascript function or code bound to a method of
js-interface will be done by a call function. You can define your own
function (see JsCallFunction).
VaniUtils, because
for handling jquery elements, a uuid is used for caching. Therefore the
VaniUtils.uuid4() will be needed:
@JavaScriptDependency(VaniUtils.class)
@JavaScript(source = "classpath:jquery-regex-selector.js")
public interface JQueryRegexSelectorPlugin {
...
}
JQueryRegexSelectorPlugin to provide a
regex-selector:
@JavaScript(source = "classpath:jquery-regex-selector.js")
public interface JQueryRegexSelectorPlugin {
...
}
@JavaScript(source = "classpath:jquery-2.2.1.js")
public interface JQuery extends JQueryRegexSelectorPlugin {
...
}
In the above example, the source code of JQueryRegexSelectorPlugin
will be append to the one of JQuery.
JsCallFunction,
JsTypeHandler,
JavascriptExecutor,
TypeHandlerCopyright © 2016. All rights reserved.