Information Classification: External Restricted.
See https://www.chili-publish.com/security

Accessing selected frames and other resources

Selections

Various objects within the document's object model are selectable lists. The items within such a list (a Layer, Frame, Color, ...) inherit from Document Object model - DocumentListItemSelectableBase

Those lists allow you to loop through the items, and check which one is selected (through the item's "selected" property). Most however also have a read-only property on the document itself, such as: "document.selectedFrame", "document.selectedLayer", etc.).

Frames

The selected frame can be retrieved using the "document.selectedFrame" object descriptor. This only applies to a text selected using the pointer, though. Text selection is separately stored in the "document.selectedText" object, which holds a reference to its frame:

function GetSelectedFrame()
{
   var selectedFrame;
   selectedFrame = editor.GetObject("document.selectedText.frame")
   if (selectedFrame == null)
     selectedFrame = editor.GetObject("document.selectedFrame")

   //might still be null, if no frame or text was selected:
   return selectedFrame;
 }

To be notified of changes in the selection, you can register to events within the Editor (eg: SelectedFrameChanged or SelectedTextChanged).

If multiple frames are selected by the user inside the editor, the same events are triggered, and "document.selectedFrame" contains the first frame. To loop through multiple selected frames, you can use:

var numFrames = editor.GetObject("document.selectedFrames").length;

for (var a=0;a<numFrames;a++)
{
   var frame = editor.ExecuteFunction("document.selectedFrames","GetItemAt",a);
   var frameID = frame.id;
   //DO MAGIC
}

Other Resources

Other useful object descriptors include:

  • document.selectedPage
  • document.selectedLayer
  • document.selectedAlternateLayout

External Resource Panels

Most events and objects within the document's DOM pertain to the document itself (or its viewPreferences). For external resources, however, a special callback has been added. This pertains to the External Assets and External Snippets panels. When the user selects an item within those panels (fed to it by your XML feeds), CHILI will check if a callback function is available in the containing page, and trigger it with the relevant information on the new selection.

To handle this change, you can add the following function to your own HTML page, containing the Editor iframe:

function ExternalResourceSelected(resource,panel,dirID,id,itemXmlString)
 {
     var txt = "";
     // resource = "Assets" or "Snippets"
     txt += "Resource = " + resource + "\n";
     // panel = title of the Panel triggering the change
     txt += "Panel = " + panel + "\n";
     // dirID = the ID of the currently selected directory within the panel's tree list (as provided in your XML)
     txt += "Dir. ID = " + dirID + "\n";
     // id = the ID of the selected item (as provided in your XML)
     txt += "ID = " + id + "\n";
     // itemXmlString: the full XML (as a string) of the selected item, as provided in your XML
     txt += "XML = " + itemXmlString + "\n";

     alert(txt);
 }

All information on this page must be treated as External Restricted, or more strict. https://www.chili-publish.com/security