Adobe Extending Dreamweaver CS4 User Manual
Page 340

334
EXTENDING DREAMWEAVER CS4
Data translators
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
orig
attribute. For example, if the untranslated code is
and the Property inspector has a Time text
box, you must extract the value of the
TIME
attribute from the
orig
string:
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);
document.layers['timelayer'].document.timeForm.timefield.value = timeValue;
}
After you parse the
orig
attribute to populate the boxes in the Property inspector for the translated tag, the next
step is probably to set the value of the
orig
attribute if the user changes the value in any of the text boxes. You might
find restrictions against making changes in a locked region. You can avoid this problem by changing the original
markup and retranslating.
The Property inspector for translated server-side includes (the ssi_translated.js file in the Configuration/Inspectors
folder) demonstrates this technique in its
setComment()
function. Rather than rewriting the
orig
attribute, the
Property inspector assembles a new server-side include comment. It inserts that comment into the document,
replacing the old one by rewriting the contents of the document, which generates a new
orig
attribute. The
following code summarizes this technique: