Package run.undead.js
Class JS
java.lang.Object
run.undead.js.JS
JS is a helper class for building JS commands that are rendered in
UndeadTemplates.
JS provides a number of methods that make it easier to manipulate the DOM, dispatch client-side events,
and push events (and data) to the server.
Here is an example of using JS to toggle the visibility of an element:
// in your {@link View#render} method ...
public UndeadTemplate render() {
return Undead.HTML."""
<div id="my-div" class="hidden">Hello World!</div>
<button ud-click="\{ JS.toggle("#my-div") }">Toggle</button>
""" ;
}
JS commands are "chainable" so you can build up a list of commands to execute in order.
For example, the following hides an element and pushes an event to the server:
// in your {@link View#render} method ...
return Undead.HTML."""
<button ud-click="\{ JS.hide("#my-div").push("my-event") }">Hide</button>
""" ;
List of all the JS commands:
addClass(run.undead.js.AddClassOpts)dispatch(run.undead.js.DispatchOpts)exec(run.undead.js.ExecOpts)focus()focusFirst(run.undead.js.FocusFirstOpts)hide(run.undead.js.HideOpts)navigate(run.undead.js.NavigateOpts)patch(run.undead.js.PatchOpts)popFocus()push(run.undead.js.PushOpts)pushFocus(run.undead.js.PushFocusOpts)removeAttr(run.undead.js.RemoveAttrOpts)removeClass(run.undead.js.RemoveClassOpts)setAttr(run.undead.js.SetAttrOpts)show(run.undead.js.ShowOpts)toggle(run.undead.js.ToggleOpts)transition(run.undead.js.TransitionOpts)
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddClass adds css classes to DOM elementsaddClass(AddClassOpts addClassOpts) addClass adds css classes to DOM elementsdispatch dispatches an event to the DOMdispatch(DispatchOpts dispatchOpts) dispatch dispatches an event to the DOMexec executes JS commands located in element attributesexec executes JS commands located in element attributesfocus()focus sends focus to a selectorfocus sends focus to a selectorfocusFirst sends focus to the first focusable child in selectorfocusFirst(FocusFirstOpts focusFirstOpts) focusFirst sends focus to the first focusable child in selectorhide()hide makes DOM elements invisiblehide makes DOM elements invisiblenavigate sends a navigation event to the server and updates the browser's pushState history.navigate(NavigateOpts navigateOpts) navigate sends a navigation event to the server and updates the browser's pushState history.patch sends a patch event to the serverpatch sends a patch event to the serverpopFocus()popFocus focuses the last pushed elementpush sends an event to the serverpush sends an event to the serverpushFocus pushes focus from the source element to be later poppedpushFocus(PushFocusOpts pushFocusOpts) pushFocus pushes focus from the source element to be later poppedremoveAttr(String name) removeAttr removes an attribute from a DOM elementremoveAttr(RemoveAttrOpts removeAttrOpts) removeAttr removes an attribute from a DOM elementremoveClass(String classNames) removeClass removes css classes from DOM elementsremoveClass(RemoveClassOpts removeClassOpts) removeClass removes css classes from DOM elementssetAttr sets an attribute on a DOM elementsetAttr(SetAttrOpts setAttrOpts) setAttr sets an attribute on a DOM elementshow()show makes DOM elements visibleshow makes DOM elements visibletoggle()toggle toggles the visibility of DOM elementstoggle(ToggleOpts toggleOpts) toggle toggles the visibility of DOM elementstoJSON()`toJSON` returns the JSON String representation of the JS commands.transition(TransitionOpts transitionOpts) transition applies a css transition to a DOM element
-
Field Details
-
DEFAULT_DISPLAY
- See Also:
-
moshi
protected static final com.squareup.moshi.Moshi moshi -
listAdaptor
-
-
Constructor Details
-
JS
public JS()
-
-
Method Details
-
toJSON
`toJSON` returns the JSON String representation of the JS commands.- Returns:
-
addClass
addClass adds css classes to DOM elements- Parameters:
addClassOpts- options for the add_class command- Returns:
- the JS instance for chaining
- See Also:
-
addClass
addClass adds css classes to DOM elements- Parameters:
classNames- the css class names to add (space separated)- Returns:
- the JS instance for chaining
-
dispatch
dispatch dispatches an event to the DOM- Parameters:
dispatchOpts- options for the dispatch command- Returns:
- the JS instance for chaining
- See Also:
-
dispatch
dispatch dispatches an event to the DOM- Parameters:
event- the name of the event to dispatch- Returns:
- the JS instance for chaining
-
exec
exec executes JS commands located in element attributes- Parameters:
execOpts- options for the exec command- Returns:
- the JS instance for chaining
- See Also:
-
exec
exec executes JS commands located in element attributes- Parameters:
attr- the name of the attribute that contains the JS commands- Returns:
- the JS instance for chaining
-
focusFirst
focusFirst sends focus to the first focusable child in selector- Parameters:
focusFirstOpts- options for the focus_first command- Returns:
- the JS instance for chaining
- See Also:
-
focusFirst
focusFirst sends focus to the first focusable child in selector- Returns:
- the JS instance for chaining
-
focus
focus sends focus to a selector- Returns:
- the JS instance for chaining
-
focus
focus sends focus to a selector- Parameters:
to- the DOM selector to send focus to- Returns:
- the JS instance for chaining
-
hide
hide makes DOM elements invisible- Parameters:
hideOpts- options for the hide command- Returns:
- the JS instance for chaining
- See Also:
-
hide
hide makes DOM elements invisible- Returns:
- the JS instance for chaining
-
patch
patch sends a patch event to the server- Parameters:
patchOpts- options for the patch command- Returns:
- the JS instance for chaining
- See Also:
-
patch
patch sends a patch event to the server- Parameters:
href- the href to patch- Returns:
- the JS instance for chaining
-
popFocus
popFocus focuses the last pushed element- Returns:
- the JS instance for chaining
-
pushFocus
pushFocus pushes focus from the source element to be later popped- Parameters:
pushFocusOpts- options for the push_focus command- Returns:
- the JS instance for chaining
- See Also:
-
pushFocus
pushFocus pushes focus from the source element to be later popped- Parameters:
to- the DOM selector to push focus to- Returns:
- the JS instance for chaining
-
push
push sends an event to the server- Parameters:
pushOpts- options for the push command- Returns:
- the JS instance for chaining
- See Also:
-
push
push sends an event to the server- Parameters:
event- the name of the event to push- Returns:
- the JS instance for chaining
-
removeAttr
removeAttr removes an attribute from a DOM element- Parameters:
removeAttrOpts- options for the remove_attr command- Returns:
- the JS instance for chaining
- See Also:
-
removeAttr
removeAttr removes an attribute from a DOM element- Parameters:
name- the name of the attribute to remove- Returns:
- the JS instance for chaining
-
removeClass
removeClass removes css classes from DOM elements- Parameters:
removeClassOpts- options for the remove_class command- Returns:
- the JS instance for chaining
- See Also:
-
removeClass
removeClass removes css classes from DOM elements- Parameters:
classNames- the css class names to remove (space separated)- Returns:
- the JS instance for chaining
-
setAttr
setAttr sets an attribute on a DOM element- Parameters:
setAttrOpts- options for the set_attr command- Returns:
- the JS instance for chaining
- See Also:
-
setAttr
setAttr sets an attribute on a DOM element- Parameters:
name- the name of the attribute to setvalue- the value of the attribute to set- Returns:
- the JS instance for chaining
-
show
show makes DOM elements visible- Parameters:
showOpts- options for the show command- Returns:
- the JS instance for chaining
- See Also:
-
show
show makes DOM elements visible- Returns:
- the JS instance for chaining
-
toggle
toggle toggles the visibility of DOM elements- Parameters:
toggleOpts- options for the toggle command- Returns:
- the JS instance for chaining
- See Also:
-
toggle
toggle toggles the visibility of DOM elements- Returns:
- the JS instance for chaining
-
transition
transition applies a css transition to a DOM element- Parameters:
transitionOpts- options for the transition command- Returns:
- the JS instance for chaining
- See Also:
-