POE-XUL

 view release on metacpan or  search on metacpan

javascript/src/Runner.js  view on Meta::CPAN

    }
    else if( methodName == 'method' ) {
        this.commandMethod(nodeId, arg1, arg2);
    }
    else if( methodName == 'javascript' ) {
        this.commandJavascript( arg1 );
    }
    else if( methodName == 'ERROR' ) {
        $application.crash( arg1 );
    }
    else if( methodName == 'cdata' ) {
        this.commandCDATA( nodeId, arg1, arg2 );
    }
    else if( methodName == 'style' ) {
        this.commandStyle( nodeId, arg1, arg2 );
    }
    else if( methodName == 'popup_window' ) {
        this.commandPopupWindow( nodeId, arg1 );
    }
    else if( methodName == 'close_window' ) {
        this.commandCloseWindow( nodeId );

javascript/src/Runner.js  view on Meta::CPAN

        Throw(e,
            'Cannot create new node : [' + nodeId +
            ', ' + tagName + ', ' + parentId + ']'
        );
    }
}

// ------------------------------------------------------------------
_.commandCDATA = function ( nodeId, index, data ) { 
    try {
        var cdata = this.document.createCDATASection( data );

        var element = this.newNodes[nodeId];
        if (!element) element = this.getNode(nodeId);

        this.addElement( element, cdata, index );

        if( element.nodeName == 'script' &&
                element.getAttribute( 'type' ) == 'text/javascript' ) {
            this.lateCommands.push( { methodName: 'javascript', 
                                      nodeId: nodeId, 
                                      arg1: data 
                                  } );
        }
    } catch (e) {
        Throw(e,

lib/POE/XUL/CDATA.pm  view on Meta::CPAN

}

################################################################
sub is_window { 0 }

################################################################
sub update_CM
{
    my( $self ) = @_;
    return unless $POE::XUL::Node::CM;
    $POE::XUL::Node::CM->after_cdata_change( $self );
}


################################################################
sub nodeValue
{
    my( $self, $value ) = @_;
    
    if( 2==@_ ) {
        $_[0]->{data} = $value;

lib/POE/XUL/CDATA.pm  view on Meta::CPAN


=head1 NAME

POE::XUL::CDATA - XUL CDATA

=head1 SYNOPSIS

    use POE::XUL::Node;
    use POE::XUL::CDATA;

    my $cdata = POE::XUL::CDATA->new( $raw_data );
    $node->appendChild( $cdata );

    Script( <<JS );
        function something() {
            // JS code here
        }
    JS

=head1 DESCRIPTION

POE::XUL::CDATA instances is are DOM-like object for holding and

lib/POE/XUL/CDATA.pm  view on Meta::CPAN

=head1 METHODS

While POE::XUL::CDATA offers the full DOM interface, the ChangeManager will
transmit data at each update.  This means that if you modify the data more
then once during an event, the data will be sent multiple times in the
response and C<eval()>ed multiple times if it the child of a Script node. 
This may or may not be what you want.
 
=head2 nodeValue

    $cdata->nodeValue( $raw_data );
    $data = $cdata->nodeValue;

=head2 appendData

    $cdata->appendData( $more_js );

=head2 deleteData

    $cdata->deleteData( $offset, $count );

=head2 insertData

    $cdata->insertData( $offset, $more_data );

=head2 replaceData

    $cdata->insertData( $offset, $count, $more_data );

=head2 substringData

    my $data = $cdata->substringData( $offset, $count );

=head2 as_xml

    my $xml = $cdata->as_xml;

=head2 children

Returns an empty array.

=head2 dispose

Does nothing.


lib/POE/XUL/ChangeManager.pm  view on Meta::CPAN

    $child_state->is_destroyed( $parent, $index );
    push @{$self->{destroyed}}, $child_state;

    delete $self->{states}{ "$child" };
    delete $self->{states}{ $child_state->{style} }
                            if $child_state->{style};
    $self->unregister_node( $child_state->{id}, $child );
}

##############################################################
sub after_cdata_change
{
    my( $self, $node ) = @_;
    my $state = $self->node_state( $node );
    $state->{cdata} = $node->{data};
    $state->{is_new} = 1;
}



##############################################################
# So that we can detect changes between requests
sub request_start
{
    my( $self, $event ) = @_;

lib/POE/XUL/Node.pm  view on Meta::CPAN

        }
	}
    return ( $id, @out );
}

##############################################################
sub Script {
    my $class = shift;
    # warn "class=$class";
    # warn "script=", join "\n", @_;
    my $cdata = POE::XUL::CDATA->new( join "\n", @_ );
    return $class->new( tag=>'script', type=>'text/javascript', $cdata );
}

##############################################################
# Boot message
sub Boot
{
    my( $class, $msg ) = @_;
    if( $CM ) {
        $CM->Boot( $msg );
    }

lib/POE/XUL/State.pm  view on Meta::CPAN


    # TODO: this is probably a bad idea
	return if $is_new && $is_destroyed;

    if( $is_destroyed ) {
        return $self->get_buffer_as_commands;
    }
    elsif( $self->is_textnode ) {
        return $self->make_command_textnode;
    }
    elsif( $self->{cdata} ) {
    	return unless $self->{is_new};
        return $self->make_command_cdata;
    }
    else {
        return $self->make_command_new, $self->get_buffer_as_commands;
    }
}

sub as_deferred_command {
	my $self = shift;

	my $is_new       = $self->{is_new};

lib/POE/XUL/State.pm  view on Meta::CPAN

}

##############################################################
sub make_command_textnode_bye 
{
	my( $self, $parent_id, $index ) = @_;
    return [ 'bye-textnode', $parent_id, $index ];
}

##############################################################
sub make_command_cdata
{
	my( $self ) = @_;
    # use Data::Dumper;
    # warn Dumper $self->{buffer};
    my $ret = [ 'cdata',
                $self->get_parent_id, 
                $self->{index},
                $self->{cdata}
              ];
    return $ret;
}

##############################################################
sub make_command_cdata_bye 
{
	my( $self, $parent_id, $index ) = @_;
    return [ 'bye-cdata', $parent_id, $index ];
}


##############################################################
sub make_command_SID
{
    my( $package, $SID ) = @_;
    return [ 'SID', $SID ];
}

t/20_changemanager.t  view on Meta::CPAN


##############################
# Test script and CDATA
my $JS = "this is some JS";
$W->appendChild( Script( $JS ) );
$buffer = $CM->flush;

is_deeply( $buffer, [[ 'for', '' ],
                     [ 'new', "PXN5", 'script', 'top', 0 ],
                     [ 'set', "PXN5", 'type', 'text/javascript' ],
                     [ 'cdata', 'PXN5', 0, $JS ]
                    ],  "Javascript + CDATA" )
    or die Dumper $buffer;

## Change the CDATA
my $cdata = $W->firstChild->firstChild;
$JS = "Different JS";
# replaceData
$cdata->replaceData( 0, 100, $JS );
$buffer = $CM->flush;

is_deeply( $buffer, [[ 'for', '' ],
                     [ 'cdata', 'PXN5', 0, $JS ]
                    ],  "Changed CDATA" )
    or die Dumper $buffer;

# insertData
$cdata->insertData( 0, "Yet again " );
$buffer = $CM->flush;

is_deeply( $buffer, [[ 'for', '' ],
                     [ 'cdata', 'PXN5', 0, "Yet again Different JS" ]
                    ],  "Changed CDATA" )
    or die Dumper $buffer;

# appendData
$cdata->appendData( " man" );
$buffer = $CM->flush;

is_deeply( $buffer, [[ 'for', '' ],
                     [ 'cdata', 'PXN5', 0, "Yet again Different JS man" ]
                    ],  "Changed CDATA" )
    or die Dumper $buffer;

# deleteData
$cdata->deleteData( 0, 10 );
$cdata->deleteData( 12, 4 );
$buffer = $CM->flush;

is_deeply( $buffer, [[ 'for', '' ],
                     [ 'cdata', 'PXN5', 0, "Different JS" ]
                    ],  "Changed CDATA" )
    or die Dumper $buffer;


##############################
$W->appendChild( Label( 'honk' ) );
$buffer = $CM->flush;

is_deeply( $buffer, [[ 'for', '' ], 
                     [ qw( new PXN6 label top 1 ) ], 

t/90_complete.t  view on Meta::CPAN

ok( $AB, "Found the alert-button" ) 
        or die "I really need that button";

$resp = Click( $browser, $AB );
$data = $browser->decode_resp( $resp, 'click alert-button' );
$browser->handle_resp( $data, 'click alert-button' );

my $JS = $browser->{W}->{zC}[-1];
ok( ($JS and $JS->{type} eq 'text/javascript'), "Found the javascript" ) 
        or die "I really need that javascript";
my $code = delete $JS->{zC}[0]{cdata};
ok( ($code =~ /alert/), "Got the javascript" )
        or die $JS;

############################################################
# Test menulist
my $ML = $browser->get_node( 'ML1' );
ok( $ML, "Got the menulist" );

die Dumper $ML unless $ML->{zC};

t/90_complete.t  view on Meta::CPAN

}

#########


$JS = $browser->{W}->{zC}[-1];
ok( $JS, "Found the javascript" ) 
        or die "I really need that javascript";
is( $JS->{type}, 'text/javascript', "Found the javascript" ) 
        or die Dumper $JS;
$code = $JS->{zC}[0]{cdata};
ok( !$code, "Didn't get more javascript" )
        or die Dumper $JS;



############################################################
# Test listbox
my $SB = $browser->get_node( 'SB1' );
ok( $SB, "Got the listbox" );

t/Client.pm  view on Meta::CPAN

            my $tn = $parent->[ $args[0] ];
            if( $tn and $tn->{tag} eq 'textnode' ) {
                $tn->{nodeValue} = $args[1];
            }
            else {
                $parent->[ $args[0] ] =
                    { tag=>'textnode', nodeValue=>$args[1] };
            }
        }
    }
    elsif( $op eq 'cdata' ) {
        ok( defined( $args[1] ), "Got a cdata $id" );
        ok( $self->{NODES}->{$id}, " ... and we have its parent ($id)" );
        my $parent = $self->{NODES}->{$id}{zC};
        ok( ( $args[0] <= @{$parent} ), " ... and this isn't way out there" );
        if( $args[0] < 0 ) {
            push @$parent, { tag=>'cdata', cdata=>$args[1] };
        }
        else {
            my $tn = $parent->[ $args[0] ];
            if( $tn and $tn->{tag} eq 'cdata' ) {
                $tn->{nodeValue} = $args[1];
            }
            else {
                $parent->[ $args[0] ] =
                    { tag=>'cdata', cdata=>$args[1] };
            }
        }
    }
    elsif( $op eq 'new' ) {
        ok( ! $self->{NODES}->{$id}, "New node $id" );
        ok( $args[0], " ... with a tag type" );
        my $new = $self->{NODES}->{$id} = 
                    { tag => $args[0], id=>$id, zC=>[] };
        if( $args[1] ) {
            my $parent = $self->{NODES}->{$args[1]};

t/Client.pm  view on Meta::CPAN

         die "What do i do with op=$op";
    }
}

