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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
use super::*;
/// The DocumentFragment class.
/// [`DocumentFragment`](https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment)
#[derive(Clone, Debug, PartialEq, PartialOrd)]
#[repr(transparent)]
pub struct DocumentFragment {
inner: Node,
}
impl FromVal for DocumentFragment {
fn from_val(v: &Any) -> Self {
DocumentFragment {
inner: Node::from_val(v),
}
}
fn take_ownership(v: AnyHandle) -> Self {
Self::from_val(&Any::take_ownership(v))
}
fn as_handle(&self) -> AnyHandle {
self.inner.as_handle()
}
}
impl core::ops::Deref for DocumentFragment {
type Target = Node;
fn deref(&self) -> &Self::Target {
&self.inner
}
}
impl core::ops::DerefMut for DocumentFragment {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.inner
}
}
impl AsRef<Any> for DocumentFragment {
fn as_ref(&self) -> &Any {
&self.inner
}
}
impl AsMut<Any> for DocumentFragment {
fn as_mut(&mut self) -> &mut Any {
&mut self.inner
}
}
impl From<DocumentFragment> for Any {
fn from(s: DocumentFragment) -> Any {
let handle = s.inner.as_handle();
core::mem::forget(s);
Any::take_ownership(handle)
}
}
impl From<&DocumentFragment> for Any {
fn from(s: &DocumentFragment) -> Any {
s.inner.clone().into()
}
}
jsbind::utils::impl_dyn_cast!(DocumentFragment);
impl DocumentFragment {
/// Getter of the `children` attribute.
/// [`DocumentFragment.children`](https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment/children)
pub fn children(&self) -> HTMLCollection {
self.inner.get("children").as_::<HTMLCollection>()
}
}
impl DocumentFragment {
/// Getter of the `firstElementChild` attribute.
/// [`DocumentFragment.firstElementChild`](https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment/firstElementChild)
pub fn first_element_child(&self) -> Element {
self.inner.get("firstElementChild").as_::<Element>()
}
}
impl DocumentFragment {
/// Getter of the `lastElementChild` attribute.
/// [`DocumentFragment.lastElementChild`](https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment/lastElementChild)
pub fn last_element_child(&self) -> Element {
self.inner.get("lastElementChild").as_::<Element>()
}
}
impl DocumentFragment {
/// Getter of the `childElementCount` attribute.
/// [`DocumentFragment.childElementCount`](https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment/childElementCount)
pub fn child_element_count(&self) -> u32 {
self.inner.get("childElementCount").as_::<u32>()
}
}
impl DocumentFragment {
/// The `new DocumentFragment(..)` constructor, creating a new DocumentFragment instance
pub fn new() -> DocumentFragment {
Self {
inner: Any::global("DocumentFragment").new(&[]).as_::<Node>(),
}
}
}
impl DocumentFragment {
/// The getElementById method.
/// [`DocumentFragment.getElementById`](https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment/getElementById)
pub fn get_element_by_id(&self, element_id: &JsString) -> Element {
self.inner
.call("getElementById", &[element_id.into()])
.as_::<Element>()
}
}
impl DocumentFragment {
/// The prepend method.
/// [`DocumentFragment.prepend`](https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment/prepend)
pub fn prepend(&self, nodes: &Any) -> Undefined {
self.inner
.call("prepend", &[nodes.into()])
.as_::<Undefined>()
}
}
impl DocumentFragment {
/// The append method.
/// [`DocumentFragment.append`](https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment/append)
pub fn append(&self, nodes: &Any) -> Undefined {
self.inner
.call("append", &[nodes.into()])
.as_::<Undefined>()
}
}
impl DocumentFragment {
/// The replaceChildren method.
/// [`DocumentFragment.replaceChildren`](https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment/replaceChildren)
pub fn replace_children(&self, nodes: &Any) -> Undefined {
self.inner
.call("replaceChildren", &[nodes.into()])
.as_::<Undefined>()
}
}
impl DocumentFragment {
/// The moveBefore method.
/// [`DocumentFragment.moveBefore`](https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment/moveBefore)
pub fn move_before(&self, node: &Node, child: &Node) -> Undefined {
self.inner
.call("moveBefore", &[node.into(), child.into()])
.as_::<Undefined>()
}
}
impl DocumentFragment {
/// The querySelector method.
/// [`DocumentFragment.querySelector`](https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment/querySelector)
pub fn query_selector(&self, selectors: &JsString) -> Element {
self.inner
.call("querySelector", &[selectors.into()])
.as_::<Element>()
}
}
impl DocumentFragment {
/// The querySelectorAll method.
/// [`DocumentFragment.querySelectorAll`](https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment/querySelectorAll)
pub fn query_selector_all(&self, selectors: &JsString) -> NodeList {
self.inner
.call("querySelectorAll", &[selectors.into()])
.as_::<NodeList>()
}
}