Solstice::Button::PopUp - Open a new browser window and launch an initial state in it.


Solstice documentation Contained in the Solstice distribution.

Index


Code Index:

NAME

Top

Solstice::Button::PopUp - Open a new browser window and launch an initial state in it.

SYNOPSIS

Top

  use Solstice::Button:PopUp;

  See L<Solstice::Button|Solstice::Button> for usage.

DESCRIPTION

Top

ee Solstice::Button for description.

Superclass

Solstice::Button

Export

No symbols exported.

Methods

getButton()

Returns HTML for a text link.

Returns HTML for an image link.

Return HTML for a combination image/text link.

getPseudoButton()
getPopupAttributes()

Private Methods

_getAccessorDefinition()

Modules Used

Solstice::Button, StringLibrary (StringLibrary).

AUTHOR

Top

Catalyst Group, <catalyst@u.washington.edu>

VERSION

Top

$Revision: 3002 $

COPYRIGHT

Top


Solstice documentation Contained in the Solstice distribution.
package Solstice::Button::PopUp;

# $Id: PopUp.pm 3002 2006-01-24 22:57:29Z jdr99 $

use 5.006_000;
use strict;
use warnings;

use base qw(Solstice::Button);

use constant TRUE  => 1;
use constant FALSE => 0;

use constant DEFAULT_WINDOW_NAME   => 'solsticePopupWindow';
use constant DEFAULT_WINDOW_WIDTH  => 680;
use constant DEFAULT_WINDOW_HEIGHT => 700;
use constant MAX_WINDOW_SIZE       => 800;

our ($VERSION) = ('$Revision: 3002 $' =~ /^\$Revision:\s*([\d.]*)/);

sub getButton {
    my $self = shift;

    return $self->SUPER::getButton() if $self->{'_disabled'};
    return $self->getNoscriptButton() unless $self->{'_has_javascript'};

    my $name       = $self->{'_name'} || '';
    my $label      = $self->_generateLabel(); 
    my $title      = $self->_generateTitle(); 
    my $tooltip    = $self->_generateTooltip();
    my $tabindex = defined $self->{'_tabindex'} ? $self->{'_tabindex'} : 0;
    my $url        = $self->{'_popup_url'} || '';
    my $attributes = $self->getPopupAttributes() || ''; 
    my $window     = $self->{'_popup_name'} || DEFAULT_WINDOW_NAME;
    my $script     = $self->_generateInlineScript();

    if (defined $tooltip) {
        $self->getOnloadService()->addEvent("Solstice.addToolTip('btn_$name', '$tooltip')");
    }

    return qq|<input id="btn_$name" type="button" name="$name" value="$label" tabindex="$tabindex" onclick="Solstice.Button.newWindowSubmit('$name', '$url', '$attributes', '$window');"/>$script|;
}

sub getTextLink {
    my $self = shift;

    return $self->SUPER::getTextLink() if $self->{'_disabled'};
    return $self->getNoscriptButton() unless $self->{'_has_javascript'};
    
    my $name       = $self->{'_name'} || '';
    my $label      = $self->_generateLabel(); 
    my $tooltip    = $self->_generateTooltip();
    my $title      = $self->_generateTitle(); 
    my $jstitle    = $self->_generateScriptTitle();
    my $tabindex = defined $self->{'_tabindex'} ? $self->{'_tabindex'} : 0;
    my $url        = $self->{'_popup_url'} || '';
    my $attributes = $self->getPopupAttributes() || '';
    my $window     = $self->{'_popup_name'} || DEFAULT_WINDOW_NAME;
    my $script     = $self->_generateInlineScript();

    if (defined $tooltip) {
        $self->getOnloadService()->addEvent("Solstice.addToolTip('link_$name', '$tooltip')");
    }

    return qq|<a id="link_$name" href="javascript:void(Solstice.Button.newWindowSubmit('$name', '$url', '$attributes', '$window'));" title="$title" tabindex="$tabindex" onmouseover="window.status='$jstitle'; return true;" onmouseout="window.status=''; return true;">$label</a>$script|;
}

sub getImageLink {
    my $self = shift;

    return $self->SUPER::getImageLink() if $self->{'_disabled'};
    return $self->getNoscriptImage() unless $self->{'_has_javascript'};
    
    my $name       = $self->{'_name'}  || '';
    my $tooltip    = $self->_generateTooltip();
    my $title      = $self->_generateTitle(); 
    my $jstitle    = $self->_generateScriptTitle(); 
    my $tabindex = defined $self->{'_tabindex'} ? $self->{'_tabindex'} : 0;
    my $image      = $self->{'_image'} || '';
    my $alt        = $self->{'_title'}  || '';
    my $url        = $self->{'_popup_url'} || '';
    my $attributes = $self->getPopupAttributes() || '';
    my $window     = $self->{'_popup_name'} || DEFAULT_WINDOW_NAME;
    my $script     = $self->_generateInlineScript();

    if (defined $tooltip) {
        $self->getOnloadService()->addEvent("Solstice.addToolTip('img_$name', '$tooltip')");
    }

    return qq|<a id="img_$name" href="javascript:void(Solstice.Button.newWindowSubmit('$name', '$url', '$attributes', '$window'));" tabindex="$tabindex" title="$title" onmouseover="window.status='$jstitle'; return true;" onmouseout="window.status=''; return true;"><img src="$image" alt=""/></a>$script|;
}

