| 1 | package HTML::TurboForm::Element::Imageslider; | ||
| 2 | use warnings; | ||
| 3 | use strict; | ||
| 4 | use base qw(HTML::TurboForm::Element); | ||
| 5 | __PACKAGE__->mk_accessors( qw/ del_link max dir noimgs / ); | ||
| 6 | |||
| 7 | sub reset_js{ | ||
| 8 | my ($self)=@_; | ||
| 9 | |||
| 10 | my $name=$self->name; | ||
| 11 | |||
| 12 | $self->{options}=[] if (!$self->{options}); | ||
| 13 | my $nr_obj = scalar(@{ $self->{options} }); | ||
| 14 | |||
| 15 | #$nr_obj=1 if (($nr_obj == 0) and ($self->{options})); | ||
| 16 | |||
| 17 | my $max = $self->max; | ||
| 18 | $max = $nr_obj if($nr_obj < $max); | ||
| 19 | |||
| 20 | if ($nr_obj > 1){ | ||
| 21 | $self->{js} = ' | ||
| 22 | $(function() { | ||
| 23 | $("#'.$name.'").jCarouselLite({ | ||
| 24 | btnNext: "#next_'.$name.'", | ||
| 25 | btnPrev: "#prev_'.$name.'", | ||
| 26 | visible: '.$max.' | ||
| 27 | }); | ||
| 28 | }); | ||
| 29 | '; | ||
| 30 | } | ||
| 31 | } | ||
| 32 | |||
| 33 | sub render{ | ||
| 34 | my ($self, $options, $view)=@_; | ||
| 35 | if ($view) { $self->{view}=$view; } | ||
| 36 | my $result=''; | ||
| 37 | my $disabled=''; | ||
| 38 | my $class='form_slider'; | ||
| 39 | my $request=$self->request; | ||
| 40 | |||
| 41 | $self->label(' ') if ($self->label eq ''); | ||
| 42 | |||
| 43 | $class=$self->{class} if exists($self->{class}); | ||
| 44 | my $aha=$self->options; | ||
| 45 | my $name=$self->name; | ||
| 46 | my $nr_obj = scalar(@{ $self->{options} }); | ||
| 47 | |||
| 48 | $disabled=' disabled ' if ($options->{frozen} == 1); | ||
| 49 | my $dir=''; | ||
| 50 | $dir = $self->dir if ($self->dir); | ||
| 51 | |||
| 52 | if ($nr_obj>1){ | ||
| 53 | $result='<div class="slider_img" style="float:left;" id="prev_'.$name.'"><-</div>'; | ||
| 54 | $result.='<div class="slider_img" style="float:right;" id="next_'.$name.'">-></div>'."\n"; | ||
| 55 | #$result.='<div class="'.$class.'" id="'.$name.'"><ul>'."\n"; | ||
| 56 | $result.='<div class="'.$class.'" id="'.$name.'"><ul>'."\n"; | ||
| 57 | my $result2=''; | ||
| 58 | |||
| 59 | foreach (@{$self->{options}}){ | ||
| 60 | if (!$self->noimgs){ | ||
| 61 | if ($self->del_link){ | ||
| 62 | # $result2.='<img src="'.$dir.$_.'" border="0"/>'; | ||
| 63 | $result.='<li><input class="del_btn" type="submit" name="'.$self->name.'_delete_'.$_.'" value="Delete" /><br /> | ||
| 64 | <img src="'.$dir.$_.'" border="0"/></li>'."\n"; | ||
| 65 | }else{ | ||
| 66 | $result.='<li><img src="'.$dir.$_.'" border="0"/></li>'."\n"; | ||
| 67 | } | ||
| 68 | }; | ||
| 69 | if ($self->noimgs){ $result.='<li>'.$_.'</li>'."\n";} | ||
| 70 | } | ||
| 71 | $result.="</ul></div>"; | ||
| 72 | } | ||
| 73 | if ($nr_obj==1){ | ||
| 74 | foreach (@{$self->{options}}){ | ||
| 75 | $result.='<input class="del_btn" type="submit" name="'.$self->name.'_delete_'.$_.'" value="Delete" /><br /> | ||
| 76 | <img src="'.$dir.$_.'" border="0"/>'."\n"; | ||
| 77 | } | ||
| 78 | } | ||
| 79 | if ($nr_obj==0){ $result = '';} | ||
| 80 | |||
| 81 | $result= $self->vor($options).$result.$self->nach if ($self->check_param('norow')==0); | ||
| 82 | #$result= '' if ($self->{options}); | ||
| 83 | return $result; | ||
| 84 | } | ||
| 85 | |||
| 86 | |||
| 87 | sub init{ | ||
| 88 | my ($self)=@_; | ||
| 89 | |||
| 90 | @{$self->{modules}} = ('jquery/jquery','jquery/jcarousellite_1.0.1.min', 'jquery/easing'); | ||
| 91 | |||
| 92 | $self->{max} = 3; | ||
| 93 | my $name=$self->name; | ||
| 94 | $self->reset_js(); | ||
| 95 | } | ||
| 96 | |||
| 97 | sub get_dbix{ | ||
| 98 | my ($self)=@_; | ||
| 99 | return 0; | ||
| 100 | } | ||
| 101 | |||
| 102 | 1; | ||
| 103 | |||
| 104 | |||
| 105 | __END__ |