line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bootylicious::Plugin::AjaxLibLoader; |
2
|
1
|
|
|
1
|
|
26841
|
use strict; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
41
|
|
3
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
32
|
|
4
|
1
|
|
|
1
|
|
6
|
use base 'Mojolicious::Plugin'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
966
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
my %AjaxLibs = ( |
9
|
|
|
|
|
|
|
'jquery' => [ |
10
|
|
|
|
|
|
|
'1.3.2', 'http://ajax.googleapis.com/ajax/libs/jquery/%s/jquery.min.js' |
11
|
|
|
|
|
|
|
], |
12
|
|
|
|
|
|
|
'jqueryui' => [ |
13
|
|
|
|
|
|
|
'1.7.2', |
14
|
|
|
|
|
|
|
'http://ajax.googleapis.com/ajax/libs/jqueryui/%s/jquery-ui.min.js' |
15
|
|
|
|
|
|
|
], |
16
|
|
|
|
|
|
|
'prototype' => [ |
17
|
|
|
|
|
|
|
'1.6.0.3', |
18
|
|
|
|
|
|
|
'http://ajax.googleapis.com/ajax/libs/prototype/%s/prototype.js' |
19
|
|
|
|
|
|
|
], |
20
|
|
|
|
|
|
|
'scriptaculous' => [ |
21
|
|
|
|
|
|
|
'1.8.2', |
22
|
|
|
|
|
|
|
'http://ajax.googleapis.com/ajax/libs/scriptaculous/%s/scriptaculous.js' |
23
|
|
|
|
|
|
|
], |
24
|
|
|
|
|
|
|
'mootools' => [ |
25
|
|
|
|
|
|
|
'1.2.3', |
26
|
|
|
|
|
|
|
'http://ajax.googleapis.com/ajax/libs/mootools/%s/mootools-yui-compressed.js' |
27
|
|
|
|
|
|
|
], |
28
|
|
|
|
|
|
|
'dojo' => [ |
29
|
|
|
|
|
|
|
'1.3.1', 'http://ajax.googleapis.com/ajax/libs/dojo/%s/dojo/dojo.xd.js' |
30
|
|
|
|
|
|
|
], |
31
|
|
|
|
|
|
|
'swfobject' => [ |
32
|
|
|
|
|
|
|
'2.2', 'http://ajax.googleapis.com/ajax/libs/swfobject/%s/swfobject.js' |
33
|
|
|
|
|
|
|
], |
34
|
|
|
|
|
|
|
'yui' => [ |
35
|
|
|
|
|
|
|
'2.7.0', |
36
|
|
|
|
|
|
|
'http://ajax.googleapis.com/ajax/libs/yui/%s/build/yuiloader/yuiloader-min.js' |
37
|
|
|
|
|
|
|
], |
38
|
|
|
|
|
|
|
'ext_core' => [ |
39
|
|
|
|
|
|
|
'3.0.0', 'http://ajax.googleapis.com/ajax/libs/ext-core/%s/ext-core.js' |
40
|
|
|
|
|
|
|
], |
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub register { |
45
|
0
|
|
|
0
|
1
|
|
my ( $self, $app, $args ) = @_; |
46
|
0
|
|
0
|
|
|
|
$args ||= {}; |
47
|
|
|
|
|
|
|
$app->plugins->add_hook( |
48
|
|
|
|
|
|
|
after_dispatch => sub { |
49
|
0
|
|
|
0
|
|
|
shift; #Skip Mojolicious::Plugins obj |
50
|
0
|
|
|
|
|
|
my $c = shift; |
51
|
0
|
|
|
|
|
|
my ( $is_load, $libs ) = $self->_to_load( $c, $args ); |
52
|
0
|
0
|
|
|
|
|
return unless $is_load; |
53
|
0
|
|
|
|
|
|
$c->stash( 'libs_to_load' => $libs ); |
54
|
0
|
|
|
|
|
|
my $load_html = $c->render_partial( 'ajax_load', |
55
|
|
|
|
|
|
|
template_class => 'Bootylicious::Plugin::AjaxLibLoader' ); |
56
|
0
|
|
|
|
|
|
my $body = $c->res->body; |
57
|
0
|
|
|
|
|
|
$body =~ s/<[hH][eE][aA][dD]>/\n$load_html\n/; |
58
|
0
|
|
|
|
|
|
$c->res->body($body); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub _to_load { |
65
|
0
|
|
|
0
|
|
|
my $self = shift; |
66
|
0
|
|
|
|
|
|
my $c = shift; |
67
|
0
|
|
0
|
|
|
|
my $args = shift || {}; |
68
|
0
|
|
|
|
|
|
my $path = $c->req->url->path; |
69
|
0
|
|
|
|
|
|
$path =~ s/^\///; |
70
|
0
|
|
|
|
|
|
my @lib_to_load = (); |
71
|
0
|
|
|
|
|
|
foreach my $lib ( keys %AjaxLibs ) { |
72
|
0
|
0
|
|
|
|
|
if ( exists $args->{$lib} ) { |
73
|
0
|
|
0
|
|
|
|
my $path_for = $args->{ $lib . '_path' } || 'all'; |
74
|
0
|
0
|
0
|
|
|
|
if ( $path_for eq 'all' or $path =~ /^(?:$path_for)/ ) { |
75
|
0
|
|
0
|
|
|
|
push( |
76
|
|
|
|
|
|
|
@lib_to_load, |
77
|
|
|
|
|
|
|
{ |
78
|
|
|
|
|
|
|
'lib' => $lib, |
79
|
|
|
|
|
|
|
'version' => $args->{ $lib . '_version' } |
80
|
|
|
|
|
|
|
|| $AjaxLibs{$lib}->[0] |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
my $is_load = scalar(@lib_to_load); |
89
|
0
|
0
|
|
|
|
|
return () unless $is_load; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
#build libs url |
92
|
0
|
|
|
|
|
|
foreach my $l (@lib_to_load) { |
93
|
0
|
|
|
|
|
|
$l->{'src_url'} = $self->_build_src_url($l); |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
return ( $is_load, \@lib_to_load ); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub _build_src_url { |
101
|
0
|
|
|
0
|
|
|
my $self = shift; |
102
|
0
|
|
|
|
|
|
my $data = shift; |
103
|
0
|
|
|
|
|
|
return sprintf( $AjaxLibs{ $data->{'lib'} }->[1], $data->{'version'} ); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
1; |
107
|
|
|
|
|
|
|
__DATA__ |