| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::JSLoader; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: move js loading to the end of the document |
|
4
|
|
|
|
|
|
|
|
|
5
|
14
|
|
|
14
|
|
10039
|
use strict; |
|
|
14
|
|
|
|
|
32
|
|
|
|
14
|
|
|
|
|
411
|
|
|
6
|
14
|
|
|
14
|
|
68
|
use warnings; |
|
|
14
|
|
|
|
|
37
|
|
|
|
14
|
|
|
|
|
374
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
14
|
|
|
14
|
|
67
|
use parent 'Mojolicious::Plugin'; |
|
|
14
|
|
|
|
|
23
|
|
|
|
14
|
|
|
|
|
78
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
14
|
|
|
14
|
|
7341
|
use HTML::ParseBrowser; |
|
|
14
|
|
|
|
|
38206
|
|
|
|
14
|
|
|
|
|
539
|
|
|
11
|
14
|
|
|
14
|
|
98
|
use Mojo::ByteStream; |
|
|
14
|
|
|
|
|
28
|
|
|
|
14
|
|
|
|
|
648
|
|
|
12
|
14
|
|
|
14
|
|
5646
|
use version 0.77; |
|
|
14
|
|
|
|
|
25427
|
|
|
|
14
|
|
|
|
|
101
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = '0.08'; |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub register { |
|
17
|
14
|
|
|
14
|
1
|
10526
|
my ($self, $app, $config) = @_; |
|
18
|
|
|
|
|
|
|
|
|
19
|
14
|
|
100
|
|
|
92
|
my $base = $config->{base} || ''; |
|
20
|
|
|
|
|
|
|
|
|
21
|
14
|
100
|
100
|
|
|
76
|
if ( $base and substr( $base, -1 ) ne '/' ) { |
|
22
|
3
|
|
|
|
|
9
|
$base .= '/'; |
|
23
|
|
|
|
|
|
|
} |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
$app->helper( js_load => sub { |
|
26
|
61
|
|
|
61
|
|
406506
|
my $c = shift; |
|
27
|
|
|
|
|
|
|
|
|
28
|
61
|
100
|
|
|
|
170
|
return '' unless _match_browser($c, @_); |
|
29
|
|
|
|
|
|
|
|
|
30
|
57
|
100
|
|
|
|
316
|
if ( $_[1]->{check} ) { |
|
31
|
|
|
|
|
|
|
my $asset = $c->app->static->file( |
|
32
|
9
|
100
|
|
|
|
29
|
$_[1]->{no_base} ? $_[0] : "$base$_[0]" |
|
33
|
|
|
|
|
|
|
); |
|
34
|
|
|
|
|
|
|
|
|
35
|
9
|
100
|
|
|
|
1443
|
return '' if !$asset; |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
|
|
38
|
54
|
100
|
|
|
|
183
|
if ( $_[1]->{inplace} ) { |
|
39
|
10
|
|
|
|
|
23
|
my ($file,$config) = @_; |
|
40
|
10
|
100
|
|
|
|
29
|
my $local_base = $config->{no_base} ? '' : $base; |
|
41
|
|
|
|
|
|
|
|
|
42
|
10
|
100
|
|
|
|
43
|
$local_base = $c->url_for( $local_base ) if $local_base; |
|
43
|
|
|
|
|
|
|
|
|
44
|
10
|
100
|
|
|
|
781
|
$config->{no_file} = 1 if $config->{js}; |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
my $js = $config->{no_file} ? |
|
47
|
10
|
100
|
|
|
|
51
|
qq~~ : |
|
48
|
|
|
|
|
|
|
qq~~; |
|
49
|
10
|
|
|
|
|
530
|
return Mojo::ByteStream->new( $js ); |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
|
|
52
|
44
|
|
|
|
|
60
|
push @{ $c->stash->{__JSLOADERFILES__} }, [ @_ ]; |
|
|
44
|
|
|
|
|
130
|
|
|
53
|
|
|
|
|
|
|
|
|
54
|
44
|
|
|
|
|
506
|
return 1; |
|
55
|
14
|
|
|
|
|
198
|
} ); |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
$app->hook( after_render => sub { |
|
58
|
36
|
|
|
36
|
|
26894
|
my ($c, $content, $format) = @_; |
|
59
|
|
|
|
|
|
|
|
|
60
|
36
|
100
|
|
|
|
145
|
return if $format ne 'html'; |
|
61
|
35
|
100
|
|
|
|
125
|
return if !$c->stash->{__JSLOADERFILES__}; |
|
62
|
24
|
100
|
|
|
|
258
|
return if 'ARRAY' ne ref $c->stash->{__JSLOADERFILES__}; |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
my $load_js = |
|
65
|
|
|
|
|
|
|
join "\n", |
|
66
|
|
|
|
|
|
|
map{ |
|
67
|
42
|
|
|
|
|
190
|
my ($file,$config) = @{ $_ }; |
|
|
42
|
|
|
|
|
87
|
|
|
68
|
|
|
|
|
|
|
|
|
69
|
42
|
|
100
|
|
|
93
|
$file //= ''; |
|
70
|
|
|
|
|
|
|
|
|
71
|
42
|
100
|
|
|
|
105
|
my $local_base = $config->{no_base} ? '' : $base; |
|
72
|
|
|
|
|
|
|
|
|
73
|
42
|
100
|
|
|
|
117
|
$config->{no_file} = 1 if $config->{js}; |
|
74
|
|
|
|
|
|
|
|
|
75
|
42
|
100
|
|
|
|
122
|
$local_base = $c->url_for( $local_base ) if $local_base; |
|
76
|
|
|
|
|
|
|
|
|
77
|
42
|
100
|
100
|
|
|
4359
|
if ( $config->{no_file} and $config->{on_ready} ) { |
|
78
|
3
|
|
|
|
|
18
|
$file = sprintf '$(document).ready( function(){%s});', $file; |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
my $return = $config->{no_file} ? |
|
82
|
42
|
100
|
|
|
|
161
|
qq~~ : |
|
83
|
|
|
|
|
|
|
qq~~; |
|
84
|
|
|
|
|
|
|
|
|
85
|
42
|
100
|
|
|
|
3050
|
$file ? $return : (); |
|
86
|
|
|
|
|
|
|
} |
|
87
|
23
|
|
|
|
|
206
|
@{ $c->stash->{__JSLOADERFILES__} }; |
|
|
23
|
|
|
|
|
56
|
|
|
88
|
|
|
|
|
|
|
|
|
89
|
23
|
100
|
|
|
|
87
|
return if !$load_js; |
|
90
|
|
|
|
|
|
|
|
|
91
|
21
|
|
|
|
|
36
|
${$content} =~ s!( |