Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
Export external JavaScript libraries
Hello,
I would like to export some javascript functions from a module
to use it in portlet. In 7.1 version, it wad possible do
"addModule" as an AMD module and to use it in portlet by
"require" aui for example.
I am currently upgrading my portatl in 7.4 and
"addModule" does not exist anymore :
Previously, in my config.js and my-library.js :
Liferay.Loader.addModule({
dependencies: [],
name: 'jquery',
anonymous: true,
path: MODULE_PATH + 'my-library.js'
});
// Assuming your "module" will be exported as "my-library"
(function (root, factory) {
if (typeof Liferay.Loader.define === 'function' && Liferay.Loader.define.amd) {
// AMD. Register as a "named" module.
Liferay.Loader.define('my-library', [], factory);
} else if (typeof module === 'object' && module.exports) {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like environments that support module.exports,
// like Node.
module.exports = factory();
} else {
// Browser globals (root is window)
root['my-library] = factory();
}
}(this, function () {
myFunction= function () {
console.log('call my function');
}
}));
Now, i've tried to do it with liferay-npm-bundler but i've not succeeded to expose my library with this method. If someone as already done a similar module, it could help me.
Thanks !
As you're in a portlet, you can set
com.liferay.portlet.footer-portal-javascript
or
com.liferay.portlet.header-portal-javascript
in the
@Component
's properties (or in portlet.xml - check
this mapping)
Powered by Liferay™