Issue Details (XML | Word | Printable)

Key: LEP-6428
Type: Improvement Improvement
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Nate Cavanaugh
Reporter: Nate Cavanaugh
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
PUBLIC - Old Liferay Portal (Use Liferay Portal Standard Edition)

Liferay Events system needs tweaking

Created: 25/Jun/08 01:07 PM   Updated: 25/Jun/08 01:19 PM
Component/s: None
Affects Version/s: 5.0.1
Fix Version/s: 5.1.0

Time Tracking:
Not Specified


 Description  « Hide
The Liferay.Publisher object duplicates a lot of code and functionality that is already available. It's also not very intuitive to use.

Instead, the Liferay.Publisher object is being renamed to Liferay.Events, with shortcuts in the Liferay object itself, via Liferay.bind, Liferay.trigger, and Liferay.unbind.

The event callback API is mostly unchanged, except that the first parameter is always the event object (usable for accessing the event type, and other details), and the second parameter is whatever data is being passed in to the callback.

This allows us to more easily allow users to listen for events happening in the Liferay javascript, and perform actions when those events happen.

 All   Comments   Work Log   Change History   FishEye      Sort Order: Ascending order - Click to sort in descending order
Nate Cavanaugh added a comment - 25/Jun/08 01:18 PM - Visible to
For documentation purposes (will be added to the wiki):
Here is how the system works. Suppose we wish to perform an action every time a portlet is closed.

We would put in our Javascript:

Liferay.bind('closePortlet', function(event, data){
alert(event.type);
});

In that example, we would get an alert that said: closePortlet.

In this case, the data being passed in is an object with the properties of plid and portletId, being the plid the portlet was deleted from and the portlet id of the portlet that was closed.

The official parameters are:

Liferay.bind(eventType, fn, scope);
eventType is the Liferay event you wish to subscribe to.
fn is the function that will be executed when the event takes place.
scope is the object scope in which you wish to execute the function. This is helpful if you have a method on an object that needs access to class variables that are only available in that objects scope.

Liferay.trigger(eventType, data);
eventType is the event you wish to trigger (this can be your own event, or you can be faking an event).
data is the data you wish to pass along to all of the listening functions.

Liferay.unbind(eventType, fn);
eventType is the event you wish to stop listening to.
fn is the specific function you wish to remove from listening. If this isn't passed in, all listening functions are removed from this event type.