-
+
-
+ + + + ++ +
+
+ * {@snippet class = Greeting region = attach} + */ public interface Attachable { /** Registers the specified element for both attach and detach. */ diff --git a/src/main/java/org/jboss/elemento/By.java b/src/main/java/org/jboss/elemento/By.java index d6b14ff3f..58b9d624f 100644 --- a/src/main/java/org/jboss/elemento/By.java +++ b/src/main/java/org/jboss/elemento/By.java @@ -27,17 +27,7 @@ * Typesafe CSS selector API. *
* Use the static methods in this class to create arbitrary complex CSS selectors: - *
- * - *
- * // #main [data-list-item=foo] a[href^="http://"] > .fas.fa-check, .external[hidden] - * By.group( - * By.id("main") - * .desc(By.data("listItem", "foo") - * .desc(By.element("a").and(By.attribute("href", STARTS_WITH, "http://")) - * .child(By.classnames("fas", "fa-check")))), - * By.classname("external").and(By.attribute("hidden"))); - *+ * {@snippet class = ByDemo region = group} * * @see https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors @@ -165,7 +155,11 @@ public static By data(String name, AttributeOperator operator, String value) { return new ByData(name, operator, value); } - /** Groups the specified selectors using {@code ,}. */ + /** + * Groups the specified selectors using {@code ,}. + *
+ * {@snippet class = ByDemo region = group} + */ public static By group(By first, By second, By... remaining) { int length = 2; if (remaining != null) { @@ -184,7 +178,11 @@ public static By group(By first, By second, By... remaining) { return new ByGroup(group); } - /** Groups the specified selectors using {@code ,}. */ + /** + * Groups the specified selectors using {@code ,}. + *
+ * {@snippet class = ByDemo region = group} + */ public static By group(By[] selectors) { return new ByGroup(selectors); } @@ -195,11 +193,7 @@ public static By group(By[] selectors) { * Combines this selector with the given selector. Use this method to express selectors like {@code button.primary} or * {@code input[type=checkbox]}: *
- * - *
- * By.element("button").and(By.classname("primary")) - * By.element("input").and(By.attribute("type", "checkbox")); - *+ * {@snippet class = ByDemo region = and} */ public final By and(By selector) { return combinator(Combinator.AND, selector); diff --git a/src/main/java/org/jboss/elemento/ElementBuilder.java b/src/main/java/org/jboss/elemento/ElementBuilder.java index ec8b9e130..99ebc1918 100644 --- a/src/main/java/org/jboss/elemento/ElementBuilder.java +++ b/src/main/java/org/jboss/elemento/ElementBuilder.java @@ -106,6 +106,18 @@ public B style(String style) { return that(); } + /** Sets the specified attribute of the element. */ + public B attr(String name, boolean value) { + element().setAttribute(name, value); + return that(); + } + + /** Sets the specified attribute of the element. */ + public B attr(String name, int value) { + element().setAttribute(name, value); + return that(); + } + /** Sets the specified attribute of the element. */ public B attr(String name, String value) { element().setAttribute(name, value); @@ -123,6 +135,28 @@ public B data(String name, String value) { return that(); } + /** + * Adds an {@code aria-} attribute to the element. + * + * @param name The name of the aria attribute w/o the {@code aria-} prefix. However it won't be added if it's already + * present. + */ + public B aria(String name, boolean value) { + String safeName = name.startsWith("aria-") ? name : "aria-" + name; + return attr(safeName, value); + } + + /** + * Adds an {@code aria-} attribute to the element. + * + * @param name The name of the aria attribute w/o the {@code aria-} prefix. However it won't be added if it's already + * present. + */ + public B aria(String name, int value) { + String safeName = name.startsWith("aria-") ? name : "aria-" + name; + return attr(safeName, value); + } + /** * Adds an {@code aria-} attribute to the element. * @@ -148,7 +182,11 @@ public B hidden(boolean hidden) { // ------------------------------------------------------ event handler - /** Adds the given callback to the element. */ + /** + * Adds the given callback to the element. + *
+ * {@snippet class = ElementsDemo region = on}
+ */
public
+ * {@snippet class = ElementsDemo region = findAll}
+ */
public Iterable
+ * {@snippet class = ElementsDemo region = builder}
*
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element
*/
+@SuppressWarnings({ "unused", "ConfusingMainMethod" })
public final class Elements {
static ElementCreator createElement = new ElementCreator() {
@@ -926,7 +929,11 @@ public static TextContentBuilder
+ * {@snippet class = ElementsBagDemo region = bag}
+ */
public static ElementsBag bag() {
return new ElementsBag();
}
@@ -1006,12 +1013,22 @@ public static
+ * {@snippet class = ElementsDemo region = stream}
+ */
public static
+ * {@snippet class = ElementsDemo region = stream}
+ */
public static Stream
+ * {@snippet class = ElementsDemo region = stream}
+ */
public static Stream
+ * {@snippet class = ElementsDemo region = stream}
+ */
public static
+ * {@snippet class = ElementsBagDemo region = bag}
+ */
public class ElementsBag implements TypedBuilder
+ * {@snippet class = EventDemo region = bind}
+ */
public static
+ * {@snippet class = EventDemo region = bind}
+ */
public static HandlerRegistration bind(EventTarget target, String type, EventListener listener) {
target.addEventListener(type, listener);
return () -> target.removeEventListener(type, listener);
}
- /** Registers an event handler. */
- public static
+ * {@snippet class = EventDemo region = bind}
+ */
+ public static
+ * {@snippet class = EventDemo region = bind}
+ */
+ public static HandlerRegistration bind(EventTarget target, String type, boolean useCapture,
+ EventListener listener) {
target.addEventListener(type, listener, useCapture);
return () -> target.removeEventListener(type, listener, useCapture);
}
- /** Registers an event handler. */
- public static
+ * {@snippet class = EventDemo region = bind}
+ */
+ public static
+ * {@snippet class = EventDemo region = bind}
+ */
+ public static
+ * {@snippet class = EventDemo region = bind}
+ */
+ public static
+ * {@snippet class = EventDemo region = bind}
+ */
public static
+ * {@snippet class = HtmlContentDemo region = addAll}
+ */
public interface HtmlContent
+ * {@snippet class = TodoElement region = isElement}
+ */
public interface IsElement
+ * {@snippet class = KeyDemo region = key}
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values
*/
public enum Key {
- Accept("Accept"), Again("Again"), Alt("Alt"), AltGraph("AltGraph"), ArrowDown("ArrowDown",
- new String[] { "Down" }), ArrowLeft("ArrowLeft", new String[] { "Left" }), ArrowRight("ArrowRight", new String[] {
- "Right" }), ArrowUp("ArrowUp", new String[] { "Up" }), Attn("Attn"), Backspace("Backspace"), BrightnessDown(
- "BrightnessDown"), BrightnessUp("BrightnessUp"), Cancel("Cancel"), CapsLock("CapsLock"), Clear(
- "Clear"), ContextMenu("ContextMenu", new String[] { "Apps" }), Control("Control"), Copy(
- "Copy"), CrSel("CrSel", new String[] { "Crsel" }), Cut("Cut"), Delete("Delete",
- new String[] { "Del" }), Eject("Eject"), End("End"), Enter(
- "Enter"), EraseEof("EraseEof"), Escape("Escape",
- new String[] { "Esc" }), Execute("Execute"), ExSel("ExSel",
- new String[] { "Exsel" }), F1("F1"), F10(
- "F10"), F11("F11"), F13("F13"), F14(
- "F14"), F15("F15"), F16("F16"), F17(
- "F17"), F18("F18"), F19(
- "F19"), F2(
- "F2"), F20(
- "F20"), F3(
- "F3"), F4(
- "F4"), F5(
- "F5"), F6(
- "F6"), F7(
- "F7"), F8(
- "F8"), F9(
- "F9"), Find(
- "Find"), Finish(
- "Finish"), Fn(
- "Fn"), FnLock(
- "FnLock"), Help(
- "Help"), Hibernate(
- "Hibernate"), Home(
- "Home"), Insert(
- "Insert"), LogOff(
- "LogOff"), Meta(
- "Meta"), NumLock(
- "NumLock"), PageDown(
- "PageDown"), PageUp(
- "PageUp"), Paste(
- "Paste"), Pause(
- "Pause"), Play(
- "Play"), Power(
- "Power"), PowerOff(
- "PowerOff"), PrintScreen(
- "PrintScreen"), Props(
- "Props"), Redo(
- "Redo"), ScrollLock(
- "ScrollLock",
- new String[] {
- "Scroll" }), Select(
- "Select"), Shift(
- "Shift"), Soft1(
- "Soft1"), Soft2(
- "Soft2"), Soft3(
- "Soft3"), Soft4(
- "Soft4"), Spacebar(
- " ",
- new String[] {
- "Spacebar" }), Standby(
- "Standby"), Symbol(
- "Symbol"), SymbolLock(
- "SymbolLock"), Tab(
- "Tab"), Undo(
- "Undo"), Unidentified(
- ""), WakeUp(
- "WakeUp"), ZoomIn(
- "ZoomIn"), ZoomOut(
- "ZoomOut");
+ // @formatter:off
+ Accept("Accept"),
+ Again("Again"),
+ Alt("Alt"),
+ AltGraph("AltGraph"),
+ ArrowDown("ArrowDown", new String[]{"Down"}),
+ ArrowLeft("ArrowLeft", new String[]{"Left"}),
+ ArrowRight("ArrowRight", new String[]{"Right"}),
+ ArrowUp("ArrowUp", new String[]{"Up"}),
+ Attn("Attn"),
+ Backspace("Backspace"),
+ BrightnessDown("BrightnessDown"),
+ BrightnessUp("BrightnessUp"),
+ Cancel("Cancel"),
+ CapsLock("CapsLock"),
+ Clear("Clear"),
+ ContextMenu("ContextMenu", new String[]{"Apps"}),
+ Control("Control"),
+ Copy("Copy"),
+ CrSel("CrSel", new String[]{"Crsel"}),
+ Cut("Cut"),
+ Delete("Delete", new String[]{"Del"}),
+ Eject("Eject"),
+ End("End"),
+ Enter("Enter"),
+ EraseEof("EraseEof"),
+ Escape("Escape", new String[]{"Esc"}),
+ Execute("Execute"),
+ ExSel("ExSel", new String[]{"Exsel"}),
+ F1("F1"),
+ F10("F10"),
+ F11("F11"),
+ F13("F13"),
+ F14("F14"),
+ F15("F15"),
+ F16("F16"),
+ F17("F17"),
+ F18("F18"),
+ F19("F19"),
+ F2("F2"),
+ F20("F20"),
+ F3("F3"),
+ F4("F4"),
+ F5("F5"),
+ F6("F6"),
+ F7("F7"),
+ F8("F8"),
+ F9("F9"),
+ Find("Find"),
+ Finish("Finish"),
+ Fn("Fn"),
+ FnLock("FnLock"),
+ Help("Help"),
+ Hibernate("Hibernate"),
+ Home("Home"),
+ Insert("Insert"),
+ LogOff("LogOff"),
+ Meta("Meta"),
+ NumLock("NumLock"),
+ PageDown("PageDown"),
+ PageUp("PageUp"),
+ Paste("Paste"),
+ Pause("Pause"),
+ Play("Play"),
+ Power("Power"),
+ PowerOff("PowerOff"),
+ PrintScreen("PrintScreen"),
+ Props("Props"),
+ Redo("Redo"),
+ ScrollLock("ScrollLock", new String[]{"Scroll"}),
+ Select("Select"),
+ Shift("Shift"),
+ Soft1("Soft1"),
+ Soft2("Soft2"),
+ Soft3("Soft3"),
+ Soft4("Soft4"),
+ Spacebar(" ", new String[]{"Spacebar"}),
+ Standby("Standby"),
+ Symbol("Symbol"),
+ SymbolLock("SymbolLock"),
+ Tab("Tab"),
+ Undo("Undo"),
+ Unidentified(""),
+ WakeUp("WakeUp"),
+ ZoomIn("ZoomIn"),
+ ZoomOut("ZoomOut");
+ // @formatter:off
private static Map