| 1 | ##---------------------------------------------------------------------------- | ||
| 2 | ## HTML Object - ~/lib/HTML/Object/DOM/Element/Progress.pm | ||
| 3 | ## Version v0.2.0 | ||
| 4 | ## Copyright(c) 2021 DEGUEST Pte. Ltd. | ||
| 5 | ## Author: Jacques Deguest <jack@deguest.jp> | ||
| 6 | ## Created 2021/12/23 | ||
| 7 | ## Modified 2022/09/18 | ||
| 8 | ## All rights reserved | ||
| 9 | ## | ||
| 10 | ## | ||
| 11 | ## This program is free software; you can redistribute it and/or modify it | ||
| 12 | ## under the same terms as Perl itself. | ||
| 13 | ##---------------------------------------------------------------------------- | ||
| 14 | package HTML::Object::DOM::Element::Progress; | ||
| 15 | BEGIN | ||
| 16 | { | ||
| 17 | use strict; | ||
| 18 | use warnings; | ||
| 19 | warnings::register_categories( 'HTML::Object' ); | ||
| 20 | use parent qw( HTML::Object::DOM::Element ); | ||
| 21 | use vars qw( $VERSION ); | ||
| 22 | use HTML::Object::DOM::Element::Shared qw( :progress ); | ||
| 23 | our $VERSION = 'v0.2.0'; | ||
| 24 | }; | ||
| 25 | |||
| 26 | use strict; | ||
| 27 | use warnings; | ||
| 28 | |||
| 29 | sub init | ||
| 30 | { | ||
| 31 | my $self = shift( @_ ); | ||
| 32 | $self->{max} = '1.0'; | ||
| 33 | $self->{value} = 0; | ||
| 34 | $self->{_init_strict_use_sub} = 1; | ||
| 35 | $self->SUPER::init( @_ ) || return( $self->pass_error ); | ||
| 36 | $self->{tag} = 'progress' if( !CORE::length( "$self->{tag}" ) ); | ||
| 37 | return( $self ); | ||
| 38 | } | ||
| 39 | |||
| 40 | # Note: property labels read-only inherited | ||
| 41 | |||
| 42 | # Note: property max | ||
| 43 | sub max : lvalue { return( shift->_set_get_property( 'max', @_ ) ); } | ||
| 44 | |||
| 45 | # Note: property position read-only | ||
| 46 | sub position | ||
| 47 | { | ||
| 48 | my $self = shift( @_ ); | ||
| 49 | my $val = $self->value; | ||
| 50 | my $max = $self->max; | ||
| 51 | return(-1) if( !defined( $max ) || !CORE::length( "$max" ) || int( $max ) == 0 ); | ||
| 52 | return( $self->new_number( int( $val ) / int( $max ) ) ); | ||
| 53 | } | ||
| 54 | |||
| 55 | # Note: property value inherited | ||
| 56 | |||
| 57 | 1; | ||
| 58 | # NOTE: POD | ||
| 59 | __END__ | ||
| 60 | |||
| 61 | =encoding utf-8 | ||
| 62 | |||
| 63 | =head1 NAME | ||
| 64 | |||
| 65 | HTML::Object::DOM::Element::Progress - HTML Object DOM Progress Class | ||
| 66 | |||
| 67 | =head1 SYNOPSIS | ||
| 68 | |||
| 69 | use HTML::Object::DOM::Element::Progress; | ||
| 70 | my $progress = HTML::Object::DOM::Element::Progress->new || | ||
| 71 | die( HTML::Object::DOM::Element::Progress->error, "\n" ); | ||
| 72 | |||
| 73 | =head1 VERSION | ||
| 74 | |||
| 75 | v0.2.0 | ||
| 76 | |||
| 77 | =head1 DESCRIPTION | ||
| 78 | |||
| 79 | This interface provides special properties and methods (beyond the regular L<HTML::Object::Element> interface it also has available to it by inheritance) for manipulating the layout and presentation of C<<progress>> elements. | ||
| 80 | |||
| 81 | =head1 INHERITANCE | ||
| 82 | |||
| 83 | +-----------------------+ +---------------------------+ +-------------------------+ +----------------------------+ +--------------------------------------+ | ||
| 84 | | HTML::Object::Element | --> | HTML::Object::EventTarget | --> | HTML::Object::DOM::Node | --> | HTML::Object::DOM::Element | --> | HTML::Object::DOM::Element::Progress | | ||
| 85 | +-----------------------+ +---------------------------+ +-------------------------+ +----------------------------+ +--------------------------------------+ | ||
| 86 | |||
| 87 | =head1 PROPERTIES | ||
| 88 | |||
| 89 | Inherits properties from its parent L<HTML::Object::DOM::Element> | ||
| 90 | |||
| 91 | =head2 labels | ||
| 92 | |||
| 93 | Read-only. | ||
| 94 | |||
| 95 | Returns L<NodeList|HTML::Object::DOM::NodeList> containing the list of L<<label>|HTML::Object::DOM::Label> elements that are labels for this element. | ||
| 96 | |||
| 97 | Example: | ||
| 98 | |||
| 99 | <label id="label1" for="test">Label 1</label> | ||
| 100 | <progress id="test" value="70" max="100">70%</progress> | ||
| 101 | <label id="label2" for="test">Label 2</label> | ||
| 102 | |||
| 103 | use HTML::Object::DOM qw( window ); | ||
| 104 | window->addEventListener( DOMContentLoaded => sub | ||
| 105 | { | ||
| 106 | my $progress = $doc->getElementById( 'test' ); | ||
| 107 | for( my $i = 0; $i < $progress->labels->length; $i++ ) | ||
| 108 | { | ||
| 109 | say( $progress->labels->[$i]->textContent ); # "Label 1" and "Label 2" | ||
| 110 | } | ||
| 111 | }); | ||
| 112 | |||
| 113 | See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLProgressElement/labels> | ||
| 114 | |||
| 115 | =head2 max | ||
| 116 | |||
| 117 | Is a double value reflecting HTML attribute that describes the content attribute of the same name, limited to numbers greater than zero. Its default value is 1.0. | ||
| 118 | |||
| 119 | See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLProgressElement/max> | ||
| 120 | |||
| 121 | =head2 position | ||
| 122 | |||
| 123 | Read-only. | ||
| 124 | |||
| 125 | Returns a double value returning the result of dividing the current value (value) by the maximum value (max); if the progress bar is an indeterminate progress bar, it returns C<-1>. | ||
| 126 | |||
| 127 | See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLProgressElement/position> | ||
| 128 | |||
| 129 | =head2 value | ||
| 130 | |||
| 131 | Is a double value reflecting the HTML attribute that describes the current value; if the progress bar is an indeterminate progress bar, it returns C<0>. | ||
| 132 | |||
| 133 | my $progress = $doc->createElement( 'progress' ); | ||
| 134 | $progress->value = 2; # <progress value="2"></progress> | ||
| 135 | |||
| 136 | See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLProgressElement/value> | ||
| 137 | |||
| 138 | =head1 METHODS | ||
| 139 | |||
| 140 | Inherits methods from its parent L<HTML::Object::DOM::Element> | ||
| 141 | |||
| 142 | =head1 AUTHOR | ||
| 143 | |||
| 144 | Jacques Deguest E<lt>F<jack@deguest.jp>E<gt> | ||
| 145 | |||
| 146 | =head1 SEE ALSO | ||
| 147 | |||
| 148 | L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLProgressElement>, L<Mozilla documentation on progress element|https://developer.mozilla.org/en-US/docs/Web/HTML/Element/progress> | ||
| 149 | |||
| 150 | =head1 COPYRIGHT & LICENSE | ||
| 151 | |||
| 152 | Copyright(c) 2021 DEGUEST Pte. Ltd. | ||
| 153 | |||
| 154 | All rights reserved | ||
| 155 | |||
| 156 | This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. | ||
| 157 | |||
| 158 | =cut |