-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Web/API/CommandEvent を新規翻訳 #30358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mfuji09
wants to merge
2
commits into
mdn:main
Choose a base branch
from
mfuji09:251103-Web/API/CommandEvent-1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Web/API/CommandEvent を新規翻訳 #30358
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,113 @@ | ||
| --- | ||
| title: CommandEvent | ||
| slug: Web/API/CommandEvent | ||
| l10n: | ||
| sourceCommit: a4fcf79b60471db6f148fa4ba36f2cdeafbbeb70 | ||
| --- | ||
|
|
||
| {{APIRef("Invoker Commands API")}} | ||
|
|
||
| **`CommandEvent`** インターフェイスは、有効な {{domxref("HTMLButtonElement.commandForElement", "commandForElement")}} および {{domxref("HTMLButtonElement.command", "command")}} 属性を持つ{{domxref("HTMLButtonElement", "ボタン")}}要素が対話型要素を呼び出そうとしている際にユーザーに通知するイベントを表します。 | ||
|
|
||
| これは `HTMLElement` の {{domxref("HTMLElement.command_event", "command")}} イベントのイベントオブジェクトであり、呼び出しコントロールが操作されたとき(例えばクリックまたは押下されたとき)のアクションを表します。 | ||
|
|
||
| {{InheritanceDiagram}} | ||
|
|
||
| ## コンストラクター | ||
|
|
||
| - {{domxref("CommandEvent.CommandEvent", "CommandEvent()")}} | ||
| - : `CommandEvent` オブジェクトを作成します。 | ||
|
|
||
| ## インスタンスプロパティ | ||
|
|
||
| _このインターフェイスには、親である {{DOMxRef("Event")}} から継承したプロパティがあります。_ | ||
|
|
||
| - {{domxref("CommandEvent.source")}} {{ReadOnlyInline}} | ||
| - : この呼び出しの発生源であるボタンを表す {{domxref("HTMLButtonElement")}} です。 | ||
| - {{domxref("CommandEvent.command")}} {{ReadOnlyInline}} | ||
| - : ソースボタンの {{domxref("HTMLButtonElement.command", "command")}} 値を表す文字列です。 | ||
|
|
||
| ## 例 | ||
|
|
||
| ### 基本的な例 | ||
|
|
||
| ```html | ||
| <button commandfor="mypopover" command="show-popover">ポップオーバーを表示</button> | ||
|
|
||
| <div popover id="mypopover" role="[適切な ARIA ロールを宣言]"> | ||
| <!-- popover content here --> | ||
| <button commandfor="mypopover" command="hide-popover">ポップオーバーを非表示</button> | ||
mfuji09 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| </div> | ||
| ``` | ||
|
|
||
| ```js | ||
| const popover = document.getElementById("mypopover"); | ||
|
|
||
| // … | ||
|
|
||
| popover.addEventListener("command", (event) => { | ||
| if (event.command === "show-popover") { | ||
| console.log("ポップオーバーが表示されようとしています"); | ||
| } | ||
| }); | ||
| ``` | ||
|
|
||
| ### コマンドのカスタム値の使用 | ||
|
|
||
| この例では、[カスタム値を持つ `commands`](/ja/docs/Web/HTML/Reference/Elements/button#カスタム値) で 3 つのボタンが作成されています。 | ||
|
|
||
| ```html | ||
| <div class="controls"> | ||
| <button commandfor="the-image" command="--rotate-left">左へ回転</button> | ||
| <button commandfor="the-image" command="--reset">リセット</button> | ||
| <button commandfor="the-image" command="--rotate-right">右へ回転</button> | ||
| </div> | ||
|
|
||
| <img | ||
| id="the-image" | ||
| src="/shared-assets/images/examples/dino.svg" | ||
| alt="0 度回転した恐竜の頭" /> | ||
| ``` | ||
|
|
||
| ```css hidden | ||
| .controls { | ||
| margin-block-end: 20px; | ||
| } | ||
| ``` | ||
|
|
||
| イベントリスナーは [`command` イベント](/ja/docs/Web/API/HTMLElement/command_event)を使用して画像に取り付けられています。ボタンがクリックされると、リスナーはボタンに割り当てられた独自の `command` 値に基づいてコードを実行し、画像を回転させると同時に、画像の新しい角度を示すために alt テキストを更新しています。 | ||
|
|
||
| ```js | ||
| const image = document.getElementById("the-image"); | ||
|
|
||
| image.addEventListener("command", (event) => { | ||
| let rotate = parseInt(event.target.style.rotate || "0", 10); | ||
| if (event.command === "--reset") { | ||
| rotate = 0; | ||
| event.target.style.rotate = `${rotate}deg`; | ||
| } else if (event.command === "--rotate-left") { | ||
| rotate = rotate === -270 ? 0 : rotate - 90; | ||
| event.target.style.rotate = `${rotate}deg`; | ||
| } else if (event.command === "--rotate-right") { | ||
| rotate = rotate === 270 ? 0 : rotate + 90; | ||
| event.target.style.rotate = `${rotate}deg`; | ||
| } | ||
| event.target.alt = `${rotate} 度回転した恐竜の頭`; | ||
| }); | ||
| ``` | ||
|
|
||
| {{EmbedLiveSample('using_custom_values_for_commands', '100%', "220")}} | ||
|
|
||
| ## 仕様書 | ||
|
|
||
| {{Specifications}} | ||
|
|
||
| ## ブラウザーの互換性 | ||
|
|
||
| {{Compat}} | ||
|
|
||
| ## 関連情報 | ||
|
|
||
| - {{domxref("Invoker Commands API", "呼び出しコマンド API", "", "nocode")}} | ||
| - {{domxref("HTMLButtonElement.command")}} | ||
| - {{domxref("HTMLButtonElement.commandForElement")}} | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.