Revision 9836938f
Von Sven Schöling vor mehr als 3 Jahren hinzugefügt
SL/Layout/Base.pm | ||
---|---|---|
103 | 103 |
|
104 | 104 |
|
105 | 105 |
######################################### |
106 |
# Interface
|
|
106 |
# Stylesheets
|
|
107 | 107 |
######################################## |
108 | 108 |
|
109 |
# override in sub layouts |
|
110 |
sub static_stylesheets {} |
|
111 |
|
|
109 | 112 |
sub add_stylesheets { |
110 | 113 |
&use_stylesheet; |
111 | 114 |
} |
... | ... | |
113 | 116 |
sub use_stylesheet { |
114 | 117 |
my $self = shift; |
115 | 118 |
push @{ $self->{stylesheets} ||= [] }, @_ if @_; |
116 |
@{ $self->{stylesheets} ||= [] }; |
|
119 |
(map { $_->use_stylesheet } $self->sub_layouts), $self->static_stylesheets, @{ $self->{stylesheets} ||= [] };
|
|
117 | 120 |
} |
118 | 121 |
|
119 | 122 |
sub stylesheets { |
... | ... | |
121 | 124 |
my $css_path = $self->get_stylesheet_for_user; |
122 | 125 |
|
123 | 126 |
return uniq grep { $_ } map { $self->_find_stylesheet($_, $css_path) } |
124 |
$self->use_stylesheet, map { $_->stylesheets } $self->sub_layouts;
|
|
127 |
$self->use_stylesheet; |
|
125 | 128 |
} |
126 | 129 |
|
127 | 130 |
sub _find_stylesheet { |
... | ... | |
150 | 153 |
return $css_path; |
151 | 154 |
} |
152 | 155 |
|
156 |
######################################### |
|
157 |
# Javascripts |
|
158 |
######################################## |
|
159 |
|
|
160 |
# override in sub layouts |
|
161 |
sub static_javascripts {} |
|
162 |
|
|
153 | 163 |
sub add_javascripts { |
154 | 164 |
&use_javascript |
155 | 165 |
} |
... | ... | |
157 | 167 |
sub use_javascript { |
158 | 168 |
my $self = shift; |
159 | 169 |
push @{ $self->{javascripts} ||= [] }, @_ if @_; |
160 |
@{ $self->{javascripts} ||= [] }; |
|
170 |
map({ $_->use_javascript } $self->sub_layouts), $self->static_javascripts, @{ $self->{javascripts} ||= [] };
|
|
161 | 171 |
} |
162 | 172 |
|
163 | 173 |
sub javascripts { |
164 | 174 |
my ($self) = @_; |
165 | 175 |
|
166 | 176 |
return uniq grep { $_ } map { $self->_find_javascript($_) } |
167 |
map({ $_->javascripts } $self->sub_layouts), $self->use_javascript;
|
|
177 |
$self->use_javascript; |
|
168 | 178 |
} |
169 | 179 |
|
170 | 180 |
sub _find_javascript { |
... | ... | |
285 | 295 |
$_[0]->SUPER::post_content |
286 | 296 |
} |
287 | 297 |
|
288 |
For the stylesheet and javascript callbacks things are hard, because of the |
|
289 |
backwards compatibility, and the built-in sanity checks. The best way currently |
|
290 |
is to just add your content and dispatch to the base method. |
|
291 | 298 |
|
292 |
sub stylesheets { |
|
293 |
$_[0]->add_stylesheets(qw(mystyle1.css mystyle2.css); |
|
294 |
$_[0]->SUPER::stylesheets; |
|
299 |
Stylesheets and Javascripts can be added to every layout and sub-layout at |
|
300 |
runtime with L<SL::Layout::Dispatcher/add_stylesheets> and |
|
301 |
L<SL::Layout::Dispatcher/add_javascripts> (C<use_stylesheets> and |
|
302 |
C<use_javascripts> are aliases for backwards compatibility): |
|
303 |
|
|
304 |
$layout->add_stylesheets("custom.css"); |
|
305 |
$layout->add_javascripts("app.js", "widget.js"); |
|
306 |
|
|
307 |
Or they can be overwritten in sub layouts with the calls |
|
308 |
L<SL::Layout::Displatcher/static_stylesheets> and |
|
309 |
L<SL::Layout::Dispatcher/static_javascripts>: |
|
310 |
|
|
311 |
sub static_stylesheets { |
|
312 |
"custom.css" |
|
313 |
} |
|
314 |
|
|
315 |
sub static_javascripts { |
|
316 |
qw(app.css widget.js) |
|
295 | 317 |
} |
296 | 318 |
|
319 |
Note how these are relative to the base dirs of the currently selected |
|
320 |
stylesheets. Javascripts are resolved relative to the C<js/> basedir. |
|
321 |
|
|
322 |
Setting directly with C<stylesheets> and C<javascripts> is eprecated. |
|
323 |
|
|
324 |
|
|
297 | 325 |
=head1 GORY DETAILS ABOUT JAVASCRIPT AND STYLESHEET OVERLOADING |
298 | 326 |
|
299 | 327 |
The original code used to store one stylesheet in C<< $form->{stylesheet} >> and |
Auch abrufbar als: Unified diff
Layout::Base: besseres sub_layout javascript/css dispatching
sub_layouts werden jetzt mit add/use aggregiert. add/use gibt aber immer
auch die der sub_layouts zurück.
Statt die zu überschreiben gibt es jetzt die neuen callbacks
die zusätzlich zurückgeliefert werden.
Die alten einstiegspunkte
machen jetzt die Auflösung in die Webpfade, so dass nur das oberste
layout den Mechanismus überschreiben braucht wenn benötigt.