User Guide
232 Chapter 13: Floating Panels
The selectionChanged() function for the Script Editor contains the following code:
function selectionChanged(){
/* get the selected node */
var theDOM = dw.getDocumentDOM();
var theNode = theDOM.getSelectedNode();
/* check to see if the node is a script marker */
if (theNode.nodeType == Node.ELEMENT_NODE && ¬
theNode.tagName == "SCRIPT"){
document.layers['scriptlayer'].visibility = 'visible';
document.layers['scriptlayer'].document.theForm.¬
scriptCode.value = theNode.innerHTML;
document.layers['blanklayer'].visibility = 'hidden';
}else{
document.layers['scriptlayer'].visibility = 'hidden';
document.layers['blanklayer'].visibility = 'visible';
}
}
The selectionChanged() function first calls the dw.getDocumentDOM() function to get the
DOM for the user’s document. It then calls the
getSelectedNode() function to see if the
selected node for that document is, first, an element and, second, a
SCRIPT tag. If both these
conditions are true, the
selectionChanged() function makes the scripteditor layer visible
and loads it with the underlying JavaScript code. It also sets the
visibility property of the
blanklayer layer to the value hidden. The following figure shows the scriptlayer floating
panel with the selected JavaScript code: