Activation Xpath on JS Customized Action

<oXygen/> general issues.
jacobBocaj
Posts: 12

Activation Xpath on JS Customized Action

Tue Jun 27, 2017 6:06 pm

Hello,

I seem to have lost Activation Xpath functionality for JS (frameworks.js) customized actions. In example, in the .framework file I have an 'insert.image' action with its Activation Xpath property set to oxy:allows-child-element("*:img") - This works as expected, allowing image action in specified locations in both the desktop and WebAuthor environment when unmodified. However, in the WebAuthor environment I needed to customize this action a bit in the js (code below). When I implement this customization I am able to call the inset image action from anywhere within the document - which is not desired behavior. How can I control the Activiation Xpath after the .js customization?

Code: Select all

sync.xhtml.XhtmlExtension.prototype.editorCreated = function(editor) {
  goog.events.listen(editor, sync.api.Editor.EventTypes.ACTIONS_LOADED, function(e) {
    var actionsManager = editor.getActionsManager();
    var originalInsertImageAction = actionsManager.getActionById('insert.image');
   
    if (originalInsertImageAction) {
   
      var insertImageAction = new sync.actions.InsertImage(
        originalInsertImageAction,
        "ATPCustEditorUtils.InsertImgOperationWithUUID",
        editor);
      actionsManager.registerAction('insert.image', insertImageAction);
    } ...
cristi_talau
Posts: 155

Re: Activation Xpath on JS Customized Action

Wed Jun 28, 2017 4:34 pm

Hello,

Unfortunately, this is a limitation of Web Author. Activation XPaths are not taken into account. On the other hand, Web Author has some insertion strategies that try to insert the image in a valid location even if the caret is not in a location that allows an image to be inserted.

As a workaround you could use the JS API to activate/deactivate toolbar actions. I assume here that you can create a whitelist of elements where an image is permitted. Some pointers:
- The action base class, has an

Code: Select all

AbstractAction.isEnabled
method. You can override it. More details here: https://www.oxygenxml.com/maven/com/oxy ... ction.html .
- In order to decide whether the image is allowed, you can first find the selection and then the element at selection:

Code: Select all

editor.getSelectionManager().getSelection()
. More details here: https://www.oxygenxml.com/maven/com/oxy ... ditor.html , https://www.oxygenxml.com/maven/com/oxy ... Model.html , https://www.oxygenxml.com/maven/com/oxy ... ction.html ,
https://www.oxygenxml.com/maven/com/oxy ... ement.html .
- Then, you can refresh the toolbar actions status using

Code: Select all

actionsManager.refreshActionsStatus
. More details here: https://www.oxygenxml.com/maven/com/oxy ... nager.html
- To decide when to refresh the toolbar actions status you could use the browser selection events (https://developer.mozilla.org/en-US/doc ... tionchange) with a proper debouncing.

Best,
Cristian
jacobBocaj
Posts: 12

Re: Activation Xpath on JS Customized Action

Thu Jun 29, 2017 12:00 am

HI Cristian,

This solution works perfectly! Thank you for the guidance.

Regards,
Jacob

Return to “Other Issues”

Who is online

Users browsing this forum: No registered users and 3 guests