94 |
sub popup { my $self = shift; $self->popup_dropdown('popup', @_); } |
sub popup { my $self = shift; $self->popup_dropdown('popup', @_); } |
95 |
sub dropdown { my $self = shift; $self->popup_dropdown('dropdown', @_); } |
sub dropdown { my $self = shift; $self->popup_dropdown('dropdown', @_); } |
96 |
|
|
97 |
our $re_html = qr{<(?:!--.+?--|(\w+).+?/\1|[^>]+/?)>}s; # relaxed html check for one semi-valid tag |
our $re_html = qr{<(?:!--|(\w+)|[^>]+)/?>}s; # relaxed html check for one semi-valid tag |
98 |
|
|
99 |
sub popup_dropdown { |
sub popup_dropdown { |
100 |
my ( $self, $type, $name, $content, $full ) = @_; |
my ( $self, $type, $name, $content, $full ) = @_; |
116 |
} |
} |
117 |
} |
} |
118 |
|
|
119 |
sub _inline_path { |
sub _inline_path_size { |
120 |
my ( $self, $path ) = @_; |
my ( $self, $path ) = @_; |
121 |
-s $path < $self->inline_smaller_than; |
-s $path < $self->inline_smaller_than && -s $path; |
122 |
} |
} |
123 |
|
|
124 |
sub _head_html { |
sub _head_html { |
126 |
my $out = ''; |
my $out = ''; |
127 |
foreach my $path ( @head ) { |
foreach my $path ( @head ) { |
128 |
$path =~ s!^/!!; |
$path =~ s!^/!!; |
129 |
|
my $size = $self->_inline_path_size( $path ); |
130 |
if ( $path =~ m/\.js$/ ) { |
if ( $path =~ m/\.js$/ ) { |
131 |
$out .= $self->_inline_path( $path ) ? |
$out .= $size ? |
132 |
qq|<script type="text/javascript">\n/* inline $path */\n\n| . read_file($path) . qq|\n</script>| : |
qq|<script type="text/javascript">\n/* inline $path $size bytes */\n\n| . read_file($path) . qq|\n</script>| : |
133 |
qq|<script type="text/javascript" src="/$path"></script>|; |
qq|<script type="text/javascript" src="/$path"></script>|; |
134 |
} elsif ( $path =~ m/\.css$/ ) { |
} elsif ( $path =~ m/\.css$/ ) { |
135 |
$out .= $self->_inline_path( $path ) ? |
$out .= $size ? |
136 |
qq|<style type="text/css">\n/* inline $path */\n\n| . read_file( $path ) . qq|\n</style>| : |
qq|<style type="text/css">\n/* inline $path $size bytes */\n\n| . read_file( $path ) . qq|\n</style>| : |
137 |
qq|<link type="text/css" rel="stylesheet" href="/$path" media="screen">|; |
qq|<link type="text/css" rel="stylesheet" href="/$path" media="screen">|; |
138 |
} elsif ( $path =~ m{<.+>}s ) { |
} elsif ( $path =~ m{<.+>}s ) { |
139 |
$out .= $path; |
$out .= $path; |
175 |
|
|
176 |
} |
} |
177 |
|
|
178 |
sub _add_something { |
sub _add_css_js { |
179 |
my ( $self, $regex, $tag, $type, $content ) = @_; |
my ( $self, $what, $content ) = @_; |
180 |
|
|
181 |
my ( $package, $path, $line ) = caller(1); |
my $tag = $what eq 'css' ? 'style' : 'script'; |
182 |
|
my $type = $what eq 'css' ? 'text/css' : 'text/javascript'; |
183 |
|
my $head; |
184 |
|
|
185 |
warn "# $regex $tag $type $content caller $package $path $line"; |
my ( $package, $path, $line ) = caller(1); |
186 |
|
|
187 |
if ( $content =~ $regex ) { |
if ( $content =~ m{\.(js|css)} ) { |
188 |
$content = "/$content" if -e $content; |
$content = "/$content" if -e $content; |
189 |
$self->add_head( strip ( qq| |
if ( $content =~ $re_html ) { |
190 |
<$tag type="$type" src="$content"> |
$head = qq| |
191 |
/* via $package at $path line $line */ |
$content |
192 |
</$tag> |
<!-- $type via $package at $path line $line --> |
193 |
| ) ); |
|; |
194 |
|
} elsif ( $what eq 'js' ) { |
195 |
|
$head = qq| |
196 |
|
<$tag type="$type" src="$content"> |
197 |
|
/* $what via $package at $path line $line */ |
198 |
|
</$tag> |
199 |
|
|; |
200 |
|
} else { |
201 |
|
$head = qq| |
202 |
|
<link rel="stylesheet" type="$type" href="$content"> |
203 |
|
<!-- $what via $package at $path line $line --> |
204 |
|
|; |
205 |
|
} |
206 |
} else { |
} else { |
207 |
$self->add_head(qq| |
$head = qq| |
208 |
<$tag type="$type"> |
<$tag type="$type"> |
209 |
/* via $package at $path line $line */ |
/* via $package at $path line $line */ |
210 |
$content |
$content |
211 |
</$tag> |
</$tag> |
212 |
|); |
|; |
213 |
}; |
}; |
214 |
|
$self->add_head( $head ); |
215 |
} |
} |
216 |
|
|
217 |
sub add_css { |
sub add_css { |
218 |
my ($self,$css) = @_; |
my ($self,$css) = @_; |
219 |
$self->_add_something( qr{\.css$}, qw{style text/css}, $css ); |
$self->_add_css_js( 'css', $css ); |
220 |
} |
} |
221 |
|
|
222 |
sub add_js { |
sub add_js { |
223 |
my ($self,$js) = @_; |
my ($self,$js) = @_; |
224 |
$self->_add_something( qr{\.js$}, qw{script text/javascript}, $js ); |
$self->_add_css_js( 'js', $js ); |
225 |
} |
} |
226 |
|
|
227 |
our $reload_counter = 0; |
our $reload_counter = 0; |