This project is archived and is in readonly mode.

#83 ✓invalid
James Le Cuirot

Prototype insertion - deprecation and custom functions

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

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|

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Attachments

Pages