selectionChanged()
Description
Called when the floating panel becomes visible and when the selection changes (when focus switches to a new document or when the insertion pointer moves to a new location in the current document). This function should be defined only if the floating panel must track the selection.
NOTE | Define |
Arguments
None.
Returns
Adobe Dreamweaver expects nothing.
Example
The following example of selectionChanged() shows a different layer in the floating panel, depending on whether the selection is a script marker. If the selection is a script marker, Adobe Dreamweaver makes the script layer visible. Otherwise, Adobe Dreamweaver makes the blank layer visible.
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['blanklayer'].visibility = 'hidden'; document.layers['scriptlayer'].visibility = 'visible';} else{ document.layers['scriptlayer'].visibility = 'hidden'; document.layers['blanklayer'].visibility = 'visible'; }}About performance
Declaring the selectionChanged() or documentEdited() function in your custom floating panels can impact Adobe Dreamweaver performance adversely. Consider that the documentEdited() and selectionChanged() functions are called after every keystroke and mouse click when Adobe Dreamweaver is idle for more than one-tenth of a second. It's important to use different scenarios to test your floating panel, using large documents (100K or more of HTML) whenever possible, to test performance impact.
To help avoid performance penalties, the setTimeout() function was implemented as a global method in Adobe Dreamweaver 3. As in the browsers, the setTimeout() function takes two arguments: the JavaScript to be called and the amount of time in milliseconds to wait before calling it.
The setTimeout() method lets you build pauses into your processing. These pauses let the user continue interacting with the application. You must build in these pauses explicitly because the screen freezes while scripts process, which prevents the user from performing further edits. The pauses also prevent you from updating the interface or the floating panel.
The following example is from a floating panel that displays information about every layer in the document. It uses the setTimeout() method to pause for a half second after processing each layer.
/* create a flag that specifies whether an edit is being processed, and set it to false. */document.running = false;/* this function called when document is edited */function documentEdited(){ /* create a list of all the layers to be processed */ var dom = dw.getDocumentDOM(); document.layers = dom.getElementsByTagName("layer"); document.numLayers = document.layers.length; document.numProcessed = 0; /* set a timer to call processLayer(); if we didn't get * to finish processing the previous edit, then the timer * is already set. */ if (document.running = false){ setTimeout("processLayer()", 500); } /* set the processing flag to true */ document.running = true;}/* process one layer */function processLayer(){ /* display information for the next unprocessed layer. displayLayer() is a function you would write to perform the "magic". */ displayLayer(document.layers[document.numProcessed]); /* if there's more work to do, set a timeout to process * the next layer. If we're finished, set the document.running * flag to false. */ document.numProcessed = document.numProcessed + 1; if (document.numProcessed < document.numLayers){ setTimeout("processLayer()", 500); }else{ document.running = false; }}