# Changes required by JQuery and endeca-async upgrades

Prior to version 1.4, the Discovery Framework used jQuery 1.2.6, which is the version of jQuery supplied by Liferay. jQuery was available in the `jQuery` variable.

Starting with version 1.4, the Discovery Framework accesses two versions of jQuery: 1.2.6 and 1.4.4.

- jQuery 1.2.6 remains available in the `jQuery` variable.
- jQuery 1.4.4, which is used by the endeca-async library, is available in the `jq14` variable.

## Required component changes

1. Any component that has a postRender override must ensure that all variables used by that postRender override are initialized in a jq14.ready() block instead of a jQuery.ready() block. Because jQuery 1.4.4 is faster than, and loaded earlier than, jQuery 1.2.6, the jq14.ready() block will fire before the jQuery.ready() block. Therefore, by the time the component's postRender override executes, it is likely that jQuery.ready() has not even begun. If the postRender override depends on variables that are only initialized in jQuery.ready(), those variables will not exist yet and the override will fail.
   The following example shows the Discovery Framework 1.3 syntax, with the relevant line highlighted:

       <script type="text/javascript">
       jQuery.ready(function(){
         myVar = "hello world!";
       })

       // postRender override function
       function postRender<portlet:namespace/>(asyncObject) {

         asyncObject.initAsync();

         var detailLinks = jQuery('#<portlet:namespace/>async a .my-special-links');
         detailLinks.expire();
         detailLinks.livequery('click',
           function(e) {
             alert(myVar);
           });
       }
       </script>

   The following example shows the Discovery Framework 1.4 (and later) syntax, with the relevant line highlighted:

       <script type="text/javascript">
       jq14.ready(function(){
         myVar = "hello world!";
       })

       // postRender override function
       function postRender<portlet:namespace/>(asyncObject) {

         asyncObject.initAsync();

         var detailLinks = jq14('#<portlet:namespace/>async a .my-special-links');
         detailLinks.click(
           function(e) {
             alert(myVar);
           });
       }
       </script>

2. Any component that manually adds a form to its DOM after its initial render (that is, without re-executing postRender.jspf must add code to rewrite the new forms.
   The following example shows the form code required in Discovery Framework 1.4 and later:

       <script type="text/javascript">

       function myCustomFunction(asyncObject) {
         jq14('#myElement').append(myNewForm); // adds a new form to the document
         asyncObject.rewriteForms(); // after adding, must trigger rewriteForms
       }
       </script>

## Recommended component changes

Although it is not required, Endeca recommends that you update your components' JavaScript code to use jQuery 1.4.4 through the jq14 variable instead of jQuery 1.2.6 through the jQuery variable, in order to gain the newer version's performance and functionality enhancements.

Note: The version of livequery used in Liferay is not compatible with jQuery 1.4.4. The best approach is to replace livequery with jQuery.live().