1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use crate::;
/// Structure passed as a parameter to callback on on_message event: a message the page in a frame
/// (`<iframe>`) sent to the page with the frame, with `parent.postMessage`.
///
/// Only messages from the page in this frame come - not from other frames, the page itself or
/// a worker - but that page may be any page the frame went to. So check [`MessageEvent::origin`]
/// before trusting what it says.
///
/// ```rust
/// use vertigo::{JsJson, MessageEvent, Value, bind, dom};
///
/// // A player in a frame tells how tall it wants to be
/// let height = Value::new(150);
///
/// let on_message = bind!(height, |message: MessageEvent| {
/// if message.origin != "https://player.example.com" {
/// return;
/// }
/// if let JsJson::Object(data) = &message.data
/// && let Some(JsJson::Number(wanted)) = data.get("height")
/// {
/// height.set(wanted.as_f64() as u32);
/// }
/// });
///
/// let style = height.map(|height| format!("height: {height}px"));
///
/// dom! {
/// <iframe src="https://player.example.com/" {style} {on_message} />
/// };
/// ```