/** * Makes the element with the DOM ID specified by '$element_id' receive * dropped draggable elements (created by 'draggable_element()') and make an AJAX call. * By default, the action called gets the DOM ID of the element as parameter. * * Example: * <?php drop_receiving_element('my_cart', array( * 'url' => 'cart/add', * )) ?> * * You can change the behaviour with various options, see * http://script.aculo.us for more documentation. */ function jq_drop_receiving_element($element_id, $options = array()) { $response = sfContext::getInstance()->getResponse(); $response->addJavascript(sfConfig::get('app_mdToolsPlugin_jquery_ui_folder', '/mdToolsPlugin/js/jquery') . '/jquery-ui'); if (!isset($options['with'])) { $options['with'] = "'id=' + encodeURIComponent(jQuery(ui.draggable).attr('id'))"; } if (!isset($options['drop'])) { $options['drop'] = "function(ev, ui){" . jq_remote_function($options) . "}"; } foreach (jq_get_ajax_options() as $key) { unset($options[$key]); } if (isset($options['accept'])) { $options['accept'] = _jq_array_or_string_for_javascript($options['accept']); } if (isset($options['hoverclass'])) { $options['hoverclass'] = "'{$options['hoverclass']}'"; } return jq_javascript_tag("jQuery('#{$element_id}').droppable(" . _jq_options_for_javascript($options) . ")"); }
/** * Makes the element with the DOM ID specified by '$element_id' receive * dropped draggable elements (created by 'draggable_element()') and make an AJAX call. * By default, the action called gets the DOM ID of the element as parameter. * * Example: * <?php drop_receiving_element('my_cart', array( * 'url' => 'cart/add', * )) ?> * * You can change the behaviour with various options, see * http://script.aculo.us for more documentation. */ function jq_drop_receiving_element($selector, $options = array()) { jq_add_plugins_by_name(array("ui")); if (!isset($options['with'])) { $options['with'] = "'id=' + encodeURIComponent(element.id)"; } if (!isset($options['drop'])) { $options['drop'] = "function(element){" . jq_remote_function($options) . "}"; } // For backwards compatibility with prototype if (isset($options['hoverclass'])) { $options['hoverClass'] = $options['hoverclass']; } $options['hoverClass'] = json_encode('hoverclass'); foreach (jq_get_ajax_options() as $key) { unset($options[$key]); } if (isset($options['accept'])) { $options['accept'] = json_encode($options['accept']); } $options = jq_options_for_javascript($options); $selector = json_encode($selector); return javascript_tag("jQuery({$selector}).droppable({$options});"); }