POE-XUL
view release on metacpan or search on metacpan
javascript/src/Runner.js view on Meta::CPAN
$application.exception( "JAVASCRIPT", EXs );
}
// commands -------------------------------------------------------------------
// Run one command.
// Returning 1 means we want to give up a timeslice
_.runCommand = function (command) {
var methodName = command['methodName'];
var nodeId = command['nodeId'];
var arg1 = command['arg1'];
var arg2 = command['arg2'];
var arg3 = command['arg3'];
var rv = 0;
if (methodName == 'new') {
if (arg1 == 'window')
this.commandNewWindow(nodeId);
else
this.commandNewElement(nodeId, arg1, arg2, arg3);
}
else if (methodName == 'textnode' ) {
this.commandNewTextNode( nodeId, arg1, arg2 );
}
else if (methodName == 'SID') {
$application.setSID( nodeId );
}
else if (methodName == 'boot') {
if( $status )
$status.title( nodeId );
this.booting = true;
rv = 1;
}
else if ( methodName == 'bye' ) {
this.commandByeElement(nodeId);
}
else if ( methodName == 'bye-textnode' ) {
this.commandByeTextNode( nodeId , arg1 );
}
else if( methodName == 'set' ) {
if ( !this.late && ( POEXUL_Runner.lateAttributes[arg1] ||
this.isLateCommand( command ) ) ) {
// fb_log( 'late = ' + nodeId + "." + arg1 + "=" + arg2 );
this.lateCommands.push(command);
}
else {
rv = this.commandSetNode(nodeId, arg1, arg2);
}
}
else if( methodName == 'remove' ) {
this.commandRemoveAttribute(nodeId, arg1);
}
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 );
}
else if( methodName == 'timeslice' ) {
// fb_log( methodName );
rv = 2;
}
else if( window.name ) {
fb_log( window.name + ": Unknown command '" + methodName + "'" );
}
else {
fb_log( "Unknown command '" + methodName + "'" );
}
return rv;
}
// ------------------------------------------------------------------
_.isLateCommand = function ( command ) {
var nodeId = command['nodeId'];
var key = command['arg1'];
var element = this.newNodes[nodeId];
if (!element) element = this.getNode(nodeId, 1);
if (!element) return true;
if( key == 'textNode' && element.nodeName == 'script' ) {
return true;
}
if( key == 'value' && element.nodeName == 'search-list' ) {
// fb_log( 'late value=' + command['arg2'] );
return true;
}
return false;
}
// ------------------------------------------------------------------
_.commandNewWindow = function (nodeId) {
this.windowId = nodeId;
}
// ------------------------------------------------------------------
_.commandNewElement = function (nodeId, tagName, parentId, index) {
try {
var element = this.createElement(tagName, nodeId);
element.setAttribute('_addAtIndex', index);
this.newNodes[nodeId] = element;
var parent = this.newNodes[parentId];
if (parent)
this.addElementAtIndex(parent, element);
else {
// New elements are added to existing nodes in one batch
// in addNewNodes
if( ! this.newNodeRoots[parentId] )
this.newNodeRoots[parentId] = [];
this.newNodeRoots[parentId].push( element );
}
if (tagName == 'listbox') {
// onselect works but addEventListener( 'select' ) doesn't
element.setAttribute( 'onselect',
'$application.fireEvent_Select(event);' );
//element.addEventListener( 'select',
// function (e) { alert( 'select' );
// $application.fireEvent_Select( e ) }, true );
}
else if (tagName == 'colorpicker') {
element.setAttribute(
'onselect',
'$application.fireEvent_Pick({"targetId":"' +
element.id + '"})'
);
}
} catch (e) {
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,
'Cannot create new CDATA: ' + nodeId +
'[' + index + ']=' + data
);
}
}
// ------------------------------------------------------------------
_.commandStyle = function ( nodeId, property, value ) {
try {
var element = this.newNodes[nodeId];
if (!element) element = this.getNode(nodeId);
//if( property != 'display' || value != 'none' ||
// nodeId == 'XUL-Details' )
// fb_log( nodeId + ".style."+property+"="+value );
element.style[property] = value;
if( property == 'display' && value == 'none' &&
element.tagName == 'groupbox' )
this.clearGroupbox( element );
} catch (e) {
Throw(e,
'Cannot set style ' + nodeId + '.style.' + property +
'=' + value
);
}
}
// ------------------------------------------------------------------
_.commandNewTextNode = function ( nodeId, index, text ) {
try {
var tn = this.document.createTextNode( text );
var element = this.newNodes[nodeId];
if( !element )
element = this.getNode(nodeId);
if( index < 0 ) {
// index = this.firstTextNode( element );
}
// fb_log( "Text node = %i", index );
this.addElement( element, tn, index );
} catch (e) {
Throw(e,
'Cannot create new TextNode: ' + nodeId +
'[' + index + ']=' + text
);
}
}
// find the first textnode child
_.firstTextNode = function ( element ) {
( run in 0.341 second using v1.01-cache-2.11-cpan-0d23b851a93 )