Skip to content

Commit

Permalink
Add sourceElement to NavigateEvent
Browse files Browse the repository at this point in the history
The sourceElement is either the clicked link, the submitter button, or the submitted form if there was no submitter button.

See https://github.com/WICG/navigation-api/blob/main/README.md#navigation-monitoring-and-interception for the original explainer.
  • Loading branch information
noamr authored Jan 28, 2025
1 parent a16b0e9 commit d5c8e5c
Showing 1 changed file with 46 additions and 19 deletions.
65 changes: 46 additions & 19 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -25640,8 +25640,9 @@ document.body.appendChild(wbr);</code></pre>
<li>
<p><span>Navigate</span><!--DONAV hyperlink--> <var>targetNavigable</var> to
<var>urlString</var> using <var>subject</var>'s <span>node document</span>, with <i
data-x="navigation-referrer-policy">referrerPolicy</i> set to <var>referrerPolicy</var> and <i
data-x="navigation-user-involvement">userInvolvement</i> set to <var>userInvolvement</var>.</p>
data-x="navigation-referrer-policy">referrerPolicy</i> set to <var>referrerPolicy</var>, <i
data-x="navigation-user-involvement">userInvolvement</i> set to <var>userInvolvement</var>,
and <i data-x="navigation-source-element">sourceElement</i> set to <var>subject</var>.</p>

<p class="note">Unlike many other types of navigations, following hyperlinks does not have
special "<code data-x="NavigationHistoryBehavior-replace">replace</code>" behavior for when
Expand Down Expand Up @@ -25721,7 +25722,8 @@ document.body.appendChild(wbr);</code></pre>
<var>navigation</var> with <i data-x="fire-navigate-download-destinationURL">destinationURL</i>
set to <var>urlString</var>, <i
data-x="fire-navigate-download-userInvolvement">userInvolvement</i> set to
<var>userInvolvement</var>, and <i data-x="fire-navigate-download-filename">filename</i> set to
<var>userInvolvement</var>, <i data-x="fire-navigate-download-sourceElement">sourceElement</i>
set to <var>subject</var>, and <i data-x="fire-navigate-download-filename">filename</i> set to
<var>filename</var>.</p></li>

