line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
##---------------------------------------------------------------------------- |
2
|
|
|
|
|
|
|
## HTML Object - ~/lib/HTML/Object/DOM/Element/Slot.pm |
3
|
|
|
|
|
|
|
## Version v0.2.0 |
4
|
|
|
|
|
|
|
## Copyright(c) 2022 DEGUEST Pte. Ltd. |
5
|
|
|
|
|
|
|
## Author: Jacques Deguest <jack@deguest.jp> |
6
|
|
|
|
|
|
|
## Created 2022/01/06 |
7
|
|
|
|
|
|
|
## Modified 2022/09/18 |
8
|
|
|
|
|
|
|
## All rights reserved |
9
|
|
|
|
|
|
|
## |
10
|
|
|
|
|
|
|
## |
11
|
|
|
|
|
|
|
## This program is free software; you can redistribute it and/or modify it |
12
|
|
|
|
|
|
|
## under the same terms as Perl itself. |
13
|
|
|
|
|
|
|
##---------------------------------------------------------------------------- |
14
|
|
|
|
|
|
|
package HTML::Object::DOM::Element::Slot; |
15
|
|
|
|
|
|
|
BEGIN |
16
|
|
|
|
|
|
|
{ |
17
|
1
|
|
|
1
|
|
1510
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
18
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
19
|
1
|
|
|
1
|
|
5
|
use parent qw( HTML::Object::DOM::Element ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
20
|
1
|
|
|
1
|
|
64
|
use vars qw( $VERSION ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
40
|
|
21
|
1
|
|
|
1
|
|
6
|
use HTML::Object::DOM::Element::Shared qw( :slot ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
111
|
|
22
|
1
|
|
|
1
|
|
18
|
our $VERSION = 'v0.2.0'; |
23
|
|
|
|
|
|
|
}; |
24
|
|
|
|
|
|
|
|
25
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
26
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
191
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub init |
29
|
|
|
|
|
|
|
{ |
30
|
0
|
|
|
0
|
1
|
|
my $self = shift( @_ ); |
31
|
0
|
|
|
|
|
|
$self->{_init_strict_use_sub} = 1; |
32
|
0
|
0
|
|
|
|
|
$self->SUPER::init( @_ ) || return( $self->pass_error ); |
33
|
0
|
0
|
|
|
|
|
$self->{tag} = 'slot' if( !CORE::length( "$self->{tag}" ) ); |
34
|
0
|
|
|
|
|
|
return( $self ); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
0
|
1
|
|
sub assign { return; } |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
0
|
1
|
|
sub assignedElements { return; } |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
0
|
1
|
|
sub assignedNodes { return; } |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# Note: property name is inherited |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
0
|
0
|
|
sub onslotchange : lvalue { return( shift->on( 'slotchange', @_ ) ); } |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
1; |
48
|
|
|
|
|
|
|
# NOTE: POD |
49
|
|
|
|
|
|
|
__END__ |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=encoding utf-8 |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 NAME |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
HTML::Object::DOM::Element::Slot - HTML Object DOM Slot Class |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 SYNOPSIS |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
use HTML::Object::DOM::Element::Slot; |
60
|
|
|
|
|
|
|
my $slot = HTML::Object::DOM::Element::Slot->new || |
61
|
|
|
|
|
|
|
die( HTML::Object::DOM::Element::Slot->error, "\n" ); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 VERSION |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
v0.2.0 |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 DESCRIPTION |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
This interface of the Shadow DOM API enables access to the name and assigned nodes of an HTML C<slot> element. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 INHERITANCE |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
+-----------------------+ +---------------------------+ +-------------------------+ +----------------------------+ +----------------------------------+ |
74
|
|
|
|
|
|
|
| HTML::Object::Element | --> | HTML::Object::EventTarget | --> | HTML::Object::DOM::Node | --> | HTML::Object::DOM::Element | --> | HTML::Object::DOM::Element::Slot | |
75
|
|
|
|
|
|
|
+-----------------------+ +---------------------------+ +-------------------------+ +----------------------------+ +----------------------------------+ |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 PROPERTIES |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Inherits properties from its parent L<HTML::Object::DOM::Element> |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head2 name |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
A string used to get and set the slot's name. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Example: |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
my $slots = this->shadowRoot->querySelectorAll('slot'); |
88
|
|
|
|
|
|
|
$slots->[1]->addEventListener( slotchange => sub |
89
|
|
|
|
|
|
|
{ |
90
|
|
|
|
|
|
|
my $nodes = $slots->[1]->assignedNodes(); |
91
|
|
|
|
|
|
|
say( 'Element in Slot "' . $slots->[1]->name . '" changed to "' . $nodes->[0]->outerHTML . '".'); |
92
|
|
|
|
|
|
|
}); |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLSlotElement/name> |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 METHODS |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Inherits methods from its parent L<HTML::Object::DOM::Element> |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head2 assign |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Under perl environment, this always returns C<undef>. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Under JavaScript, this sets the manually assigned nodes for this slot to the given nodes. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Example: |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub UpdateDisplayTab |
109
|
|
|
|
|
|
|
{ |
110
|
|
|
|
|
|
|
my( $elem, $tabIdx ) = @_; |
111
|
|
|
|
|
|
|
my $shadow = $elem->shadowRoot; |
112
|
|
|
|
|
|
|
my $slot = $shadow->querySelector( 'slot' ); |
113
|
|
|
|
|
|
|
my $panels = $elem->querySelectorAll( 'tab-panel' ); |
114
|
|
|
|
|
|
|
if( $panels->length && $tabIdx && $tabIdx <= $panels->length ) |
115
|
|
|
|
|
|
|
{ |
116
|
|
|
|
|
|
|
$slot->assign( $panels->[ $tabIdx - 1 ] ); |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
else |
119
|
|
|
|
|
|
|
{ |
120
|
|
|
|
|
|
|
$slot->assign(); |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLSlotElement/assign> |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head2 assignedElements |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Under perl environment, this always returns C<undef>. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Under JavaScript, this returns a sequence of the elements assigned to this slot (and no other nodes). If the flatten option is set to true, it also returns the assigned elements of any other slots that are descendants of this slot. If no assigned nodes are found, it returns the slot's fallback content. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Example: |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
my $slots = this->shadowRoot->querySelector('slot'); |
135
|
|
|
|
|
|
|
my $elements = $slots->assignedElements({ flatten => 1 }); |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLSlotElement/assignedElements> |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head2 assignedNodes |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Under perl environment, this always returns C<undef>. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Under JavaScript, this returns a sequence of the nodes assigned to this slot, and if the flatten option is set to true, the assigned nodes of any other slots that are descendants of this slot. If no assigned nodes are found, it returns the slot's fallback content. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
Example: |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
my $slots = this->shadowRoot->querySelectorAll('slot'); |
148
|
|
|
|
|
|
|
$slots->[1]->addEventListener( slotchange => sub |
149
|
|
|
|
|
|
|
{ |
150
|
|
|
|
|
|
|
my $nodes = $slots->[1]->assignedNodes(); |
151
|
|
|
|
|
|
|
say( 'Element in Slot "' . $slots->[1]->name . '" changed to "' . $nodes->[0]->outerHTML . '".' ); |
152
|
|
|
|
|
|
|
}); |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLSlotElement/assignedNodes> |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 EVENTS |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Event listeners for those events can also be found by prepending C<on> before the event type: |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
For example, C<slotchange> event listeners can be set also with C<onslotchange> method: |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
$e->onslotchange(sub{ # do something }); |
163
|
|
|
|
|
|
|
# or as an lvalue method |
164
|
|
|
|
|
|
|
$e->onslotchange = sub{ # do something }; |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head2 slotchange |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
Fired on an HTMLSlotElement instance (<slot> element) when the node(s) contained in that slot change. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Example: |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
my $slots = this->shadowRoot->querySelectorAll('slot'); |
173
|
|
|
|
|
|
|
$slots->[1]->addEventListener( slotchange => sub |
174
|
|
|
|
|
|
|
{ |
175
|
|
|
|
|
|
|
my $nodes = $slots->[1]->assignedNodes(); |
176
|
|
|
|
|
|
|
say( 'Element in Slot "' . $slots->[1]->name . '" changed to "' . $nodes->[0]->outerHTML . '".' ); |
177
|
|
|
|
|
|
|
}); |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLSlotElement/slotchange_event> |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head1 AUTHOR |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
Jacques Deguest E<lt>F<jack@deguest.jp>E<gt> |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head1 SEE ALSO |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLSlotElement>, L<Mozilla documentation on slot element|https://developer.mozilla.org/en-US/docs/Web/HTML/Element/slot> |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
Copyright(c) 2022 DEGUEST Pte. Ltd. |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
All rights reserved |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=cut |