Example: Using Layout Objects - Adobe GoLive CS2 Programmer's Manual

Hide thumbs Also See for GoLive CS2:
Table of Contents

Advertisement

SDK Programmer's Guide
The width value in the table layout object's Inspector window displays the new value.
You can undo and redo this action in the History window.
Even in a managed element, not all attributes are managed in this way. The setAttribute method
works only on the elements and attributes listed in
SDK Programmer's Reference.
For example, the <spacer> element is listed as a managed tag, the name attribute is not listed as a
managed attribute. If you insert a horizontal spacer ( <spacer> ) element in a new document and then
select it in Layout view, the following JavaScript expression would return an Unknown attribute name
error:
document.selection.element.layout.setAttribute( "name", "Mr. Perry" )
Use the hasAttribute method to determine whether an attribute can be set successfully from the
layout object. For example, when the <spacer> element is selected in Layout view, this method returns
false :
document.selection.element.layout.hasAttribute("name")
You can also use the hasAttribute method to confirm the existence of unusually named attributes that
are difficult to access by the usual means; for instance, if their names do not follow JavaScript naming
conventions. You can use the getAttribute method to retrieve the values of such attributes.

Example: Using layout objects

This example gets the tableCell objects from a table's layout object, and calls methods of the table
cell's textArea object to add an image as each cell's content. It then uses the layout object for the newly
created image elements to modify attributes of the images.
// get path to images
var path = folderGetDialog( "Image folder" );
if( path != null )
{
// get all files with given filename extension
var files = path.getFiles( "*." + ext );
if( files.length > 0 )
{
for( c=0; c<files.length; c++ )
{
// insert a placeholder image element in each cell
var cellTextArea = table.cell[c].textArea;
var source = "<a href=\"#image" + c;
source += "\"><img src=\"(EmptyReference!)\"";
source += "alt = \"placeholder alt text\" ></a>";
cellTextArea.insertHTML(source);
}
// set attributes of the newly created <img> elements
for( i=0; i<files.length; i++ )
{
// set the src path
var img = doc.documentElement.getSubElement( "img", i );
img.layout.setAttribute( "src", files[i].url );
// set absolute width/height
img.layout.setAttribute( "widthmode", "pixel" );
img.layout.setAttribute( "heightmode", "pixel" );
Adobe GoLive CS2 SDK
Appendix C, "Managed Layout
Editing with Layout
110
Tags, " in the GoLive CS

Advertisement

Table of Contents
loading

Table of Contents