<li><p>If <var>continue</var> is false, then return.</p></li>
Expand Down Expand Up @@ -60152,6 +60154,7 @@ fur
using the <code>form</code> element's <span>node document</span>, with <var
data-x="navigation-hh">historyHandling</var> set to <var>historyHandling</var>, <i
data-x="navigation-user-involvement">userInvolvement</i> set to <var>userInvolvement</var>,
<i data-x="navigation-source-element">sourceElement</i> set to <var>submitter</var>,
<i data-x="navigation-referrer-policy">referrerPolicy</i> set to <var>referrerPolicy</var>,
<i data-x="navigation-resource">documentResource</i> set to <var>postResource</var>, and <i
data-x="navigation-form-data-entry-list">formDataEntryList</i> set to <var>entry
Expand Down Expand Up @@ -95383,6 +95386,7 @@ interface <dfn interface>NavigateEvent</dfn> : <span>Event</span> {
readonly attribute DOMString? <span data-x="dom-NavigateEvent-downloadRequest">downloadRequest</span>;
readonly attribute any <span data-x="dom-NavigateEvent-info">info</span>;
readonly attribute boolean <span data-x="dom-NavigateEvent-hasUAVisualTransition">hasUAVisualTransition</span>;
readonly attribute Element? <span data-x="dom-NavigateEvent-sourceElement">sourceElement</span>;

undefined <span data-x="dom-NavigateEvent-intercept">intercept</span>(optional <span>NavigationInterceptOptions</span> options = {});
undefined <span data-x="dom-NavigateEvent-scroll">scroll</span>();
Expand Down Expand Up @@ -95513,6 +95517,12 @@ callback <dfn callback>NavigationInterceptHandler</dfn> = <span data-x="idl-Prom
dispatching this event. If true, the best user experience will be given if the author
synchronously updates the DOM to the post-navigation state.</p></dd>

<dt><code data-x=""><var>event</var>.<span subdfn data-x="dom-NavigateEvent-sourceElement">sourceElement</span></code></dt>
<dd><p>Returns the <code>Element</code> responsible for this navigation. This can be an
<code>a</code>or <code>area</code> element, a <span
data-x="concept-submit-button">submit button</span>, or a submitted <code>form</code>
element.</p></dd>

<dt><code data-x=""><var>event</var>.<span subdfn data-x="dom-NavigateEvent-intercept">intercept</span>({ <span subdfn data-x="dom-NavigationInterceptOptions-handler">handler</span>, <span subdfn data-x="dom-NavigationInterceptOptions-focusReset">focusReset</span>, <span subdfn data-x="dom-NavigationInterceptOptions-scroll">scroll</span> })</code></dt>
<dd>
<p>Intercepts this navigation, preventing its normal handling and instead converting it into a
Expand Down Expand Up @@ -95617,9 +95627,11 @@ callback <dfn callback>NavigationInterceptHandler</dfn> = <span data-x="idl-Prom
for="NavigateEvent"><code data-x="dom-NavigateEvent-formData">formData</code></dfn>, <dfn
attribute for="NavigateEvent"><code
data-x="dom-NavigateEvent-downloadRequest">downloadRequest</code></dfn>, <dfn attribute
for="NavigateEvent"><code data-x="dom-NavigateEvent-info">info</code></dfn>, and <dfn attribute
for="NavigateEvent"><code data-x="dom-NavigateEvent-info">info</code></dfn>, <dfn attribute
for="NavigateEvent"><code
data-x="dom-NavigateEvent-hasUAVisualTransition">hasUAVisualTransition</code></dfn> attributes
data-x="dom-NavigateEvent-hasUAVisualTransition">hasUAVisualTransition</code></dfn>, and
<dfn attribute for="NavigateEvent"><code
data-x="dom-NavigateEvent-sourceElement">sourceElement</code></dfn> attributes
must return the values they are initialized to.</p>

<p>The <dfn method for="NavigateEvent"><code
Expand Down Expand Up @@ -95932,7 +95944,8 @@ interface <dfn interface>NavigationDestination</dfn> {
<li><p>Return the result of performing the <span>inner <code
data-x="event-navigate">navigate</code> event firing algorithm</span> given
<var>navigation</var>, "<code data-x="dom-NavigationType-traverse">traverse</code>",
<var>event</var>, <var>destination</var>, <var>userInvolvement</var>, null, and null.</p></li>
<var>event</var>, <var>destination</var>, <var>userInvolvement</var>, null, null, and
null.</p></li>
</ol>

<p>To <dfn>fire a push/replace/reload <code data-x="event-navigate">navigate</code> event</dfn> at
Expand All @@ -95942,7 +95955,9 @@ interface <dfn interface>NavigationDestination</dfn> {
data-x="fire-navigate-prr-isSameDocument"><var>isSameDocument</var></dfn>, an optional <span>user
navigation involvement</span> <dfn
data-x="fire-navigate-prr-userInvolvement"><var>userInvolvement</var></dfn> (default "<code
data-x="uni-none">none</code>"), an optional <span>entry list</span>-or-null <dfn
data-x="uni-none">none</code>"), an optional <code>Element</code>-or-null <dfn
data-x="fire-navigate-prr-sourceElement"><var>sourceElement</var></dfn> (default null), an
optional <span>entry list</span>-or-null <dfn
data-x="fire-navigate-prr-formDataEntryList"><var>formDataEntryList</var></dfn> (default null), an
optional <span>serialized state</span> <dfn
data-x="fire-navigate-prr-navigationAPIState"><var>navigationAPIState</var></dfn> (default
Expand Down Expand Up @@ -95980,14 +95995,17 @@ interface <dfn interface>NavigationDestination</dfn> {
<li><p>Return the result of performing the <span>inner <code
data-x="event-navigate">navigate</code> event firing algorithm</span> given
<var>navigation</var>, <var>navigationType</var>, <var>event</var>, <var>destination</var>,
<var>userInvolvement</var>, <var>formDataEntryList</var>, and null.</p></li>
<var>userInvolvement</var>, <var>sourceElement</var>, <var>formDataEntryList</var>, and
null.</p></li>
</ol>

<p>To <dfn>fire a download request <code data-x="event-navigate">navigate</code> event</dfn> at a
<code>Navigation</code> <var>navigation</var> given a <span>URL</span> <dfn
data-x="fire-navigate-download-destinationURL"><var>destinationURL</var></dfn>, a <span>user
navigation involvement</span> <dfn
data-x="fire-navigate-download-userInvolvement"><var>userInvolvement</var></dfn>, and a string
data-x="fire-navigate-download-userInvolvement"><var>userInvolvement</var></dfn>, an
<code>Element</code>-or-null <dfn
data-x="fire-navigate-download-sourceElement"><var>sourceElement</var></dfn>, and a string
<dfn data-x="fire-navigate-download-filename"><var>filename</var></dfn>:</p>

<ol>
Expand Down Expand Up @@ -96019,15 +96037,17 @@ interface <dfn interface>NavigationDestination</dfn> {
<li><p>Return the result of performing the <span>inner <code
data-x="event-navigate">navigate</code> event firing algorithm</span> given
<var>navigation</var>, "<code data-x="dom-NavigationType-push">push</code>", <var>event</var>,
<var>destination</var>, <var>userInvolvement</var>, null, and <var>filename</var>.</p></li>
<var>destination</var>, <var>userInvolvement</var>, <var>sourceElement</var>, null, and
<var>filename</var>.</p></li>
</ol>

<p>The <dfn>inner <code data-x="event-navigate">navigate</code> event firing algorithm</dfn>
consists of the following steps, given a <code>Navigation</code> <var>navigation</var>, a
<code>NavigationType</code> <var>navigationType</var>, a <code>NavigateEvent</code>
<var>event</var>, a <code>NavigationDestination</code> <var>destination</var>, a <span>user
navigation involvement</span> <var>userInvolvement</var>, an <span>entry list</span>-or-null
<var>formDataEntryList</var>, and a string-or-null <var>downloadRequestFilename</var>:</p>
navigation involvement</span> <var>userInvolvement</var>, an <code>Element</code>-or-null
<var>sourceElement</var>, an <span>entry list</span>-or-null <var>formDataEntryList</var>, and a
string-or-null <var>downloadRequestFilename</var>:</p>

<ol>
<li>
Expand Down Expand Up @@ -96149,6 +96169,10 @@ interface <dfn interface>NavigationDestination</dfn> {
transition, to display a cached rendered state of the <var>document</var>'s <span>latest
entry</span>, was done by the user agent. Otherwise, initialize it to false.</p></li>

<li><p>Initialize <var>event</var>'s <code
data-x="dom-NavigateEvent-sourceElement">sourceElement</code> to
<var>sourceElement</var>.</p></li>

<li><p>Set <var>event</var>'s <span data-x="concept-NavigateEvent-abort-controller">abort
controller</span> to a <span>new</span> <code>AbortController</code> created in
<var>navigation</var>'s <span data-x="concept-relevant-realm">relevant realm</span>.</p></li>
Expand Down Expand Up @@ -100364,9 +100388,10 @@ location.href = '#foo';</code></pre>
null <dfn for="navigate" data-x="navigation-form-data-entry-list"
export><var>formDataEntryList</var></dfn> (default null), an optional <span>referrer
policy</span> <dfn data-x="navigation-referrer-policy"><var>referrerPolicy</var></dfn> (default
the empty string), and an optional <span>user navigation involvement</span> <dfn
the empty string), an optional <span>user navigation involvement</span> <dfn
data-x="navigation-user-involvement"><var>userInvolvement</var></dfn> (default "<code
data-x="uni-none">none</code>"):</p>
data-x="uni-none">none</code>"), and an optional <code>Element</code> <dfn
data-x="navigation-source-element"><var>sourceElement</var></dfn> (default null):</p>

<ol>
<li><p>Let <var>cspNavigationType</var> be "<code data-x="">form-submission</code>" if
Expand Down Expand Up @@ -100486,7 +100511,7 @@ location.href = '#foo';</code></pre>
<ol>
<li><p><span data-x="navigate-fragid">Navigate to a fragment</span> given <var>navigable</var>,
<var>url</var>, <var>historyHandling</var>, <var>userInvolvement</var>,
<var>navigationAPIState</var>, and <var>navigationId</var>.</p></li>
<var>sourceElement</var>, <var>navigationAPIState</var>, and <var>navigationId</var>.</p></li>

<li><p>Return.</p></li>
</ol>
Expand Down Expand Up @@ -100585,7 +100610,8 @@ location.href = '#foo';</code></pre>
data-x="fire-navigate-prr-navigationType">navigationType</i> set to <var>historyHandling</var>,
<i data-x="fire-navigate-prr-isSameDocument">isSameDocument</i> set to false, <i
data-x="fire-navigate-prr-userInvolvement">userInvolvement</i> set to
<var>userInvolvement</var>, <i
<var>userInvolvement</var>, <i data-x="fire-navigate-prr-sourceElement">sourceElement</i> set
to <var>sourceElement</var>, <i
data-x="fire-navigate-prr-formDataEntryList">formDataEntryList</i> set to
<var>entryListForFiring</var>, <i data-x="fire-navigate-prr-destinationURL">destinationURL</i>
set to <var>url</var>, and <i
Expand Down Expand Up @@ -101182,8 +101208,8 @@ location.href = '#foo';</code></pre>
<p>To <dfn data-x="navigate-fragid">navigate to a fragment</dfn> given a <span>navigable</span>
<var>navigable</var>, a <span>URL</span> <var>url</var>, a <span>history handling behavior</span>
<var>historyHandling</var>, a <span>user navigation involvement</span> <var>userInvolvement</var>,
a <span>serialized state</span>-or-null <var>navigationAPIState</var>, and a <span>navigation
ID</span> <var>navigationId</var>:</p>
an <code>Element</code>-or-null <var>sourceElement</var>, a <span>serialized state</span>-or-null
<var>navigationAPIState</var>, and a <span>navigation ID</span> <var>navigationId</var>:</p>

<ol>
<li><p>Let <var>navigation</var> be <var>navigable</var>'s <span data-x="nav-window">active
Expand All @@ -101201,7 +101227,8 @@ location.href = '#foo';</code></pre>
<var>navigation</var> with <i data-x="fire-navigate-prr-navigationType">navigationType</i> set to
<var>historyHandling</var>, <i data-x="fire-navigate-prr-isSameDocument">isSameDocument</i> set
to true, <i data-x="fire-navigate-prr-userInvolvement">userInvolvement</i> set to
<var>userInvolvement</var>, <i data-x="fire-navigate-prr-destinationURL">destinationURL</i>
<var>userInvolvement</var>, <i data-x="fire-navigate-prr-sourceElement">sourceElement</i> set
to <var>sourceElement</var>, <i data-x="fire-navigate-prr-destinationURL">destinationURL</i>
set to <var>url</var>, and <i
data-x="fire-navigate-prr-navigationAPIState">navigationAPIState</i> set to
<var>destinationNavigationAPIState</var>.</p></li>
Expand Down

0 comments on commit d5c8e5c

Please sign in to comment.