sub getImageTextLink {
    my $self = shift;
    
    return $self->SUPER::getImageTextLink() if $self->{'_disabled'};
    unless ($self->{'_has_javascript'}) {
        return ($self->getNoscriptImage().' '.$self->getNoscriptButton());
    }
    
    my $name       = $self->{'_name'}  || '';
    my $label      = $self->_generateLabel();
    my $tooltip    = $self->_generateTooltip();
    my $title      = $self->_generateTitle(); 
    my $jstitle    = $self->_generateScriptTitle(); 
    my $tabindex = defined $self->{'_tabindex'} ? $self->{'_tabindex'} : 0;
    my $image      = $self->{'_image'} || '';
    my $url        = $self->{'_popup_url'} || '';
    my $attributes = $self->getPopupAttributes() || '';
    my $window     = $self->{'_popup_name'} || DEFAULT_WINDOW_NAME;
    my $script     = $self->_generateInlineScript();

    if (defined $tooltip) {
        $self->getOnloadService()->addEvent("Solstice.addToolTip('img_$name', '$tooltip')");
        $self->getOnloadService()->addEvent("Solstice.addToolTip('link_$name', '$tooltip')");
    }
    return qq|<a id="img_$name" href="javascript:void(Solstice.Button.newWindowSubmit('$name', '$url', '$attributes', '$window'));" title="$title" onmouseover="window.status='$jstitle'; return true;" onmouseout="window.status=''; return true;"><img src="$image" alt=""/></a> <a id="link_$name" href="javascript:void(Solstice.Button.newWindowSubmit('$name', '$url', '$attributes', '$window'));" title="$title" tabindex="$tabindex" onmouseover="window.status='$jstitle'; return true;" onmouseout="window.status=''; return true;">$label</a>$script|;
}

sub getPseudoButton {
    my $self = shift;

    return $self->SUPER::getPseudoButton() if $self->{'_disabled'};
    return $self->getNoscriptButton() unless $self->{'_has_javascript'};
    
    my $name       = $self->{'_name'}  || '';
    my $label      = $self->_generateLabel(); 
    my $title      = $self->_generateTitle();
    my $tooltip    = $self->_generateTooltip();
    my $image      = $self->{'_image'} ? ('<img src="'.$self->{'_image'}.'" alt=""/> ') : '';
    my $url        = $self->{'_popup_url'} || '';
    my $tabindex = defined $self->{'_tabindex'} ? $self->{'_tabindex'} : 0;
    my $attributes = $self->getPopupAttributes() || '';
    my $window     = $self->{'_popup_name'} || DEFAULT_WINDOW_NAME; 
    my $script     = $self->_generateInlineScript();

    if (defined $tooltip) {
        $self->getOnloadService()->addEvent("Solstice.addToolTip('pseudo_$name', '$tooltip')");
    }

    return qq|<div id="pseudo_$name" title="$title" onmouseover="this.style.cursor='pointer';" onmouseout="this.style.cursor='default';" onclick="void(Solstice.Button.newWindowSubmit('$name', '$url', '$attributes', '$window'));" tabindex="$tabindex" >$image$label</div>$script|;
}

sub getPopupAttributes {
    my $self = shift;

    if (my $file = $self->getPopupFile()) {
        my $width  = $file->getAttribute('width');
        my $height = $file->getAttribute('height');

        if ($width and $height) {
            $width += 20;
            $height += 20;
            if ($height > MAX_WINDOW_SIZE || $width > MAX_WINDOW_SIZE) {
                if ($height > MAX_WINDOW_SIZE) {
                    $width = int($width / $height * MAX_WINDOW_SIZE) || 1;
                    $height = MAX_WINDOW_SIZE;
                } else {
                    $width = MAX_WINDOW_SIZE;
                    $height = int($height / $width * MAX_WINDOW_SIZE) || 1;
                }
            }
        } else {
            $width  = DEFAULT_WINDOW_WIDTH;
            $height = DEFAULT_WINDOW_HEIGHT;
        } 
        
        return ('height='.$height.',width='.$width.',resizable=yes,scrollbars=yes,status=no,toolbar=no,menubar=no');
    }
    return $self->_getPopupAttributes();
}

sub _getAccessorDefinition {
    return [
        {
            name => 'PopupURL',
            key  => '_popup_url',
            type => 'String',
        },
        {
            name => 'PopupName',
            key  => '_popup_name',
            type => 'String',
        },
        {
            name => 'PopupAttributes',
            key  => '_popup_attributes',
            type => 'String',
            private_get => TRUE,
        },
        {
            name => 'PopupFile',
            key  => '_popup_file',
            #TODO: Accept all Solstice::Resource::File subclasses
            type => 'Solstice::Resource::File::BlackBox',
        },
    ];
}


1;
__END__