フレーム
# 基本フレーム
フレーム内にある、リンク先または送信したフォームのレスポンスにこのフレームとマッチするフレームタグが含まれていることを期待し、フレーム内の全ナビゲーションを制限しています。
<turbo-frame id="messages">
<a href="/messages/expanded">
このフレームに、展開されたメッセージをすべて表示する。
</a>
<form action="/messages">
このフレームに、フォームからの応答を表示する。
</form>
</turbo-frame>
原文
Frames
# Basic frame
Confines all navigation within the frame by expecting any followed link or form submission to return a response including a matching frame tag:
<turbo-frame id="messages">
<a href="/messages/expanded">
Show all expanded messages in this frame.
</a>
<form action="/messages">
Show response from this form within this frame.
</form>
</turbo-frame>
# フレームの事前読み込み
基本的なフレームと同じように動作しますが、コンテンツはまずリモートのsrcから読み込まれます。
<turbo-frame id="messages" src="/messages">
コンテンツは、/messagesが読み込まれたときに置き換えられます。
</turbo-frame>
原文
# Eager-loaded frame
Works like the basic frame, but the content is loaded from a remote src first.
<turbo-frame id="messages" src="/messages">
Content will be replaced when /messages has been loaded.
</turbo-frame>
# フレームの遅延読み込み
フレームの事前読み込みに似ていますが、フレームが表示されるまでコンテンツはsrcから読み込まれません。
<turbo-frame id="messages" src="/messages" loading="lazy">
このフレームが表示され、/messagesが読み込まれると、コンテンツは置き換えられます。
</turbo-frame>
原文
# Lazy-loaded frame
Like an eager-loaded frame, but the content is not loaded from src until the frame is visible.
<turbo-frame id="messages" src="/messages" loading="lazy">
Content will be replaced when the frame becomes visible and /messages has been loaded.
</turbo-frame>
# デフォルトでページ全体を対象とするフレーム
<turbo-frame id="messages" target="_top">
<a href="/messages/1">
このリンクは、このフレームではなく、ページ全体を置き換えます。
</a>
<a href="/messages/1" data-turbo-frame="_self">
このリンクは、このフレームだけを置き換えます。
</a>
<form action="/messages">
フォームの送信は、このフレームではなく、ページ全体を置き換えます。
</form>
</turbo-frame>
原文
# Frame targeting the whole page by default
<turbo-frame id="messages" target="_top">
<a href="/messages/1">
Following link will replace the whole page, not this frame.
</a>
<a href="/messages/1" data-turbo-frame="_self">
Following link will replace just this frame.
</a>
<form action="/messages">
Submitting form will replace the whole page, not this frame.
</form>
</turbo-frame>
# ナビゲーションターゲットが上書きされたフレーム
<turbo-frame id="messages">
<a href="/messages/1">
このリンクは、このフレームを置き換えます。
</a>
<a href="/messages/1" data-turbo-frame="_top">
このリンクは、このフレームではなく、ページ全体を置き換えます。
</a>
<form action="/messages" data-turbo-frame="navigation">
フォームの送信は、このフレームではなく、idが navigationのフレームを置き換えます。
</form>
</turbo-frame>
原文
# Frame with overwritten navigation targets
<turbo-frame id="messages">
<a href="/messages/1">
Following link will replace this frame.
</a>
<a href="/messages/1" data-turbo-frame="_top">
Following link will replace the whole page, not this frame.
</a>
<form action="/messages" data-turbo-frame="navigation">
Submitting form will replace the navigation frame.
</form>
</turbo-frame>
# ページ遷移をナビゲーションしやすくするフレーム
<turbo-frame id="messages" data-turbo-action="advance">
<a href="/messages?page=2">
ブラウザ履歴を次のページへ進めます
</a>
<a href="/messages?page=2" data-turbo-action="replace">
ブラウザ履歴を次のページに置き換えます
</a>
</turbo-frame>
原文
# Frame that promotes navigations to Visits
<turbo-frame id="messages" data-turbo-action="advance">
<a href="/messages?page=2">Advance history to next page</a>
<a href="/messages?page=2" data-turbo-action="replace">Replace history with next page</a>
</turbo-frame>
属性、プロパティ、関数
<turbo-frame>要素は、独自のHTML属性とJavaScriptプロパティを持つカスタム要素です。
原文
Attributes, properties, and functions
The <turbo-frame> element is a custom element with its own set of HTML
attributes and JavaScript properties.
# HTML属性
srcは、要素のナビゲーションをコントロールするURLまたはパスを受け付けます。loadingは列挙属性で、"eager"と"lazy"を指定できます。"eager"を指定した場合は、src属性の値へすぐに遷移します。lazyを指定した場合は、src属性の値への遷移は、要素がビューポートに表示されるまで遅れます。デフォルト値は"eager"です。busyは真偽属性で、<turbo-frame>によるリクエストが開始されたときにtrue、終了したときにfalseになります。disabledは真偽属性で、この属性があるとナビゲーションができなくなります。targetには、子孫の<a>がクリックされたときに遷移する別の<turbo-frame>要素をIDで指定します。target="_top"の場合、ページ全体が遷移します。completeは真偽属性で、<turbo-frame>要素がナビゲーションを終了したかどうかを示します。autoscrollは真偽属性で、読み込み後に<turbo-frame>要素(および、その子孫の<turbo-frame>要素)をスクロールして表示するかどうかをコントロールします。data-autoscroll-block属性に、Element.scrollIntoView({ block: “…” })で有効な"end"、"start"、"center"、"nearest"のどれかを指定することで、垂直方向のスクロールをコントロールします。data-autoscroll-block属性がない場合、デフォルト値は"end"です。data-autoscroll-behavior属性に、Element.scrollIntoView({ behavior: “…” })で有効な"auto"、"smooth"のどれかを指定することで、スクロールの振る舞いをコントロールします。data-autoscroll-behavior属性がない場合、デフォルト値は"auto"です。
原文
# HTML Attributes
-
srcaccepts a URL or path value that controls navigation of the element -
loadinghas two valid enumerated values: “eager” and “lazy”. Whenloading="eager", changes to thesrcattribute will immediately navigate the element. Whenloading="lazy", changes to thesrcattribute will defer navigation until the element is visible in the viewport. The default value iseager. -
busyis a boolean attribute toggled to be present when a<turbo-frame>-initiated request starts, and toggled false when the request ends -
disabledis a boolean attribute that prevents any navigation when present -
targetrefers to another<turbo-frame>element by ID to be navigated when a descendant<a>is clicked. Whentarget="_top", navigate the window. -
completeis a boolean attribute whose presence or absence indicates whether or not the<turbo-frame>element has finished navigating. -
autoscrollis a boolean attribute that controls whether or not to scroll a<turbo-frame>element (and its descendant<turbo-frame>elements) into view when after loading. Control the scroll’s vertical alignment by setting thedata-autoscroll-blockattribute to a valid Element.scrollIntoView({ block: “…” }) value: one of"end","start","center", or"nearest". Whendata-autoscroll-blockis absent, the default value is"end". Control the scroll’s behavior by setting thedata-autoscroll-behaviorattribute to a valid Element.scrollIntoView({ behavior: “…” }) value: one of"auto", or"smooth". Whendata-autoscroll-behavioris absent, the default value is"auto".
# プロパティ
すべての<turbo-frame>要素は、FrameElementクラスのインスタンスを通してJavaScript環境でコントロールされます。
FrameElement.srcは、読み込むパス名またはURLをコントロールします。srcプロパティを設定すると、要素はすぐに遷移します。FrameElement.loadedが"lazy"の場合、srcプロパティの変更は、要素の遷移をビューポートに表示されるまで遅らせます。FrameElement.disabledは真偽値のプロパティで、要素を読み込むかどうかをコントロールします。FrameElement.loadingは、フレームがコンテンツを読み込むスタイル("eager"または"lazy")をコントロールします。FrameElement.loadedで、FrameElementの遷移が完了した後に解決されるPromiseインスタンスを参照できます。FrameElement.completeは読み取り専用の真偽値プロパティで、FrameElementの遷移が終了した時にtrueに設定され、そうでなければfalseに設定されます。FrameElement.autoscrollは、一度読み込まれた要素をスクロールするかどうかをコントロールします。FrameElement.isActiveは読み取り専用の真偽値プロパティで、フレームが読み込まれインタラクションできる状態になっているかどうかを示します。FrameElement.isPreviewは読み取り専用の真偽値プロパティで、要素を含むdocumentがプレビューである場合にtrueを返します。
原文
# Properties
All <turbo-frame> elements can be controlled in JavaScript environments
through instances of the FrameElement class.
-
FrameElement.srccontrols the pathname or URL to be loaded. Setting thesrcproperty will immediately navigate the element. WhenFrameElement.loadedis set to"lazy", changes to thesrcproperty will defer navigation until the element is visible in the viewport. -
FrameElement.disabledis a boolean property that controls whether or not the element will load -
FrameElement.loadingcontrols the style (either"eager"or"lazy") that the frame will loading its content. -
FrameElement.loadedreferences a Promise instance that resolves once theFrameElement’s current navigation has completed. -
FrameElement.completeis a read-only boolean property set totruewhen theFrameElementhas finished navigating andfalseotherwise. -
FrameElement.autoscrollcontrols whether or not to scroll the element into view once loaded -
FrameElement.isActiveis a read-only boolean property that indicates whether or not the frame is loaded and ready to be interacted with -
FrameElement.isPreviewis a read-only boolean property that returnstruewhen thedocumentthat contains the element is a preview.
# 関数
FrameElement.reload()は、フレーム要素をそのsrcからリロードする関数です。
原文
# Functions
FrameElement.reload()is a function that reloads the frame element from itssrc.