Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Nate Shaw
Minimize Portlet Using JavaScript
November 21, 2012 8:52 AM
Answer

Nate Shaw

Rank: Junior Member

Posts: 33

Join Date: October 26, 2010

Recent Posts

Hi all.

I am developing a mobile theme and have a requirement that all portlets be minimized when the page loads. I figured I could do this using JavaScript simply by adding the "portlet-minimized" CSS class to the portlet-boundary div on page load. However, this does not work.

1
2function collapsePortlets() {
3        jQuery('.portlet-boundary').addClass('portlet-minimized');
4        jQuery('.portlet-minimize-icon img').each(function(){
5            jQuery(this).attr('src','$restoreIcon');
6        });
7    }


So, I turned my attention to using the Liferay JavaScript objects. I found the Portlet object and tried calling the minimize function for each portlet on page load, but it is not working either.

 1
 2Liferay.Portlet.ready(
 3
 4    /*
 5    This function gets loaded after each and every portlet on the page.
 6
 7    portletId: the current portlet's id
 8    node: the Alloy Node object of the current portlet
 9    */
10
11    function(portletId, node) {
12        alert("loading portlet"+portletId);
13        Liferay.Portlet.minimize(portletId, node);
14        /*
15        AUI().use('portlet', function(A) {
16            A.Portlet.minimize(portletId, node);
17        });
18        */
19    }
20);


Obviously, Liferay is doing this when a user clicks on the minimize icon, but as far as I can tell, the only things happening are 1) the "portlet-minimized" class is added to the portlet-boundary and 2) the minimize icon is swapped with the restore icon. Am I missing something? Is there a way to do this?
Nate Shaw
RE: Minimize Portlet Using JavaScript
November 26, 2012 9:40 AM
Answer

Nate Shaw

Rank: Junior Member

Posts: 33

Join Date: October 26, 2010

Recent Posts

FYI, I figured this out. I was missing one CSS class required to make the portlets collapse properly.

1
2jQuery('.portlet-content-container').addClass('aui-helper-hidden');


Once I added that to my code, it worked like a charm.