X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=SelectLayers.pm;h=54440719de65c43afa40a5092c9f2d1e74056665;hb=c596647a05d29ca82878b47dbc78112916c19950;hp=7e5bbc86447df334bdea7197154fff743e8e1478;hpb=648754131458fe53c7ac041b8b3ad8aa5e968dd9;p=HTML-Widgets-SelectLayers.git
diff --git a/SelectLayers.pm b/SelectLayers.pm
index 7e5bbc8..5444071 100644
--- a/SelectLayers.pm
+++ b/SelectLayers.pm
@@ -3,7 +3,7 @@ package HTML::Widgets::SelectLayers;
use strict;
use vars qw($VERSION);
-$VERSION = '0.01';
+$VERSION = '0.07';
=head1 NAME
@@ -23,8 +23,17 @@ HTML::Widgets::SelectLayers - Perl extension for selectable HTML layers
'options' => \%options,
'form_name' => 'dummy',
'form_action' => 'process.cgi',
- 'form_text' => [ qw( textfield1 textfield2 ) ],
- 'form_checkbox' => [ qw( checkbox1 ) ],
+
+ #new code auto-detects form types (radio not yet supported)
+ #'form_elements' => [ qw( textfield1 textfield2 checkbox1 radio1 select1 ) ],
+ 'form_elements' => [ qw( textfield1 textfield2 checkbox1 radio1 select1 ) ],
+
+ #deprecated style still works for now
+ #'form_text' => [ qw( textfield1 textfield2 ) ],
+ #'form_checkbox' => [ qw( checkbox1 ) ],
+ #'form_radio' => [ qw( radio1 ) ],
+ #'form_select' => [ qw( select1 ) ],
+
'layer_callback' => sub {
my $layer = shift;
my $html = qq!!;
@@ -33,7 +42,7 @@ HTML::Widgets::SelectLayers - Perl extension for selectable HTML layers
},
);
- print '
';
+ $self->_select. $between. ''.
+ "";
#foreach my $layer ( 'konq_kludge', keys %$options ) {
foreach my $layer ( keys %$options ) {
#start layer
- my $visibility = "hidden";
+
$html .= <
- if (document.getElementById) {
- document.write("");
- } else {
-END
- $visibility="show" if $visibility eq "visible";
- $html .= <
");
- }
-
+
END
#form fields
$html .= <
+
END
}
+ if ( $under_position eq 'absolute' ) {
+ $html .= <
+ //var max = ${key}maxHeight;
+ document.write("");
+
+END
+ }
+
$html;
}
@@ -187,17 +223,75 @@ sub _fixup {
my $self = shift;
my $key = exists($self->{unique_key}) ? $self->{unique_key} : '';
my $form_name = $self->{form_name} or return '';
+
+ my $form_elements =
+ exists($self->{form_elements}) ? $self->{form_elements} : [];
my $form_text =
exists($self->{form_text}) ? $self->{form_text} : [];
my $form_checkbox =
exists($self->{form_checkbox}) ? $self->{form_checkbox} : [];
- my $html = "
+ my $form_radio =
+ exists($self->{form_radio}) ? $self->{form_radio} : [];
+ my $form_select =
+ exists($self->{form_select}) ? $self->{form_select} : [];
+ my $html = <
- function ${key}fchanged(what) {
- ${key}fixup(what.form);
+
+function copyelement(from, to) {
+ if ( from.type == undefined ) {
+ to.value = '';
+ } else if ( from.type == 'select-one' ) {
+ to.value = from.options[from.selectedIndex].value;
+ //alert(from + " (" + from.type + "): " + to.name + " => (" + from.selectedIndex + ") " + to.value);
+ } else if ( from.type == 'select-multiple' ) {
+ var i = 0;
+ var count = 0;
+ var values = new Array();
+ for (i=0;i 0) {
+ to.value = values[values.length-1];
+ }else{
+ to.value = '';
+ }
+ } else if ( from.type == 'checkbox' ) {
+ if ( from.checked ) {
+ to.value = from.value;
+ } else {
+ to.value = '';
+ }
+// } else if ( from.type == 'radio' ) {
+ } else {
+ if ( from.value == undefined ) {
+ to.value = '';
+ } else {
+ to.value = from.value;
+ }
+ }
+ //alert(from + " (" + from.type + "): " + to.name + " => " + to.value);
+}
+END
+
+ $html .= "
+ //function ${key}fchanged(what) {
+ // ${key}fixup(what.form);
+ //}
function ${key}fixup(what) {\n";
+ foreach my $f ( @$form_elements ) {
+ $html .= "copyelement( document.$form_name.elements['$f'],
+ what.elements['$f']
+ )\n";
+ }
+
foreach my $f ( @$form_text ) {
$html .= "what.$f.value = document.$form_name.$f.value;\n";
}
@@ -209,9 +303,16 @@ sub _fixup {
what.$f.value = '';\n"
}
-# foreach my $f ( @$form_select ) {
-# $html .= "what.$f.value = document.$form_name.$f.options[document.$form_name.$f.selectedIndex].value;\n";
-# }
+ foreach my $f ( @$form_radio ) {
+ $html .= "what.$f.value = '';
+ for ( i=0; i< document.$form_name.$f.length; i++ )
+ if ( document.$form_name.$f\[i].checked )
+ what.$f.value = document.$form_name.$f\[i].value;\n";
+ }
+
+ foreach my $f ( @$form_select ) {
+ $html .= "what.$f.value = document.$form_name.$f.options[document.$form_name.$f.selectedIndex].value;\n";
+ }
$html .= &{$self->{fixup_callback}}() if exists($self->{fixup_callback});
@@ -231,7 +332,7 @@ sub _select {