Page 1 of 1

Annotate a JS Function with 'WebappRestSafe'

Posted: Fri Nov 08, 2024 9:28 am
by rohan_12
Hi !

I have created a custom action and put it in plugin.js file of my web author plugin.

In my plugin.js file I have a code snippet:

Code: Select all

this.editor.getActionsManager().invokeOperation('ro.sync.ecss.extensions.commons.operations.JSOperation',
                    {
                        script:'common.js'
                        });
My common.js code :

Code: Select all

class GetCurrentId {

    doOperation() {
        var currentNode = authorAccess.getEditorAccess().getFullySelectedNode();
        var currentNodeId= currentNode("id");
        return currentNodeId;
    }
}
I get the error :
Image
safe.JPG
How do I annotate JS code with 'WebappRestSafe' ? I have seen implementations in Java, but I don't know for Javascript.
I have tried couple of approaches but it didn't work.

Re: Annotate a JS Function with 'WebappRestSafe'

Posted: Fri Nov 08, 2024 2:22 pm
by cosminef
Hello,

If you only need to retrieve the id of the fully selected element, I recommend using the sync.api.dom.Element [1] API, which is more streamlined for this purpose. For example, you can use the method sync.api.Selection.getFullySelectedNode() [2] (accessed via sync.api.EditingSupport.getSelectionManager().getSelection()) and then get the id attribute using sync.api.dom.Element.getAttribute("id") [3]

[1] https://www.oxygenxml.com/maven/com/oxy ... ement.html
[2] https://www.oxygenxml.com/maven/com/oxy ... de__anchor
[3] https://www.oxygenxml.com/maven/com/oxy ... te__anchor

Best,
Cosmin