root/lang/perl/Moxy/trunk/lib/Moxy/Plugin/DisplayWidth.pm @ 31550

Revision 31550, 1.5 kB (checked in by tokuhirom, 4 years ago)

added default width for avoid warnings

Line 
1package Moxy::Plugin::DisplayWidth;
2use strict;
3use warnings;
4use base qw/Moxy::Plugin/;
5
6# HTML全体の横幅をUAの画面サイズに合わせる
7sub response_filter :Hook {
8    my ($class, $context, $args) = @_;
9    my $attr = $args->{mobile_attribute};
10    return if $attr->is_non_mobile;
11
12    # HTTP::MobileAttribute::Plugin::Display は AirHPhone に対応していない。
13    # が、ディスプレイ幅の指定がないと利用に耐えないので、現行機種のほとんどが 320px であることが下記 URL より確認できるので
14    # http://www.willcom-inc.com/ja/lineup/spec/voice/index.html
15    # 320px 固定にしておく。だれか Willcom が大好きでたまらないような人があらわれたら対応してください。
16    my $width = $attr->is_airh_phone ? 320 : $attr->display->width;
17    $width ||= 320; # なんかうまくとれなかったときのデフォルトのサイズは 320 とする。とくに理由はない。
18
19    my $header = qq!<div style="border: 1px black solid; width: ${width}px; margin: 0 auto;float: left;">!;
20
21    my $content = $args->{response}->content;
22    $content =~ s!(<body[^>]*>)!$1$header!i;
23    $content =~ s!(</body>)!"</div>$1"!ie;
24    $args->{response}->content($content);
25}
26
271;
28__END__
29
30=for stopwords localsrc HTML
31
32=head1 NAME
33
34Moxy::Plugin::DisplayWidth - limit the HTML width
35
36=head1 SYNOPSIS
37
38  - module: HTMLWidth
39
40=head1 DESCRIPTION
41
42limit the HTML width
43
44=head1 AUTHOR
45
46Kan Fushihara
47
48Tokuhiro Matsuno
49
50=head1 SEE ALSO
51
52L<Moxy>
Note: See TracBrowser for help on using the browser.