Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Prototype insertion - deprecation and custom functions

#83

The Prototype Insertion classes have been marked as deprecated in version 1.6.0. The part of the updateContent function that deals with insertion currently looks like this.

      if (options.insertion) {
        if (Object.isString(options.insertion)) {
          var insertion = { }; insertion[options.insertion] = responseText;
          receiver.insert(insertion);
        }
        else options.insertion(receiver, responseText);
      }

I'm not sure whether the "else" option has been provided solely for backwards compatibility or whether it was intended to also allow custom insertion functions. The Prototype API documentation makes no mention of using it in this way.

Either way, I'd like this option to stay. I've found that it is the only clean way to reliably perform two scriptaculous effects before and after the content is replaced. Using effect queues, as suggested in http://dev.rubyonrails.org/ticke..., is not sufficient because even though this separates the effects, it does not prevent Prototype from replacing the content before the first effect has completed.

However, the Rails helpers currently only support the deprecated Insertion classes. This patch tackles both the deprecation issue and the custom function issue in a backwards compatible way, as long as Prototype 1.6.0 or greater is used. The existing :position option takes priority over the new :insertion option. The former is passed as a string, whereas the latter is passed as-is, thereby allowing a custom function to be given. Here is an example. I have tested this with Edge and 2.0.2.

remote_form_for :foo, @foo, :url => { ... }, :update => 'content', :insertion => "function(receiver, response_text) { " + visual_effect(:blind_up, 'content', :afterFinish => "function() { receiver.update(response_text);" + visual_effect(:blind_down, 'content') + " }") + " }" do |f|

Reported by James Le Cuirot · May 1st, 2008 @ 05:57 PM

State: invalid
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. James Le Cuirot
    James Le Cuirot

    Just had a thought. The ideal way to do this would probably be to ditch :position and have :insertion pass the value as a string or as-is depending on whether the value itself is a symbol or a string respectively. That would break backwards compatibility though.

    May 1st, 2008 @ 06:11 PM

  2. DHH
    DHH
    • State changed from new to invalid

    Hi Chewi, Prototype now has its own Lighthouse: http://prototype.lighthouseapp.com

    May 1st, 2008 @ 08:44 PM