-
Notifications
You must be signed in to change notification settings - Fork 22.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
345 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
files/en-us/web/api/htmlbuttonelement/invokeaction/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
title: "HTMLButtonElement: invokeAction property" | ||
short-title: invokeAction | ||
slug: Web/API/HTMLButtonElement/invokeAction | ||
page-type: web-api-instance-property | ||
browser-compat: api.HTMLButtonElement.invokeAction | ||
--- | ||
|
||
{{ APIRef("DOM") }} | ||
|
||
The **`invokeAction`** property of the {{domxref("HTMLButtonElement")}} interface gets and sets the action to be performed on an element being controlled by a button. For this to have an effect, [`invoketarget`](/en-US/docs/Web/HTML/Element/button#invoketarget) must be set. | ||
|
||
It reflects the [`invokeaction`](/en-US/docs/Web/HTML/Element/button#invokeaction) HTML attribute. | ||
|
||
## Value | ||
|
||
A string. | ||
|
||
## Examples | ||
|
||
```js | ||
const popover = document.getElementById("mypopover"); | ||
const toggleBtn = document.getElementById("toggleBtn"); | ||
|
||
toggleBtn.invokeAction = "showPopover"; | ||
``` | ||
|
||
## Specifications | ||
|
||
{{Specifications}} | ||
|
||
## Browser compatibility | ||
|
||
{{Compat}} | ||
|
||
## See also | ||
|
||
- [Invokers API](/en-US/docs/Web/API/Invokers_API) |
38 changes: 38 additions & 0 deletions
38
files/en-us/web/api/htmlbuttonelement/invoketargetelement/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
title: "HTMLButtonElement: invokeTargetElement property" | ||
short-title: invokeTargetElement | ||
slug: Web/API/HTMLButtonElement/invokeTargetElement | ||
page-type: web-api-instance-property | ||
browser-compat: api.HTMLButtonElement.invokeTargetElement | ||
--- | ||
|
||
{{ APIRef("DOM") }} | ||
|
||
The **`invokeTargetElement`** property of the {{domxref("HTMLButtonElement")}} interface gets and sets the element to control via a button. | ||
|
||
It is the JavaScript equivalent of the [`invoketarget`](/en-US/docs/Web/HTML/Element/button#invoketarget) HTML attribute. | ||
|
||
## Value | ||
|
||
A reference to an element in the DOM. | ||
|
||
## Examples | ||
|
||
```js | ||
const popover = document.getElementById("mypopover"); | ||
const toggleBtn = document.getElementById("toggleBtn"); | ||
|
||
toggleBtn.invokeTargetElement = popover; | ||
``` | ||
|
||
## Specifications | ||
|
||
{{Specifications}} | ||
|
||
## Browser compatibility | ||
|
||
{{Compat}} | ||
|
||
## See also | ||
|
||
- [Invokers API](/en-US/docs/Web/API/Invokers_API) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
--- | ||
title: "HTMLElement: invoke event" | ||
slug: Web/API/HTMLElement/invoke_event | ||
page-type: web-api-event | ||
status: | ||
- experimental | ||
browser-compat: api.HTMLElement.invoke_event | ||
--- | ||
|
||
{{APIRef}}{{SeeCompatTable}} | ||
|
||
The **`invoke`** event of the {{domxref("HTMLElement")}} interface fires on a {{domxref("Invokers_API", "invoker controlled", "", "nocode")}} element (i.e. one that has a button with an `invoketarget` attribute pointing to this element) whenever the invoker is interacted with (e.g. it is clicked). | ||
|
||
## Syntax | ||
|
||
Use the event name in methods like {{domxref("EventTarget.addEventListener", "addEventListener()")}}, or set an event handler property. | ||
|
||
```js | ||
addEventListener("invoke", (event) => {}); | ||
|
||
oninvoke = (event) => {}; | ||
``` | ||
|
||
## Event type | ||
|
||
A {{domxref("InvokeEvent")}}. Inherits from {{domxref("Event")}}. | ||
|
||
{{InheritanceDiagram("InvokeEvent")}} | ||
|
||
## Examples | ||
|
||
### Basic example | ||
|
||
```js | ||
const popover = document.getElementById("mypopover"); | ||
|
||
// ... | ||
|
||
popover.addEventListener("invoke", (event) => { | ||
if (event.action === "show") { | ||
console.log("Popover is about to be shown"); | ||
} | ||
}); | ||
``` | ||
|
||
### A note on event dispatch and cancellation | ||
|
||
It is worth pointing out that `invoke` events fire on the element being invoked. If an Invoker (i.e. the `<button>`) is clicked, it will first dispatch a `click` event which, if cancelled, then the `invoke` event will not fire and the default behavior will not be run. | ||
In addition to cancelling the `click` event on the button, it is also possible to cancel the `invoke` event. | ||
|
||
For example: | ||
|
||
```js | ||
button.addEventListener("click", (event) => { | ||
event.preventDefault(); // the `invoke` event will never fire | ||
}); | ||
``` | ||
|
||
```js | ||
element.addEventListener("invoke", (event) => { | ||
event.preventDefault(); // the `invoke` event fires but the default behavior is cancelled | ||
}); | ||
``` | ||
|
||
## Specifications | ||
|
||
{{Specifications}} | ||
|
||
## Browser compatibility | ||
|
||
{{Compat}} | ||
|
||
## See also | ||
|
||
- [Invokers API](/en-US/docs/Web/API/Invokers_API) |
38 changes: 38 additions & 0 deletions
38
files/en-us/web/api/htmlinputelement/invokeaction/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
title: "HTMLInputElement: invokeAction property" | ||
short-title: invokeAction | ||
slug: Web/API/HTMLInputElement/invokeAction | ||
page-type: web-api-instance-property | ||
browser-compat: api.HTMLInputElement.invokeAction | ||
--- | ||
|
||
{{ APIRef("DOM") }} | ||
|
||
The **`invokeAction`** property of the {{domxref("HTMLInputElement")}} interface gets and sets the action to be performed on an element being controlled by a button. For this to have an effect, [`invoketarget`](/en-US/docs/Web/HTML/Element/button#invoketarget) must be set. | ||
|
||
It reflects the [`invokeaction`](/en-US/docs/Web/HTML/Element/button#invokeaction) HTML attribute. | ||
|
||
## Value | ||
|
||
A string. | ||
|
||
## Examples | ||
|
||
```js | ||
const popover = document.getElementById("mypopover"); | ||
const toggleBtn = document.getElementById("toggleBtn"); | ||
|
||
toggleBtn.invokeAction = "showPopover"; | ||
``` | ||
|
||
## Specifications | ||
|
||
{{Specifications}} | ||
|
||
## Browser compatibility | ||
|
||
{{Compat}} | ||
|
||
## See also | ||
|
||
- [Invokers API](/en-US/docs/Web/API/Invokers_API) |
38 changes: 38 additions & 0 deletions
38
files/en-us/web/api/htmlinputelement/invoketargetelement/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
title: "HTMLInputElement: invokeTargetElement property" | ||
short-title: invokeTargetElement | ||
slug: Web/API/HTMLInputElement/invokeTargetElement | ||
page-type: web-api-instance-property | ||
browser-compat: api.HTMLInputElement.invokeTargetElement | ||
--- | ||
|
||
{{ APIRef("DOM") }} | ||
|
||
The **`invokeTargetElement`** property of the {{domxref("HTMLInputElement")}} interface gets and sets the element to control via a button. | ||
|
||
It is the JavaScript equivalent of the [`invoketarget`](/en-US/docs/Web/HTML/Element/button#invoketarget) HTML attribute. | ||
|
||
## Value | ||
|
||
A reference to an element in the DOM. | ||
|
||
## Examples | ||
|
||
```js | ||
const popover = document.getElementById("mypopover"); | ||
const toggleBtn = document.getElementById("toggleBtn"); | ||
|
||
toggleBtn.invokeTargetElement = popover; | ||
``` | ||
|
||
## Specifications | ||
|
||
{{Specifications}} | ||
|
||
## Browser compatibility | ||
|
||
{{Compat}} | ||
|
||
## See also | ||
|
||
- [Invokers API](/en-US/docs/Web/API/Invokers_API) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
--- | ||
title: InvokeEvent | ||
slug: Web/API/InvokeEvent | ||
page-type: web-api-interface | ||
browser-compat: api.InvokeEvent | ||
--- | ||
|
||
{{APIRef("UI Events")}} | ||
|
||
The **`InvokeEvent`** interface represents an event notifying the user when a [invoker control](/en-US/docs/Web/API/Invoker_API) is about to invoke an interactive element. | ||
|
||
It is the event object for the `HTMLElement` {{domxref("HTMLElement.invoke_event", "invoke")}} event, which fires elements from an Invoker Control, when the Invoker Control is interacted with (for example when it is clicked). | ||
|
||
{{InheritanceDiagram}} | ||
|
||
## Constructor | ||
|
||
- {{DOMxRef("InvokeEvent.InvokeEvent", "InvokeEvent()")}} | ||
- : Creates an `InvokeEvent` object. | ||
|
||
## Instance properties | ||
|
||
_This interface inherits properties from its parent, {{DOMxRef("Event")}}._ | ||
|
||
- {{DOMxRef("InvokeEvent.invoker")}} {{ReadOnlyInline}} | ||
- : An Element representing the Invoker Control that caused this invocation. | ||
- {{DOMxRef("InvokeEvent.action")}} {{ReadOnlyInline}} | ||
- : A string representing the action the element is about to take. | ||
|
||
## Examples | ||
|
||
### Basic example | ||
|
||
```js | ||
const popover = document.getElementById("mypopover"); | ||
|
||
// ... | ||
|
||
popover.addEventListener("invoke", (event) => { | ||
if (event.action === "show") { | ||
console.log("Popover is about to be shown"); | ||
} | ||
}); | ||
``` | ||
|
||
### Custom example | ||
|
||
```js | ||
const customElement = document.querySelector("my-custom-element"); | ||
|
||
// ... | ||
|
||
customElement.addEventListener("invoke", (event) => { | ||
if (event.action === "spin") { | ||
console.log("My own custom invoke behavior"); | ||
} | ||
}); | ||
``` | ||
|
||
## Specifications | ||
|
||
{{Specifications}} | ||
|
||
## Browser compatibility | ||
|
||
{{Compat}} | ||
|
||
## See also | ||
|
||
- [Invokers API](/en-US/docs/Web/API/Invokers_API) | ||
- [`invoke` event](/en-US/docs/Web/API/HTMLElement/invoke_event) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--- | ||
title: Invokers API | ||
slug: Web/API/Invokers_API | ||
page-type: web-api-overview | ||
browser-compat: api.HTMLElement.invokers | ||
--- | ||
|
||
{{DefaultAPISidebar("Invokers API")}} | ||
|
||
The **Invokers API** provides developers with a standard, consistent, flexible mechanism for controlling interactive HTML Elements on the page. Invokers allow for declaratively control using HTML attributes for equivalent JavaScript APIs. | ||
|
||
## Concepts and usage | ||
|
||
It is very common on the web to control interactive elements using {{htmlelement("button")}} elements, adding JavaScript event listeners to control what a button does when pressed. Invokers provide a declarative way to achieve the same effect for simple behaviors, such as toggling a popover, dialog, or details element. | ||
|
||
Invokers also allow for custom actions that can control behaviors using JavaScript without adding event listeners to the buttons. | ||
|
||
## HTML attributes | ||
|
||
- [`invoketarget`](/en-US/docs/Web/HTML/Element/button#invoketarget) | ||
- : Turns a {{htmlelement("button")}} or {{htmlelement("input")}} element into a Invoker control button; takes the ID of the element to control as its value. | ||
- [`invokeaction`](/en-US/docs/Web/HTML/Element/button#invokeaction) | ||
- : Specifies the action to be performed on the element being controlled by an Invoker {{htmlelement("button")}} or {{htmlelement("input")}}. | ||
|
||
## Interfaces | ||
|
||
- {{domxref("InvokeEvent")}} | ||
- : Represents an event notifying the user when an button is about to invoke an element. It is the event object for the {{domxref("HTMLElement.invoke_event", "invoke")}} event, which fires on the element to be invoked, when the button is interacted with. | ||
|
||
## Extensions to other interfaces | ||
|
||
### Instance properties | ||
|
||
- {{domxref("HTMLButtonElement.invokeTargetElement")}} and {{domxref("HTMLInputElement.invokeTargetElement")}} | ||
- : Gets and sets the invoker element being controlled by the control button. The JavaScript equivalent of the [`invoketarget`](/en-US/docs/Web/HTML/Element/button#invoketarget) HTML attribute. | ||
- {{domxref("HTMLButtonElement.invokeAction")}} and {{domxref("HTMLInputElement.invokeAction")}} | ||
- : Gets and sets the action to be performed on the invoker element being controlled by the control button. Reflects the value of the [`invokeraction`](/en-US/docs/Web/HTML/Element/button#invokeraction) HTML attribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters