This project is archived and is in readonly mode.

#966 ✓invalid
47primes

Add options to ScriptaculousHelper.drop_receiving_element_js to pass commands before and after Ajax call

Reported by 47primes | September 3rd, 2008 @ 07:21 PM | in 3.x

This version of drop_receiving_element_js adds two additional options, beforeAjax and afterAjax, that provide a means for javascript code to be executed before and after the creation of the Ajax.Request object.


def drop_receiving_element_js(element_id, options = {}) #:nodoc:
        options[:with]     ||= "'id=' + encodeURIComponent(element.id)"
        beforeAjax = options[:beforeAjax] ? options[:beforeAjax] + ';' : ''
        afterAjax = options[:afterAjax] ? options[:afterAjax] + ';' : ''
        options.delete(:beforeAjax)
        options.delete(:afterAjax)
        options[:onDrop]   ||= "function(draggable,droppable,event){" + beforeAjax + remote_function(options) + ';' + afterAjax + "}"
        options.delete_if { |key, value| PrototypeHelper::AJAX_OPTIONS.include?(key) }

        options[:accept] = array_or_string_for_javascript(options[:accept]) if options[:accept]
        options[:hoverclass] = "'#{options[:hoverclass]}'" if options[:hoverclass]

        # Confirmation happens during the onDrop callback, so it can be removed from the options
        options.delete(:confirm) if options[:confirm]

        %(Droppables.add(#{element_id.to_json}, #{options_for_javascript(options)});)
      end

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>

Pages