| 1 | package Tags::HTML::Element::Button; | ||
| 2 | |||
| 3 | 3 | ▶ | use base qw(Tags::HTML); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 3 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 3 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | |||
| 7 | 0 | ▶ | use Error::Pure qw(err); |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 8 | use Scalar::Util qw(blessed); | ||
| 9 | use Tags::HTML::Element::Utils qw(tags_boolean tags_data tags_value); | ||
| 10 | |||
| 11 | our $VERSION = 0.15; | ||
| 12 | |||
| 13 | sub _cleanup { | ||
| 14 | my $self = shift; | ||
| 15 | |||
| 16 | delete $self->{'_button'}; | ||
| 17 | |||
| 18 | return; | ||
| 19 | } | ||
| 20 | |||
| 21 | sub _init { | ||
| 22 | my ($self, $button) = @_; | ||
| 23 | |||
| 24 | # Check button. | ||
| 25 | if (! defined $button | ||
| 26 | || ! blessed($button) | ||
| 27 | || ! $button->isa('Data::HTML::Element::Button')) { | ||
| 28 | |||
| 29 | err "Button object must be a 'Data::HTML::Element::Button' instance."; | ||
| 30 | } | ||
| 31 | |||
| 32 | $self->{'_button'} = $button; | ||
| 33 | |||
| 34 | return; | ||
| 35 | } | ||
| 36 | |||
| 37 | # Process 'Tags'. | ||
| 38 | sub _process { | ||
| 39 | my $self = shift; | ||
| 40 | |||
| 41 | if (! exists $self->{'_button'}) { | ||
| 42 | return; | ||
| 43 | } | ||
| 44 | |||
| 45 | $self->{'tags'}->put( | ||
| 46 | ['b', 'button'], | ||
| 47 | ['a', 'type', $self->{'_button'}->type], | ||
| 48 | tags_value($self, $self->{'_button'}, 'css_class', 'class'), | ||
| 49 | tags_value($self, $self->{'_button'}, 'name'), | ||
| 50 | tags_value($self, $self->{'_button'}, 'id'), | ||
| 51 | tags_value($self, $self->{'_button'}, 'value'), | ||
| 52 | tags_boolean($self, $self->{'_button'}, 'autofocus'), | ||
| 53 | tags_boolean($self, $self->{'_button'}, 'disabled'), | ||
| 54 | ); | ||
| 55 | tags_data($self, $self->{'_button'}); | ||
| 56 | $self->{'tags'}->put( | ||
| 57 | ['e', 'button'], | ||
| 58 | ); | ||
| 59 | |||
| 60 | return; | ||
| 61 | } | ||
| 62 | |||
| 63 | sub _process_css { | ||
| 64 | my $self = shift; | ||
| 65 | |||
| 66 | if (! exists $self->{'_button'}) { | ||
| 67 | return; | ||
| 68 | } | ||
| 69 | |||
| 70 | my $css_class = ''; | ||
| 71 | if (defined $self->{'_button'}->css_class) { | ||
| 72 | $css_class = '.'.$self->{'_button'}->css_class; | ||
| 73 | } | ||
| 74 | |||
| 75 | $self->{'css'}->put( | ||
| 76 | ['s', 'button'.$css_class], | ||
| 77 | ['d', 'width', '100%'], | ||
| 78 | ['d', 'background-color', '#4CAF50'], | ||
| 79 | ['d', 'color', 'white'], | ||
| 80 | ['d', 'padding', '14px 20px'], | ||
| 81 | ['d', 'margin', '8px 0'], | ||
| 82 | ['d', 'border', 'none'], | ||
| 83 | ['d', 'border-radius', '4px'], | ||
| 84 | ['d', 'cursor', 'pointer'], | ||
| 85 | ['e'], | ||
| 86 | |||
| 87 | ['s', "button$css_class:hover"], | ||
| 88 | ['d', 'background-color', '#45a049'], | ||
| 89 | ['e'], | ||
| 90 | ); | ||
| 91 | |||
| 92 | return; | ||
| 93 | } | ||
| 94 | |||
| 95 | 1; | ||
| 96 | |||
| 97 | __END__ | ||