Search code examples
javascriptliferayicefaces

How to register an IcePush Listener in a Portlet?


I want to execute some custom code on an IcePush Render update. IcePush itself is working porperly (also over mulitple portlets)

So what i want to do exactly is to resize an image to an given aspect ratio and place marker pins (known from google Maps). But these markers (and the image) are dynamicaly updated via IcePush.

So if i use JQuery's ready() it works the first time but after an page update it fails.

greetings Florian


Solution

  • I have solved it! If you change the JS Code it will be executed after AJAX Update. Like this:

        <script type="text/javascript">
            function resizeStage() {
                var prefWidth=maxWidth*(1+(0.1*zoomFactor));
                jQuery(".slide_" + slideUUID).width(prefWidth);
                var actualWidth=jQuery(".slide_" + slideUUID).width();
                jQuery(".slide_" + slideUUID).height(actualWidth * 3 / 4); // Fix to 4x3
            }
            // This will be executed after AJAX Update
            // Because the var slideUUID changes after each AJAX Update
            var slideUUID = "#{navigationBackingBean.currentSlide.uuid}"; // To identify slide and to execute JS after AJAX udpate!
    
            resizeStage();
            jQuery(window).unbind('resize', resizeStage)
            jQuery(window).resize(resizeStage);
        </script>