Loading JavaScript AMD modules for the responsive WebHelp output
Post here questions and problems related to editing and publishing DITA content.
-
- Posts: 16
- Joined: Mon Apr 23, 2018 8:38 am
Loading JavaScript AMD modules for the responsive WebHelp output
Hi,
I'm trying to load AMD modules using the publishing template but I can't seem to be able to define the paths to the JS libraries correctly. For instance, I'd like to initialize DataTables in this manner but I get the following error in the console:
And in template-main.js, I have:
Additionally, can I use the WebHelp localization framework in the DataTables initialization? I suppose I'd have to add the localization module as a dependency but how would one go about doing that?
Best,
Antti
I'm trying to load AMD modules using the publishing template but I can't seem to be able to define the paths to the JS libraries correctly. For instance, I'd like to initialize DataTables in this manner but I get the following error in the console:
Here's my JS file, tables,js, that attempts to initialize DataTables:require.js:5 GET file:///C:/[...]/out/webhelp-responsive/oxygen-webhelp/app/datatables.js 0 ()
Uncaught Error: Script error for "datatables", needed by: template-base-dir/resources/js/tables
http://requirejs.org/docs/errors.html#scripterror
at makeError (require.js:5)
at HTMLScriptElement.onScriptError (require.js:5)
Code: Select all
var rootDir = $('meta[name=wh-path2root]').attr('content'),
templateDir = rootDir + 'oxygen-webhelp/template/',
datatables = templateDir + 'resources/js/datatables.min';
define(['jquery', 'datatables'], function ($) {
$('.sortable').DataTable({
paging: paging,
pagingType: 'simple_numbers',
pageLength: pageLength,
info: paging
});
});
Code: Select all
define(['require'], function (require) {
require(['./tables']);
});
Best,
Antti
-
- Posts: 4
- Joined: Wed Jul 18, 2018 8:56 am
Re: Loading JavaScript AMD modules for the responsive WebHelp output
Post by Kiyoshirue »
Hi there,
I'm having similar issues with defining the paths to the JS libraries. Getting Antti's issue resolved would most likely help me out as well.
Thanks,
Kiyoshirue
I'm having similar issues with defining the paths to the JS libraries. Getting Antti's issue resolved would most likely help me out as well.
Thanks,
Kiyoshirue
-
- Site Admin
- Posts: 275
- Joined: Thu Dec 24, 2009 11:21 am
Re: Loading JavaScript AMD modules for the responsive WebHelp output
Hello,
Supposing that your template directory would look like this:
The tables.js should look as follows:
Note that the "tables.js" declares a dependency for the "localization" module. You can specify dependencies for any WebHelp core library using its module ID as defined in [WebHelp-Responsive-Base-Dir]/oxygen-webhelp/app/config.js
You should also update the JS related fileset from the template's descriptor file to recursively include all *.js files under the "js" directory:
You can find the template samples here: https://github.com/oxygenxml/oxygen-pub ... js-modules
Regards,
Alin
Supposing that your template directory would look like this:
Code: Select all
[js-modules] --- the Publishing Template base dir
- [js]
- [datatables]
- datatables.min.js
- tables.js
- template-main.js
Code: Select all
define(["jquery", "localization", "./datatables/datatables.min"], function ($, i18n) {
$(document).ready(function () {
console.log("i18n: ", i18n.getLocalization('webhelp.search'));
$('.table').DataTable();
});
});
You should also update the JS related fileset from the template's descriptor file to recursively include all *.js files under the "js" directory:
Code: Select all
<resources>
<css file="js-modules.css"/>
<js-amd-module file="js/template-main.js"/>
<fileset>
<include name="js/**/*.js"/>
</fileset>
</resources>
Regards,
Alin
Alin Balasa
Software Developer
<oXygen/> XML Editor
http://www.oxygenxml.com
Software Developer
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 16
- Joined: Mon Apr 23, 2018 8:38 am
Re: Loading JavaScript AMD modules for the responsive WebHelp output
Thank you, that helped me solve the issue.
On a related note, our webhelp user guides share a JavaScript file that uses jQuery UI. We have different versions of our user guides in separate folders, like so:
<domain>/user-guide/<product version>/<language>/index.html
The JavaScript file shared by each user guide version is located under the following location:
<domain>/user-guide
So each HTML file in each documentation set has the following element:
<script type="text/javascript" src="../../<shared JS file>.js"></script>
Now, since the shared JavaScript file employs jQuery UI, I suppose the shared JS file should use the RequireJS define function to load the jQuery UI library for newer user guide versions that use RequireJS, and for older versions where jQuery UI is loaded via the script tag, the same jQuery UI stuff is done outside the define function.
Is there any way to achieve this using the JS file defined in the <js-amd-module/> element in the publishing template?
On a related note, our webhelp user guides share a JavaScript file that uses jQuery UI. We have different versions of our user guides in separate folders, like so:
<domain>/user-guide/<product version>/<language>/index.html
The JavaScript file shared by each user guide version is located under the following location:
<domain>/user-guide
So each HTML file in each documentation set has the following element:
<script type="text/javascript" src="../../<shared JS file>.js"></script>
Now, since the shared JavaScript file employs jQuery UI, I suppose the shared JS file should use the RequireJS define function to load the jQuery UI library for newer user guide versions that use RequireJS, and for older versions where jQuery UI is loaded via the script tag, the same jQuery UI stuff is done outside the define function.
Is there any way to achieve this using the JS file defined in the <js-amd-module/> element in the publishing template?
-
- Site Admin
- Posts: 275
- Joined: Thu Dec 24, 2009 11:21 am
Re: Loading JavaScript AMD modules for the responsive WebHelp output
Hello,
The JavaScript file referenced using the "<js-amd-module/>" element will only be loaded as an AMD module using a "require" call.
Furthermore, this JS file should reside in the Publishing Template's root directory. This means that it should be located in the same directory as the template's descriptor file (*.opt). The descriptor file cannot reference files outside that directory.
At publishing time, the contents of a template package will be copied in the output folder. So you cannot share the same instance of a file among different publications using the Publishing Template mechanism.
Regards,
Alin
The JavaScript file referenced using the "<js-amd-module/>" element will only be loaded as an AMD module using a "require" call.
Furthermore, this JS file should reside in the Publishing Template's root directory. This means that it should be located in the same directory as the template's descriptor file (*.opt). The descriptor file cannot reference files outside that directory.
At publishing time, the contents of a template package will be copied in the output folder. So you cannot share the same instance of a file among different publications using the Publishing Template mechanism.
Regards,
Alin
Alin Balasa
Software Developer
<oXygen/> XML Editor
http://www.oxygenxml.com
Software Developer
<oXygen/> XML Editor
http://www.oxygenxml.com
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