-
Notifications
You must be signed in to change notification settings - Fork 22.5k
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
11 changed files
with
189 additions
and
267 deletions.
There are no files selected for viewing
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,72 @@ | ||
--- | ||
title: CommandEvent | ||
slug: Web/API/CommandEvent | ||
page-type: web-api-interface | ||
browser-compat: api.CommandEvent | ||
--- | ||
|
||
{{APIRef("UI Events")}} | ||
|
||
The **`CommandEvent`** interface represents an event notifying the user when a {{domxref("HTMLButtonElement", "button")}} element with valid {{domxref("HTMLButtonElement.commandForElement", "commandForElement")}} and {{domxref("HTMLButtonElement.command", "command")}} attributes is about to invoke an interactive element. | ||
|
||
It is the event object for the `HTMLElement` {{domxref("HTMLElement.invoke_event", "invoke")}} event, which represents an action from an Invoker Control it is invoked (for example when it is clicked or pressed). | ||
|
||
{{InheritanceDiagram}} | ||
|
||
## Constructor | ||
|
||
- {{domxref("CommandEvent.CommandEvent", "CommandEvent()")}} | ||
- : Creates an `CommandEvent` object. | ||
|
||
## Instance properties | ||
|
||
_This interface inherits properties from its parent, {{DOMxRef("Event")}}._ | ||
|
||
- {{domxref("CommandEvent.source")}} {{ReadOnlyInline}} | ||
- : An Element representing the control button that caused this invocation. | ||
- {{domxref("CommandEvent.command")}} {{ReadOnlyInline}} | ||
- : A string representing the {{domxref("HTMLButtonElement.command", "command")}} value of the source control button. | ||
|
||
## Examples | ||
|
||
### Basic example | ||
|
||
```js | ||
const popover = document.getElementById("mypopover"); | ||
|
||
// ... | ||
|
||
popover.addEventListener("command", (event) => { | ||
if (event.command === "show-popover") { | ||
console.log("Popover is about to be shown"); | ||
} | ||
}); | ||
``` | ||
|
||
### Custom example | ||
|
||
```js | ||
const myImage = document.querySelector("img"); | ||
|
||
// ... | ||
|
||
myImage.addEventListener("command", (event) => { | ||
if (event.command === "--rotate-right") { | ||
console.log("My own custom invoke behavior"); | ||
myImage.style.rotate = "90deg"; | ||
} | ||
}); | ||
``` | ||
|
||
## Specifications | ||
|
||
{{Specifications}} | ||
|
||
## Browser compatibility | ||
|
||
{{Compat}} | ||
|
||
## See also | ||
|
||
- [command](/en-US/docs/Web/API/HTMLButtonElement/command) | ||
- [commandForElement](/en-US/docs/Web/API/HTMLButtonElement/commandForElement) |
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,58 @@ | ||
--- | ||
title: "HTMLButtonElement: command property" | ||
short-title: command | ||
slug: Web/API/HTMLButtonElement/command | ||
page-type: web-api-instance-property | ||
browser-compat: api.HTMLButtonElement.command | ||
--- | ||
|
||
{{ APIRef("DOM") }} | ||
|
||
The **`command`** 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, [`commandfor`](/en-US/docs/Web/HTML/Element/button#commandfor) must be set. | ||
|
||
It reflects the [`command`](/en-US/docs/Web/HTML/Element/button#command) HTML attribute. | ||
|
||
## Value | ||
|
||
A string. | ||
|
||
### Basic example | ||
|
||
```js | ||
const popover = document.getElementById("mypopover"); | ||
const toggleBtn = document.getElementById("toggleBtn"); | ||
|
||
toggleBtn.command = "show-popover"; | ||
``` | ||
|
||
### Custom example, using events | ||
|
||
```js | ||
const toggleBtn = document.getElementById("toggleBtn"); | ||
const myImage = document.querySelector("img"); | ||
|
||
toggleBtn.commandForElement = myImage; | ||
|
||
// Set a custom "command", must start with two hyphen characters (`--`) | ||
toggleBtn.command = "--rotate-right"; | ||
|
||
myImage.addEventListener("command", (event) => { | ||
if (event.command === "--rotate-right") { | ||
console.log("My own custom invoke behavior"); | ||
myImage.style.rotate = "90deg"; | ||
} | ||
}); | ||
``` | ||
|
||
## Specifications | ||
|
||
{{Specifications}} | ||
|
||
## Browser compatibility | ||
|
||
{{Compat}} | ||
|
||
## See also | ||
|
||
- [commandForElement](/en-US/docs/Web/API/HTMLButtonElement/commandForElement) | ||
- [CommandEvent](/en-US/docs/Web/API/CommandEvent) |
39 changes: 39 additions & 0 deletions
39
files/en-us/web/api/htmlbuttonelement/commandforelement/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,39 @@ | ||
--- | ||
title: "HTMLButtonElement: commandForElement property" | ||
short-title: commandForElement | ||
slug: Web/API/HTMLButtonElement/commandForElement | ||
page-type: web-api-instance-property | ||
browser-compat: api.HTMLButtonElement.commandForElement | ||
--- | ||
|
||
{{ APIRef("DOM") }} | ||
|
||
The **`commandForElement`** property of the {{domxref("HTMLButtonElement")}} interface gets and sets the element to control via a button. | ||
|
||
It is the JavaScript equivalent of the [`commandfor`](/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.commandForElement = popover; | ||
``` | ||
|
||
## Specifications | ||
|
||
{{Specifications}} | ||
|
||
## Browser compatibility | ||
|
||
{{Compat}} | ||
|
||
## See also | ||
|
||
- [command](/en-US/docs/Web/API/HTMLButtonElement/command) | ||
- [CommandEvent](/en-US/docs/Web/API/CommandEvent) |
38 changes: 0 additions & 38 deletions
38
files/en-us/web/api/htmlbuttonelement/invokeaction/index.md
This file was deleted.
Oops, something went wrong.
38 changes: 0 additions & 38 deletions
38
files/en-us/web/api/htmlbuttonelement/invoketargetelement/index.md
This file was deleted.
Oops, something went wrong.
File renamed without changes.
38 changes: 0 additions & 38 deletions
38
files/en-us/web/api/htmlinputelement/invokeaction/index.md
This file was deleted.
Oops, something went wrong.
38 changes: 0 additions & 38 deletions
38
files/en-us/web/api/htmlinputelement/invoketargetelement/index.md
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.