Run AMD script after built-in scripts
Post here questions and problems related to editing and publishing DITA content.
-
- Posts: 56
- Joined: Wed Aug 08, 2018 10:23 pm
Run AMD script after built-in scripts
We have some javascript code in an AMD module that needs to run after the built-in oXygen scripts. Specifically, we need some code to run after the expand.js script is loaded so that all expandable elements have been initialized to their default state. Is there some way to do this? It appears as if this would be possible if we could use the 'defer' attribute on the <script> tag for our script, instead of the default 'async' value but there doesn't seem to be a way to configure that. Thanks for any help you can provide.
-
- Site Admin
- Posts: 275
- Joined: Thu Dec 24, 2009 11:21 am
Re: Run AMD script after built-in scripts
Hello,
For the WebHelp Responsive output, please have a look at this topic: https://www.oxygenxml.com/doc/versions/ ... s-amd.html
Regards,
Alin
For the WebHelp Responsive output, please have a look at this topic: https://www.oxygenxml.com/doc/versions/ ... s-amd.html
Regards,
Alin
Alin Balasa
Software Developer
<oXygen/> XML Editor
http://www.oxygenxml.com
Software Developer
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 56
- Joined: Wed Aug 08, 2018 10:23 pm
Re: Run AMD script after built-in scripts
Thanks Alin. We've already successfully used the publishing template approach to inject our custom javascript and it works great. We're having a timing issue with our code versus code that's in the built-in javascript files from oXygen, specifically expand.js. I didn't see anything in that topic about timing issues unless I missed something.
-
- Site Admin
- Posts: 275
- Joined: Thu Dec 24, 2009 11:21 am
Re: Run AMD script after built-in scripts
Hello,
You could try to list the "expand.js" as a dependency in your module definition. For example:
Here is my console output (I have added some log in the expand.js module):

According to the requirejs documentation here (https://requirejs.org/docs/api.html#defdep):

Regards,
Alin
You could try to list the "expand.js" as a dependency in your module definition. For example:
Code: Select all
define(["expand"], function () {
console.log("template module loaded");
});

According to the requirejs documentation here (https://requirejs.org/docs/api.html#defdep):
Here is another approach you could use:If the module has dependencies, the first argument should be an array of dependency names, and the second argument should be a definition function. The function will be called to define the module once all dependencies have loaded.
Code: Select all
define(["require"], function() {
console.log("template module loaded");
require(['expand'], function() {
console.log("expand dependent function called");
});
});

Regards,
Alin
Alin Balasa
Software Developer
<oXygen/> XML Editor
http://www.oxygenxml.com
Software Developer
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 56
- Joined: Wed Aug 08, 2018 10:23 pm
Re: Run AMD script after built-in scripts
Thanks Alin. I'd actually tried the dependency module route but then you end up with two loaded versions of the built-in expand script, which causes problems. I managed to work around the issue by adding code to my script that does what I need from the expand script. Thanks again for your suggestions!
-
- Posts: 56
- Joined: Wed Aug 08, 2018 10:23 pm
Re: Run AMD script after built-in scripts
Correction regarding my earlier statement about multiple instances of the script. I mistakenly thought that I needed to specify the relative path to the expand script in the define statement, and should have just specified "expand" as in your example. When specify a relative path, you get a second instance of the script and when you just specify "expand" you only get a single instance which is what is needed. Many thanks again for the help!
Return to “DITA (Editing and Publishing DITA Content)”
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