Annotate a JS Function with 'WebappRestSafe'

Having trouble deploying Oxygen XML Web Author? Got a bug to report? Post it all here.
rohan_12
Posts: 6
Joined: Wed May 08, 2024 7:19 am

Annotate a JS Function with 'WebappRestSafe'

Post 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
safe.JPG (30.17 KiB) Viewed 170 times
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.
cosminef
Site Admin
Posts: 197
Joined: Wed Aug 30, 2023 2:33 pm

Re: Annotate a JS Function with 'WebappRestSafe'

Post 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
Cosmin Eftenie
www.oxygenxml.com
Post Reply