Currently, with the way the AJAX Javascript helpers work, you cannot use
the returned javascript from something like sortable_element in a function.

For example, the following code can not work;
<?php echo javascript_tag("

  function initExtraSortable()
  {
    ".sortable_element('body', array(
                                   'url'      => '@myroute',
                                   'tag'      => 'tr',
                                   'before'   => "Element.show('i')",
                                   'complete' => "Element.hide('i');",
                                   'handle'   => 'handle',
      ))."
  }
"); ?>

The reason for this is that the sortable_element (and other similar
functions) return their data within a <script> tag, so the above would
output something like:
<script type="text/javascript">
//<![CDATA[
  function initExtraSortable()
  {
    <script type="text/javascript">
//<![CDATA[
Sortable.create('extra_body', {handle:'handle',
onUpdate:function(){Element.show(i'); new Ajax.Request('/',
{asynchronous:true, evalScripts:false, onComplete:function(request,
json){Element.hide('i');}, parameters:Sortable.serialize('body')})},
tag:'tr'})
//]]>
</script>

  }
//]]>
</script>


Notice the nested <script>'s

This also means you can't assign the returned value of a call to a
variable, so you can't do this:

var a = '.periodically_call_remote().'
a.stop();

I suggest that we add a 'notag' option to all javascript functions,
which means that these functions would return their javascript as-is,
without wrapping them in the script tag, for example (change marked with
*'s):

<?php echo javascript_tag("

  function initExtraSortable()
  {
    ".sortable_element('body', array(
                                   'url'      => '@myroute',
                                   'tag'      => 'tr',
                                   'before'   => "Element.show('i')",
                                   'complete' => "Element.hide('i');",
                                   'handle'   => 'handle',
                                   'notag'    => true // *******
      ))."
  }
"); ?>


Comments?

-- 
Ian P. Christian ~ http://pookey.co.uk

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to