Skip Menu |

This queue is for tickets about the XUL-Node CPAN distribution.

Report information
The Basics
Id: 25199
Status: new
Priority: 0/
Queue: XUL-Node

People
Owner: Nobody in particular
Requestors: perl [...] pied.nu
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 0.05
Fixed in: (no value)



Subject: Suport for Javascript and better textNode
This patch adds support for a Script() tag. The entire content of the tag is assumed to be javascript, and when sent to the client is eval()ed. Script( "alert( 'hello world' )" ); It also improves textNode handling. In 0.05, if one replaces a text node from the server ($node->set_attribute( textNode => "Something else" ); ) would cause the new text to be appended to the current text. New behaviour is to search all child nodes looking for a previous textNode, and replace it with a new one. If no previous textNode, a new one is created and appended.
Subject: Philip_Gwyn-XUL-javascript_textnode.patch
diff -rub XUL-Node-0.05/lib/XUL/Node.pm XUL-Node-0.05.PG/lib/XUL/Node.pm --- XUL-Node-0.05/lib/XUL/Node.pm 2004-08-06 02:36:17.000000000 -0400 +++ XUL-Node-0.05.PG/lib/XUL/Node.pm 2007-02-27 19:14:45.000000000 -0500 @@ -17,6 +17,10 @@ MenuBar Menu MenuSeparator StatusBarPanel StatusBar ); +my @OTHER_ELEMENTS = qw( + Script +); + # creating -------------------------------------------------------------------- my %XUL_ELEMENTS = map { $_ => 1 } @XUL_ELEMENTS; @@ -33,6 +37,10 @@ # export the xul element constants foreach my $constant_name (@XUL::Node::Constants::EXPORT) { *{"${package}::$constant_name"} = *{"$constant_name"} } + foreach my $other (@OTHER_ELEMENTS) { + *{"${package}::$other"} = sub + { my $scalar_context = $class->can("$other")->( $class, @_ ) }; + } } sub new { @@ -51,6 +59,13 @@ return $self; } +sub Script { + my $class = shift; + # warn "class=$class"; + # warn "script=", join "\n", @_; + return $class->new( tag=>'script', javascript => join "\n", @_ ); +} + # attribute handling ---------------------------------------------------------- sub attributes { wantarray? %{shift->{attributes}}: shift->{attributes} } diff -rub XUL-Node-0.05/xul-node/xul/jslib/Client/Runner.js XUL-Node-0.05.PG/xul-node/xul/jslib/Client/Runner.js --- XUL-Node-0.05/xul-node/xul/jslib/Client/Runner.js 2004-07-12 17:42:28.000000000 -0400 +++ XUL-Node-0.05.PG/xul-node/xul/jslib/Client/Runner.js 2007-02-27 20:15:05.000000000 -0500 @@ -85,7 +85,11 @@ if (!element) element = this.getNode(nodeId); if (key == 'textNode') { - element.appendChild(this.document.createTextNode(value)); + this.commandSetTextNode( element, nodeId, value ); + return; + } + if (key == 'javascript') { + this.commandSetJavascript( element, nodeId, value ); return; } if (Client_Runner.boleanAttributes[key]) { @@ -118,6 +122,33 @@ ); }} + +_.commandSetTextNode = function ( element, nodeId, value ) { + + var textNode = this.document.createTextNode(value); + element.appendChild( textNode ); + return; + + for ( var q=0 ; q < element.childNodes.length ; q++ ) { + var child = element.childNodes[ q ]; + // HTML nodes might need .tagName + if( child.nodeName == '#text' ) { + element.replaceChild( textNode, child ); + return; + } + } + +} + +_.commandSetJavascript = function ( element, nodeId, value ) { + try { + eval( value ); + } catch( e ) { + Throw(e, 'Cannot evaluate javascript: [' + nodeId + '=' + value + ']' + ); + } +} + _.commandByeElement = function (nodeId) { var node = this.getNode(nodeId); node.parentNode.removeChild(node);