pub struct Embed<T = Given> { /* private fields */ }Expand description
A page from another site in a locked frame, such as a video player or a map.
let video = Embed::url("https://www.youtube-nocookie.com/embed/abc")
.title(Text::from("Product tour"))
.allow([EmbedPermission::Fullscreen, EmbedPermission::PictureInPicture])
.aspect(16, 9)
.click_to_load("/static/tour.jpg");The frame gets sandbox="allow-scripts allow-same-origin allow-presentation",
referrerpolicy="no-referrer" and loading="lazy". When the address is not https or its
host is not in the app’s frame-src (App::csp(|c| c.frame_src([...]))), no frame is
rendered at all; a warning says why. With Embed::click_to_load the other site is not
contacted until the user presses the poster button.
A title is required, because screen readers announce frames by it:
let stack = Stack::new().add(Embed::url("https://player.example.com/v/1"));Implementations§
Source§impl<T> Embed<T>
impl<T> Embed<T>
Sourcepub fn allow(
self,
permissions: impl IntoIterator<Item = EmbedPermission>,
) -> Self
pub fn allow( self, permissions: impl IntoIterator<Item = EmbedPermission>, ) -> Self
Browser features the framed page may use. None unless set.
Sourcepub fn aspect(self, width: u32, height: u32) -> Self
pub fn aspect(self, width: u32, height: u32) -> Self
Width to height ratio of the frame. 16:9 unless set; zeros are ignored.
Sourcepub fn click_to_load(self, poster: impl Into<String>) -> Self
pub fn click_to_load(self, poster: impl Into<String>) -> Self
Shows a button first and loads the frame only when it is pressed, so the other site
learns nothing about visitors who do not use it. poster is an image shown on the button:
a path on the app or an https address on a host of img-src; pass "" for none.
Sourcepub fn notice(self, notice: impl Into<Text>) -> Self
pub fn notice(self, notice: impl Into<Text>) -> Self
A text of the app shown on the click to load button, such as a content warning. It is part
of the button’s accessible name, so screen readers read it before the button is pressed.
Without Embed::click_to_load it turns the button on with no poster.
let tour = Embed::url("https://video.example.com/embed/tour")
.title(Text::from("Product tour"))
.click_to_load("")
.notice(Text::from("This video is served by another site."));Sourcepub fn remember(self, key: ClientPref<Consent>) -> Self
pub fn remember(self, key: ClientPref<Consent>) -> Self
Remembers that the user pressed the click to load button, under a consent key declared
with crate::ClientPref::consent and registered with App::client_prefs, so embeds
bound to the same key load at once on later pages and in other tabs for the key’s
lifetime. Use it for a notice that should be confirmed once in a while, not on every page
that shows such an embed.
pub const EXTERNAL_VIDEO: ClientPref<Consent> =
ClientPref::consent("external-video", Duration::from_secs(24 * 60 * 60), Purpose::Necessary);
let tour = Embed::url("https://video.example.com/embed/tour")
.title(Text::from("Product tour"))
.notice(Text::from("This video is served by another site."))
.remember(EXTERNAL_VIDEO);The browser keeps the record in zeyn.state (see crate::ClientPref); no cookie is set
and the server never sees it, so cached public pages stay the same for everyone. A
remembered frame loads without moving focus (WCAG 2.2 3.2.1 On Focus and 2.4.3 Focus
Order); focus moves to the frame only after a real press. The button stays when the
record has ended or does not pass its checks, when the app did not register the key, and
without JavaScript. Without Embed::click_to_load it turns the button on with no poster.
Trait Implementations§
impl Complete for Embed<Given>
Source§impl Component for Embed<Given>
impl Component for Embed<Given>
fn render(&self, out: &mut String, r: &Render<'_>)
fn grid(&self) -> Option<&dyn GridSource>
fn form(&self) -> Option<&dyn FormSource>
Source§fn reveal(&self, _field: &str) -> Option<Revealed>
fn reveal(&self, _field: &str) -> Option<Revealed>
Source§fn import(&self) -> Option<&dyn ImportSource>
fn import(&self) -> Option<&dyn ImportSource>
crate::Import).Source§fn children(&self) -> &[Node]
fn children(&self) -> &[Node]
i of the node at path p has the path p.i.