######################################################
sub find_parent
{
    my( $self, $node ) = @_;
    return unless defined $node;
    foreach my $N ( values %{$self->{NODES}} ) {
        next if $N->{tag} eq 'textnode' or $N->{tag} eq 'cdata';
        use Data::Dumper;
        die Dumper $N unless $N->{zC};
        for( my $q1=0; $q1 < @{ $N->{zC} }; $q1++ ) {
            unless( defined $N->{zC}[ $q1 ] ) {
                # die "$q1=", Dumper $N->{zC};
                next;
            }
            next unless $N->{zC}[$q1] == $node;
            return $N, $q1 if wantarray;
            return $N;

t/Client.pm  view on Meta::CPAN


######################################################
sub drop_node
{
    my( $self, $node ) = @_;
    if( $node->{id} ) {
        delete $self->{NODES}->{ $node->{id} };
        $self->{deleted}{ $node->{id} } = 1;
    }

    return if not $node->{tag} or $node->{tag} eq 'textnode' or $node->{tag} eq 'cdata';
    foreach my $C ( @{ $node->{zC} } ) {
        $self->drop_node( $C );
    }
    $node->{zC} = [];
}

######################################################
sub root_uri
{
    my( $self ) = @_;



( run in 0.592 second using v1.01-cache-2.11-cpan-454fe037f31 )