When adding custom behavior to your application, modifying the existing script.aculo.us javascript files can leave you in a bind. As new features are added and bugs are fixed, you’ll need to modify the library files with each release.

However, there is a better way – extending script.aculo.us without modifying the source code is easy as of the release of version 1.5_pre4.

  1. Create an extensions.js file and save it in the same directory as the other script.aculo.us files in your application (i.e. /public/javascripts/extensions.js in Ruby on Rails).

  2. Add the extensions file to the end of the load list in scriptaculous.js.
    
    this.require(path + 'extensions.js');
    

    In the newer version of scriptaculous, add ‘extensions’ to the list of “builder,effects,dragdrop,controls,slider” on line 39 of scriptaculous.js:

    
    (includes ? includes[1] : 'builder,effects,dragdrop,controls,slider').split(',').each(
    function(include) { Scriptaculous.require(path+include+'.js') });
    


    You should also be able to use <script type="text/javascript" src="scriptaculous/scriptaculous.js?load=effects,dragdrop,extensions">when calling your script.
  1. Add overrides and extensions of the library to the newly created extensions.js file.
    
    /* when finished, don't jump back to the top of the page. 
     */
    Object.extend(Element, {
    show: function() {
        for (var i = 0; i < arguments.length; i++) {
          var element = $(arguments[i]);
          element.style.display = '';
        } // end for
      }})
    

When you checkout the next release of script.aculo.us, simply repeat step 2.