Techminded

Effective JavaScript for Liferay

The State of JavaScript in Liferay

Liferay's Javascript is based on library named AlloyUI that has Yahoo UI framework and bootrstap (starting from version 6.2 underlying. Besides lots of stuff from YUI it has many own improvements and portal specific features. Alloy brings JQuery like API that makes it easier for frontend developers to learn. You can compare and reffer to this at the following url: http://alloyui.com/rosetta-stone/

Modules & Dependencies

Let's create file named my-form.js in js folder of portlet. First of all, we should enclose our javascript function into anonymous function as it's intended to be used in most of js frameworks. We will use AUI global object function call and functions to load Alloy UI modules that is names use. The second function we call that is named add brings out module to the development pool that allows to rely other code loading only after mentioned in use is loaded

So instead of hundreds of functions Alloy withYui introduces Components that allows you to split the code into resusable, logically consistent units. We will create component definition just in our anonymous functon body: