Loading JavaScript AMD modules for the responsive WebHelp output
Posted: Fri Jul 13, 2018 4:26 pm
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