Class JSOperation

  • All Implemented Interfaces:
    AuthorOperation, Extension

    @API(type=INTERNAL,
         src=PUBLIC)
    public class JSOperation
    extends java.lang.Object
    implements AuthorOperation
    An implementation of an operation that allows you to call the Java API from custom JavaScript content. This operation has the following parameters:
    • script: the JavaScript content to execute.

      It must have a function called doOperation(), which can use the predefined authorAccess variable. The authorAccess variable has access to the AuthorAccess instance. The following example is a script that can be used to move the caret location after the current element:

          function doOperation(){ 
            caretOffset = authorAccess.getEditorAccess().getCaretOffset(); 
            currentNode = authorAccess.getDocumentController().getNodeAtOffset(caretOffset); 
            //Move caret after current node 
            authorAccess.getEditorAccess().setCaretPosition(currentNode.getEndOffset() + 1); 
          }
        

    Note: If you have a script called commons.js in the framework directory, you can call functions defined inside it from your custom script content so that you can use that external script file as a library of functions.