Home Forums General XMetaL Discussion Moving Rows and Columns for CALS Table Reply To: Moving Rows and Columns for CALS Table

Derek Read

Reply to: Moving Rows and Columns for CALS Table

The user's selection is most likely going to be inside an entry or one of its children (if allowed by your DTD — most DTD define paragraph-like and formatting-like elements for use inside entry, such as , , etc). You need to check if the current row has a row before it. I think something similar to the following may be close to what you are looking for:

[code]//XMetaL Script Language JScript:
//Assumptions:
//   We are working with CALS tables that use lowercase element names.
//   The document is valid.

var rng = ActiveDocument.Range;
//Check if we're in a table cell:
if(rng.InContextOfType(“tablecell”)) {
var nd = rng.ContainerNode;
var emergencyBreak = 0;
//If we're not already in a row then move to a parent that is:
while(nd.nodeName != “row”) {
nd = nd.parentNode;
emergencyBreak++;
if(emergencyBreak > 20) {
//Something has probably gone wrong.
//”emergencyBreak” is my way of saying I threw this code together but YOU need to test it.
//Once all potential cases are handled properly this is probably not necessary.
break;
}
}
//Check if the row has a row before it:
var prevSibling = nd.previousSibling;
if(prevSibling) {
//The following check may be redundant:
if (prevSibling.nodeName == “row”) {
//…your code for enabling / disabling stuff goes here…
Application.Alert(“has row before…”);
}
}
//Check if the row has a row before it:
var nextSibling = nd.nextSibling;
if(nextSibling) {
//The following check may be redundant:
if (nextSibling.nodeName == “row”) {
//…your code for enabling / disabling stuff goes here…
Application.Alert(“has row after…”);
}
}
}[/code]

You would need to have similar code to check for “columns”. In that case check to see if the current entry has a previousSibling.

Reply

Products
Downloads
Support