Jifty/Plugin/IEFixes.pm untested

filter: Statementstmt 0.0% 0 / 33 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 48 CC 3 SCAR 17.5
CC
3
Cov
0%
init
12.0
add_javascript
2.0
BEGIN
2.0
CRAP 5.8
1 use strict;
2 use warnings;
3  
4 package Jifty::Plugin::IEFixes;
5 use base 'Jifty::Plugin';
6  
7 =head1 NAME
8  
9 Jifty::Plugin::IEFixes - Add javascript files for IE
10  
11 =head1 SYNOPSIS
12  
13 # In your jifty config.yml under the framework section:
14  
15 Plugins:
16 - IEFixes:
17 use_external_ie7js: 1
18 js:
19 - IE7
20 - IE8
21 - ie7-recalc
22 - ie7-squish
23  
24  
25 In your app, if you want to add more IE-specific js:
26  
27 my ($ief) = Jifty->find_plugin('Jifty::Plugin::IEFixes')
28 $ief->add_javascript( qw(file.js) );
29  
30 =cut
31  
32 __PACKAGE__->mk_accessors(qw(use_external_ie7js js user_js));
33  
34 use constant IE7JS_VERSION => '2.0(beta3)';
35  
36 =head1 METHODS
37  
38 =head2 init
39  
40 Outputs IE-specific "conditional comments" in the C<< <head> >> of
41 each response which include more javascript.
42  
43 =cut
44  
45 sub init {
46 my $self = shift;
47 return if $self->_pre_init;
48  
49 my %opt = @_;
50 $self->use_external_ie7js( $opt{ use_external_ie7js } );
51 $self->user_js([]);
52 # default is just IE7.js
53 my @base_js = @{ $opt{ js } || ['IE7'] };
54  
55 Jifty::Web->add_trigger(
56 name => 'after_include_javascript',
57 callback => sub {
58 Jifty->web->out(qq{<!--[if lt IE 7]>\n});
59 if ($self->use_external_ie7js) {
60 Jifty->web->out(qq{<script src="http://ie7-js.googlecode.com/svn/version/@{[ IE7JS_VERSION ]}/$_.js" type="text/javascript"></script>\n}) for @base_js;
61 }
62 else {
63 # XXX: make ccjs able to cope with this as a separate CAS object
64 Jifty->web->out(qq{<script type="text/javascript" src="@{[ Jifty->web->static(qq{js/iefixes/$_.js}) ]}" type="text/javascript"></script>\n})
65 for @base_js;
66  
67 Jifty->web->out(qq{<script type="text/javascript" src="@{[ Jifty->web->static(qq{js/$_}) ]}" type="text/javascript"></script>\n})
68 for @{ $self->user_js };
69 }
70 Jifty->web->out(qq{<![endif]-->\n});
71 }
72 );
73  
74 }
75  
76 =head2 add_javascript FILE
77  
78 Can be called during application initialization (at startup time) to
79 add more javascript which should only be included in IE browsers. See
80 also L<Jifty::Web/add_javascript>.
81  
82 =cut
83  
84 sub add_javascript {
85 my $self = shift;
86 push @{ $self->user_js }, @_;
87 }
88  
89  
90  
91 1;