X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=SelectLayers.pm;h=54440719de65c43afa40a5092c9f2d1e74056665;hb=c596647a05d29ca82878b47dbc78112916c19950;hp=6acb19d7f8d64494a794990a90aa0d36c02846f8;hpb=0522831b021c55984699ce20fd4e19950d055161;p=HTML-Widgets-SelectLayers.git diff --git a/SelectLayers.pm b/SelectLayers.pm index 6acb19d..5444071 100644 --- a/SelectLayers.pm +++ b/SelectLayers.pm @@ -3,7 +3,7 @@ package HTML::Widgets::SelectLayers; use strict; use vars qw($VERSION); -$VERSION = '0.02'; +$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 '
'. + print ''. ''. ''. ''. @@ -46,15 +55,16 @@ is visible at any given time, controlled by a ESELECTE box. For an example see http://www.420.am/selectlayers/ This HTML generated by this module uses JavaScript, but nevertheless attempts -to be as cross-browser as possible, testing for features via DOM support rather -than specific browsers or versions. It has been tested under Mozilla 0.9.8, -Netscape 4.77, IE 5.5, Konqueror 2.2.2, and Opera 5.0. +to be as cross-browser as possible. The 0.05 release drops Navigator 4 +compatibility and has been tested under Mozilla Firefox 1.0.6, MSIE 6.0, +Konqueror 3.3.2, and Opera 8.0.2 (2006 note: still working under newer +browsers such as IE7, Firefox 2.0, etc.). =head1 FORMS -Not all browsers seem happy with forms that span layers. The generated HTML -will have a E/FORME tag before the layers and will generate -EFORME and E/FORME tags for each layer. To facilitate +My understanding is that forms cannot span EDIVEs elements. The +generated HTML will have a E/FORME tag before the layers and will +generate EFORME and E/FORME tags for each layer. To facilitate ESUBMITE buttons located within the layers, you can pass a form name and element names, and the relevant values will be copied to the layer's form. See the B options below. @@ -81,14 +91,22 @@ form_name - (optional) Form name to copy values from. If not supplied, no form_action - Form action +form_elements - (optional) Array reference of form fields to copy from the + B form. Field type is autodetected; currently + text, hidden, checkbox, and select fields are + supported. Radio fields are not yet supported. + form_text - (optional) Array reference of text (or hidden) form fields to copy from the B form. form_checkbox - (optional) Array reference of checkbox form fields to copy from the B form. -form_select - (optional) Array reference of select (not select multiple) form - fields to copy from the B form. +form_radio - (optional) Array reference of radio form fields to copy from the + B form. + +form_select - (optional) Array reference of select form fields to copy from + the B form. fixup_callback - (optional) subroutine reference, returns supplimentary JavaScript for the function described above under FORMS. @@ -100,6 +118,8 @@ unique_key - (optional) prepended to all JavaScript function/variable/object html_beween - (optional) HTML between the ESELECTE and the layers. +under_position - (optional) specifies the positioning of any HTML appearing after the widget. I, the default, positions subsequent HTML underneath the current layer (or immediately under the select box if no layer has yet been selected), reflowing when layers are changed. I calculates the size of the largest layer and keeps the subsequent HTML in a single position underneath it. Note that I works by positioning subsequent HTML in a EDIVE, so you should probably close it yourself with a E/DIVE before your E/HTMLE end tag. I is a bit experimental and might have some quirks with truncating the end of the page under IE; you might have better results by just making all your layers the exact same size at the moment. + =cut sub new { @@ -123,43 +143,50 @@ sub html { my $between = exists($self->{html_between}) ? $self->{html_between} : ''; my $options = $self->{options}; my $form_action = exists($self->{form_action}) ? $self->{form_action} : ''; + + 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 $form_radio = + exists($self->{form_radio}) ? $self->{form_radio} : []; my $form_select = exists($self->{form_select}) ? $self->{form_select} : []; + my $under_position = + exists($self->{under_position}) ? $self->{under_position} : 'static'; + my $hidden = lc($under_position) eq 'absolute' + ? 'visibility: hidden; position: absolute; z-index: 0' + : 'display: none; z-index: 0'; + #my $show = lc($under_position) eq 'absolute' + # ? 'visibility: visible' + # : 'display: "" '; + my $html = $self->_safeonload. $self->_visualize. "". $self->_changed. $self->_fixup. - $self->_select. $between. ''; + $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 - foreach my $f ( @$form_text, @$form_checkbox, @$form_select ) { + foreach my $f ( @$form_elements, @$form_text, @$form_checkbox, @$form_radio, @$form_select ) + { $html .= < END @@ -171,18 +198,24 @@ END #end form & layer $html .= < - +
END } + if ( $under_position eq 'absolute' ) { + $html .= < + //var max = ${key}maxHeight; + document.write("
"); + +END + } + $html; } @@ -190,19 +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 $form_radio = + exists($self->{form_radio}) ? $self->{form_radio} : []; my $form_select = exists($self->{form_select}) ? $self->{form_select} : []; - my $html = " + 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"; } @@ -214,6 +303,13 @@ sub _fixup { what.$f.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"; } @@ -236,7 +332,7 @@ sub _select {