Another problem is inherent in inspecting translated content. When you call the
dom.getSelection()
untranslated source. To expand the selection properly so that the locked region (and only the
locked region) is selected, use the following technique:
var currentDOM = dw.getDocumentDOM();
var offsets = currentDOM.getSelection();
var theSelection = currentDOM.offsetsToNode(offsets[0],offsets[0]+1);
Using
offsets[0]+1
lock tag when you convert the offsets to a node. If you use
argument, you risk selecting the node above the lock.
After you make the selection (after ensuring that its
can inspect the
type
shown in the following example:
if (theSelection.nodeType == node.ELEMENT_NODE && ¬
theSelection.getAttribute('type') == 'happy'){
return true;
}else{
return false
}
To populate the text boxes in the Property inspector for the translated tag, you must parse the
value of the
attribute. For example, if the untranslated code is
orig
the Property inspector has a Time text box, you must extract the value of the
from the
string:
orig
function inspectSelection() {
var currentDOM = dw.getDocumentDOM();
var currSelection = currentDOM.getSelection();
var theObj = currentDOM.offsetsToNode¬
(curSelection[0],curSelection[0]+1);
if (theObj.nodeType != Node.ELEMENT_NODE) {
return;
}
// To convert the encoded characters back to their
// original values, use the unescape() method.
var origAtt = unescape(theObj.getAttribute("ORIG"));
// Convert the string to lowercase for processing
var origAttLC = origAtt.toLowerCase();
var timeStart = origAttLC.indexOf('time="');
var timeEnd = origAttLC.indexOf('"',timeStart+6);
var timeValue = origAtt.substring(timeStart+6,timeEnd);
440
Data Translators
function, the values that return by default are offsets into the
as the second argument ensures that you remain within the opening
attribute to see if the locked region matches this Property inspector, as
as the second
offsets[1]
is
nodeType
node.ELEMENT_NODE
<HAPPY TIME="22">
), you
and
attribute
TIME
Need help?
Do you have a question about the DREAMWEAVER 8-EXTENDING DREAMWEAVER and is the answer not in the manual?