Writing the JavaScript code

You need to add JavaScript functions to make sure you can inspect the selection, to inspect the selection, and to enter the appropriate values in the Property inspector.

To write the JavaScript code:

  1. Create a new blank file.
  2. To specify that the Property inspector appears whenever the selection contains the MARQUEE tag, add the following function:
    function canInspectSelection(){ return true;}
  3. To refresh the value of the direction attribute that appears in the text field, add the following function at the end of the file:
    function inspectSelection(){ // Get the DOM of the current document. var theDOM = dw.getDocumentDOM(); // Get the selected node.  var theObj = theDOM.getSelectedNode(); // Get the value of the DIRECTION attribute on the MARQUEE tag.  var theDirection = theObj.getAttribute('direction'); // Initialize a variable for the DIRECTION attribute to -1.  // This is used to store the menu index that corresponds to // the value of the attribute. // var typeIndex = -1; var directionIndex = -1;  // If there was a DIRECTION attribute... if (theDirection){ // If the value of DIRECTION is "left", set typeIndex to 0. if (theDirection.toLowerCase() == "left"){ directionIndex = 0; // If the value of DIRECTION is "right", set typeIndex to 1. }else if (theDirection.toLowerCase() == "right"){ directionIndex = 1; } } // If the value of the DIRECTION attribute was "left" // or "right", choose the corresponding // option from the pop-up menu in the interface. if (directionIndex != -1){ document.topLayer.document.topLayerForm.marqDirection.selectedIndex =¬ directionIndex; }}
  4. To get the current selection and make the text box in the Property inspector display the direction attribute's value, add the following function at the end of the file:
    function setMarqueeTag(){ // Get the DOM of the current document. var theDOM = dw.getDocumentDOM(); // Get the selected node. var theObj = theDOM.getSelectedNode();  // Get the index of the selected option in the pop-up menu // in the interface. var directionIndex = ¬ document.topLayer.document.topLayerForm.marqDirection.selectedIndex; // Get the value of the selected option in the pop-up menu // in the interface. var theDirection = ¬ document.topLayer.document.topLayerForm.marqDirection.¬ options[directionIndex].value; // Set the value of the direction attribute to theDirection. theObj.setAttribute('direction',theDirection);}
  5. Save the file as marquee.js in the Configuration/Inspectors folder.