7 Replies Latest reply on Apr 26, 2012 10:48 AM by shannonsumner

    Javascript on page load

    shannonsumner

      Hello,

       

      I use jQuery in my pages to add animations etc ... to my pages.  This works great until I go into the "edit page", "add a new page" or "edit layout" screens and return to my original page.  The page is getting redrawn but the javascript is not reapplied.  I assume this is because the page is not reloaded.  Does anyone know how I would reapply my javascript after I exit these administrative pages?

       

      Thanks,

       

      Shannon

        • 1. Re: Javascript on page load
          mstruk
          • 2. Re: Javascript on page load
            vstorm83

            @Shannon : Can you tell me which GateIn version you are using, and how do you add jQuery JS file to page, did you use Extra Markup Header ? There is a bug with Extra Markup Header with old GateIn version (extra headers are lost when Finish editing page) , but it has been fixed on the newest GateIn version

            • 3. Re: Javascript on page load
              shannonsumner

              Hello Vu,

               

              I've added the javascript via a js-module in the portal skin.

               

              Thanks,

               

              Shannon

              • 4. Re: Javascript on page load
                vstorm83

                ok, so you use the gatein-resources.xml, right ?

                Your jQuery js file will be merged in to merged.js file. Portal use Ajax when the page editing process is closed and return to normal page --> the browser is not refreshed and the merged.js file is still there on the html header.

                 

                Note that, it's an ajax request, so you shouldn't use the document.onload or DOMContentLoaded ($(document).ready()) JS event to initialize your portlet's html

                • 5. Re: Javascript on page load
                  shannonsumner

                  Hi Vu,

                   

                  I am using the gatein-resources.xml.  Are there any GateIn javascript activities for me to link against so I can can trigger my jQuery code upon their completion?

                   

                  Thanks,

                   

                  Shannon

                  • 6. Re: Javascript on page load
                    vstorm83

                    1. You can add markup head elements in your portlet render phase. This is defined in portlet spec (JSR 286)

                     

                    2. Just simply put your JS entry point code to the end of your portlet's html template. After Ajax request, portal will update your portlet html, and execute that JS code

                     

                    3. Or you can use JavascriptManager that is a property of RequestContext: org.exoplatform.web.application.RequestContext.getCurrentInstance()

                    Then call org.exoplatform.web.application.JavascriptManager#addJavascript(String) --> call this in your portlet's render phase, this javascript snipet will be called after Ajax request has been finished

                     


                    • 7. Re: Javascript on page load
                      shannonsumner

                      Hello Vu,

                       

                      I utilized the JavascriptManager to initiate my scripts and that worked wonderfully.

                       

                      Thanks,

                       

                      Shannon