HTML-Widgets-SelectLayers-0.07/0000755000175000017500000000000010571426575014675 5ustar ivanivanHTML-Widgets-SelectLayers-0.07/Makefile.PL0000644000175000017500000000101607443413001016625 0ustar ivanivanuse ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile( 'NAME' => 'HTML::Widgets::SelectLayers', 'VERSION_FROM' => 'SelectLayers.pm', # finds $VERSION 'PREREQ_PM' => {}, # e.g., Module::Name => 1.1 ($] >= 5.005 ? ## Add these new keywords supported since 5.005 (ABSTRACT_FROM => 'SelectLayers.pm', # retrieve abstract from module AUTHOR => 'Ivan Kohler ') : ()), ); HTML-Widgets-SelectLayers-0.07/Changes0000644000175000017500000000204410571426515016162 0ustar ivanivanRevision history for Perl extension HTML::Widgets::SelectLayers. 0.07 Wed Feb 28 17:32:35 PST 2007 - Also overdue: add support for select-multiple "form_elements" instead of the old form_* options. - eliminate dubious fchanged javascript function - check the type against undefined rather than the object itself in copyelement 0.06 Wed Dec 20 01:50:00 PST 2006 - Also long overdue: add auto-sensing of form field types, pass "form_elements" instead of the old form_* options. 0.05 Wed Aug 24 06:31:24 PDT 2005 - Long overdue: remove NN4 support. - Add under_position option, based on a patch from Ricardo SIGNES - set zIndex foo, hopefully selected layer will be active in IE properly now 0.04 Fri Jan 30 23:23:28 2004 - fix for pre-5.8 versions. *sigh* 0.03 Fri Jan 30 20:51:14 2004 - add form_radio 0.02 Thu May 9 03:05:15 2002 - enable form_select 0.01 Thu Mar 7 04:36:46 2002 - original version; created by h2xs 1.21 with options -A -X -n HTML::Widgets::SelectLayers HTML-Widgets-SelectLayers-0.07/test.pl0000644000175000017500000000077307443413001016200 0ustar ivanivan# Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl test.pl' ######################### # change 'tests => 1' to 'tests => last_test_to_print'; use Test; BEGIN { plan tests => 1 }; use HTML::Widgets::SelectLayers; ok(1); # If we made it this far, we're ok. ######################### # Insert your test code below, the Test module is use()ed here so read # its man page ( perldoc Test ) for help writing this test script. HTML-Widgets-SelectLayers-0.07/homepage.pl0000755000175000017500000001514010303075464017011 0ustar ivanivan#!/usr/bin/perl -w use strict; use Tie::IxHash; use HTML::Widgets::SelectLayers; tie my %o, 'Tie::IxHash', 'download' => 'Download', 'installation' => 'Installation', 'compatibility' => 'Compatibility', 'documentation' => 'Documentation', 'cvs' => 'Anonymous CVS access', ; my %html = ( 'download' => 'Download HTML-Widgets-SelectLayers-0.05.tar.gz', 'installation' => '
  perl Makefile.PL
  make
  make test
  make install
', 'cvs' => '
Anonymous CVS access is available:
  $ export CVSROOT=":pserver:anonymous@pouncequick.420.am:/home/cvs/cvsroot"
  $ cvs login
  (Logging in to anonymous@pouncequick.420.am
  CVS password: anonymous
  $ cvs checkout DBIx-DBSchema
as well as browsable via cvsweb.
', 'documentation' => join('',), 'compatibility' => '
This HTML generated by this module uses JavaScript, but nevertheless attempts
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.
', ); close DATA; my $w = new HTML::Widgets::SelectLayers( 'options' => \%o, 'selected_layer' => 'download', 'layer_callback' => sub { my $layer = shift; "
". $html{$layer}; }, #'form_action' => '', #'form_text' => [], #'form_checkbox' => [], ); print <html, "\n"; HTML::Widgets::SelectLayers - selectable HTML layers
HTML::Widgets::SelectLayers

Copyright (c) 2002-2005 Ivan Kohler
All rights reserved.
This program is free software; you can redistribute it and/or modify it under
the same terms as Perl itself.

This module implements an HTML widget with multiple layers.  Only one layer
is visible at any given time, controlled by a <SELECT> box.  For an example
see below.

END __DATA__

NAME

HTML::Widgets::SelectLayers - Perl extension for selectable HTML layers


SYNOPSIS

  use HTML::Widgets::SelectLayers;
  use Tie::IxHash;
  tie my %options, 'Tie::IxHash',
    'value'  => 'Select One',
    'value2' => 'Select Two',
  ;
  $widget = new HTML::Widgets::SelectLayers(
    'options'       => \%options,
    'form_name'     => 'dummy',
    'form_actoin'   => 'process.cgi',
    'form_text'     => [ qw( textfield1 textfield2 ) ],
    'form_checkbox' => [ qw( checkbox1 ) ],
    'layer_callback' => sub {
      my $layer = shift;
      my $html = qq!<INPUT TYPE="hidden" NAME="layer" VALUE="$layer">!;
      $html .= $other_stuff;
      $html;
    },
  );
  print '<FORM NAME=dummy>'.
        '<INPUT TYPE="text" NAME="textfield1">'.
        '<INPUT TYPE="text" NAME="textfield2">'.
        '<INPUT TYPE="checkbox" NAME="checkbox1" VALUE="Y">'.
        $widget->html;


DESCRIPTION

This module implements an HTML widget with multiple layers. Only one layer is visible at any given time, controlled by a <SELECT> 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. 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.


FORMS

Not all browsers seem happy with forms that span layers. The generated HTML will have a </FORM> tag before the layers and will generate <FORM> and </FORM> tags for each layer. To facilitate <SUBMIT> 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 form_ options below.


METHODS

new KEY, VALUE, KEY, VALUE...
Options are passed as name/value pairs:

options - Hash reference of layers and labels for the <SELECT>. See the Tie::IxHash manpage to control ordering. In HTML: <OPTION VALUE=``$layer''>$label</OPTION>

layer_callback - subroutine reference to create each layer. The layer name is passed as an option in @_

selected_layer - (optional) initially selected layer

form_name - (optional) Form name to copy values from. If not supplied, no values will be copied.

form_action - Form action

form_text - (optional) Array reference of text (or hidden) form fields to copy from the form_name form.

form_checkbox - (optional) Array reference of checkbox form fields to copy from the form_name form.

fixup_callback - (optional) subroutine reference, returns supplimentary JavaScript for the function described above under FORMS.

#form_select

size - (optional) size of the <SELECT>, default 1.

unique_key - (optional) prepended to all JavaScript function/variable/object names to avoid namespace collisions.

html_beween - (optional) HTML between the <SELECT> and the layers.

html
Returns HTML for the widget.


AUTHOR

Ivan Kohler <ivan-selectlayers@420.am>


COPYRIGHT

Copyright (c) 2002 Ivan Kohler All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


BUGS

JavaScript


SEE ALSO

perl. the Tie::IxHash manpage, http://www.xs4all.nl/~ppk/js/dom.html, http://javascript.about.com/library/scripts/blsafeonload.htm

HTML-Widgets-SelectLayers-0.07/README0000644000175000017500000000152210006635012015532 0ustar ivanivanHTML::Widgets::SelectLayers =========================== This module implements an HTML widget with multiple layers. Only one layer is visible at any given time, controlled by a !; $html .= $other_stuff; $html; }, ); print ''. ''. ''. ''. $widget->html; =head1 DESCRIPTION This module implements an HTML widget with multiple layers. Only one layer 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. 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 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. =head1 METHODS =over 4 =item new KEY, VALUE, KEY, VALUE... Options are passed as name/value pairs: options - Hash reference of layers and labels for the ESELECTE. See L to control ordering. In HTML: EOPTION VALUE="$layer"E$labelE/OPTIONE layer_callback - subroutine reference to create each layer. The layer name is passed as an option in I<@_> selected_layer - (optional) initially selected layer form_name - (optional) Form name to copy values from. If not supplied, no values will be copied. 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_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. size - (optional) size of the ESELECTE, default 1. unique_key - (optional) prepended to all JavaScript function/variable/object names to avoid namespace collisions. 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 { my($proto, %options) = @_; my $class = ref($proto) || $proto; my $self = \%options; bless($self, $class); } =cut =item html Returns HTML for the widget. =cut sub html { my $self = shift; my $key = exists($self->{unique_key}) ? $self->{unique_key} : ''; 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. ''. ""; #foreach my $layer ( 'konq_kludge', keys %$options ) { foreach my $layer ( keys %$options ) { #start layer $html .= < END #form fields $html .= < END foreach my $f ( @$form_elements, @$form_text, @$form_checkbox, @$form_radio, @$form_select ) { $html .= < END } #layer $html .= &{$self->{layer_callback}}($layer); #end form & layer $html .= < END } if ( $under_position eq 'absolute' ) { $html .= < //var max = ${key}maxHeight; document.write("
"); END } $html; } 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 = < 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"; } foreach my $f ( @$form_checkbox ) { $html .= "if (document.$form_name.$f.checked) what.$f.value = document.$form_name.$f.value; else 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"; } $html .= &{$self->{fixup_callback}}() if exists($self->{fixup_callback}); $html .= "}\n"; $html; } sub _select { my $self = shift; my $key = exists($self->{unique_key}) ? $self->{unique_key} : ''; my $options = $self->{options}; my $selected = exists($self->{selected_layer}) ? $self->{selected_layer} : ''; my $size = exists($self->{size}) ? $self->{size} : 1; my $html = " '; } sub _changed { my $self = shift; my $key = exists($self->{unique_key}) ? $self->{unique_key} : ''; my $options = $self->{options}; my $under_position = exists($self->{under_position}) ? $self->{under_position} : 'static'; my $html = " "; $html; } sub _visualize { my $self = shift; my $key = exists($self->{unique_key}) ? $self->{unique_key} : ''; return '' unless exists($self->{selected_layer}); my $selected = $self->{selected_layer}; my $under_position = exists($self->{under_position}) ? $self->{under_position} : 'static'; my $display = ( $under_position eq 'absolute' ) ? 'visibility = "visible"' : 'display = ""'; < function ${key}visualize() { document.getElementById('${key}d$selected').style.$display; document.getElementById('${key}d$selected').style.zIndex = 1; } END } sub _safeonload { < var gSafeOnload = new Array(); function SafeAddOnLoad(f) { if (window.onload) { if (window.onload != SafeOnload) { gSafeOnload[0] = window.onload; window.onload = SafeOnload; } gSafeOnload[gSafeOnload.length] = f; } else { window.onload = f; } } function SafeOnload() { for (var i=0;i END } =back =head1 AUTHOR Ivan Kohler Eivan-selectlayers@420.amE =head1 COPYRIGHT Copyright (c) 2002-2005 Ivan Kohler All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 BUGS JavaScript All the different form_* options are unnecessary, could use .type to auto-sense Could give you a function or something for copying variables out of the layered forms. =head1 SEE ALSO L. L, http://www.xs4all.nl/~ppk/js/dom.html, http://javascript.about.com/library/scripts/blsafeonload.htm =cut