Posted by Yanick Rochon
on 11.09.2006 09:36
Since I didn't find an easy way to customize the behavior of <response 
type="element"... when updating the element, I modified the source code 
(sorry guys!) of the Rico library (1.1.2) so I could have an extra 
attribute named 'insertion'. This way I can control how html is inserted 
in my tree from server side. Example :

<ajax-response>
  <response type="object" id="listHandler">
    <item value="1">Car</item>
    <item value="2">Boat</item>
    <item value="3">Foo</item>
  </response>
  <response type="element" id="divCart">
    Nothing in cart.
  </response>
  <response type="element" id="divMessages" insertion="Top">
    <div>Hello there !</div>
    <div>Please make your selection</div>
  </response>
</ajax-response>

I thought that this could become handy for some people, and the changes 
are quick to make to the source (only 3 lines to modify!) What do you 
think ?


Here's the modification :

Rico.AjaxEngine.prototype = {

   ...

   _processAjaxElementUpdate: function( ajaxElement, responseElement ) {
      // added on 2006-09-12
      var insertMode = responseElement.getAttribute("insertion");
      var html = RicoUtil.getContentAsString(responseElement);

      // the possible values for insertMode are (case sensitive)
      //   Before, Bottom, Top, After
      if ( insertMode ) {
        new Insertion[insertMode](ajaxElement, html);
      } else {
        Element.update(ajaxElement, html);
      }
   }

}

-Yanick