Activation Xpath on JS Customized Action
Oxygen general issues.
-
- Posts: 12
- Joined: Thu May 11, 2017 10:18 pm
Activation Xpath on JS Customized Action
Post by jacobBocaj »
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?
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);
} ...
-
- Posts: 517
- Joined: Thu Sep 04, 2014 4:22 pm
Re: Activation Xpath on JS Customized Action
Post by cristi_talau »
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 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:. 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 . 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
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
- 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()
https://www.oxygenxml.com/maven/com/oxy ... ement.html .
- Then, you can refresh the toolbar actions status using
Code: Select all
actionsManager.refreshActionsStatus
- 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
-
- Posts: 12
- Joined: Thu May 11, 2017 10:18 pm
Re: Activation Xpath on JS Customized Action
Post by jacobBocaj »
HI Cristian,
This solution works perfectly! Thank you for the guidance.
Regards,
Jacob
This solution works perfectly! Thank you for the guidance.
Regards,
Jacob
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service