[csswg-drafts] [css-view-transitions-2] Script event on old Document for cross-document ViewTransitions (#8785)

khushalsagar has just created a new issue for https://github.com/w3c/csswg-drafts:

== [css-view-transitions-2] Script event on old Document for cross-document ViewTransitions ==
View Transition API needs to provide an event on the old Document to enable customization of the navigation based on the URL for the new Document and the current Document state. For example, the Document could have changed from user interaction after its first load.

The proposed IDL is as follows:

```
[Exposed=Window]
interface ViewTransitionBeforeCaptureEvent : Event {
  // The URL being navigated to, after resolving server-side redirects.
  readonly attribute USVString url;

  // Opaque contextual information passed to the new Document.
  // This must be a serializable object : https://developer.mozilla.org/en-US/docs/Glossary/Serializable_object.
  attribute any context;
};
```

The following is an API sketch for this event:

```js
document.addEventListener("viewtransitionbeforecapture", (event) => {
  // Cancel the transition (based on new URL) if needed.
  if (shouldNotTransition(event.toURL)) {
    event.preventDefault();
    return;
  }

  // Set up names on elements based on the new URL.
  if (shouldTagThumbnail(event.toURL)) {
    thumbnail.style.viewTransitionName = "full-embed";
  }

  // Add opaque contextual information to share with the new Document.
  event.context = createTransitionContext(event.url);
});
```

Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/8785 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Monday, 1 May 2023 21:47:03 UTC