Symfony Unobtrusive JavaScript Plug-In

Written by on February 28th, 2007 in Ajax News.

François Zaninotto has been talking about a new Unobtrusive JavaScript Plug-In for symfony.

Simple Example

PHP:

  1.  
  2. <div id=”foobar”>
  3.   I’m here !
  4. </div>
  5. <?php UJS("$(’#foobar’).css(’display’, ‘none’)") ?>
  6.  

How it is generated

PHP:

  1.  
  2. <?php UJS_write(’<a href="#" onclick="$(\’#foobar\’).toggle();return false;">click me’) ?>
  3. <div id=”foobar”>
  4.   I’m here !
  5. </div>
  6. <?php UJS_change_style(’#foobar’, ‘display:none’) ?>
  7.  

this becomes…

HTML:

  1.  
  2. <span style=”display: none” class=”UJS_placeholder” id=”UJS_0″></span>
  3. <div id=”foobar”>
  4.   I’m here !
  5. </div>
  6. //  <![CDATA[
  7. $().ready(function(){
  8.     $(’#UJS_0′).after(’<a href="#" onclick="$(\’#foobar\’).toggle();return false;">click me’);
  9.     $(’#UJS_0′).remove();
  10.     $(’#foobar’).css(’display’, ‘none’);
  11.  })
  12. //  ]]>
  13. </script>
  14.  

Source: Ajaxian
Original Article: http://ajaxian.com/archives/symfony-unobtrusive-javascript-plug-in

Leave a Reply

You must be logged in to post a comment.



Site Navigation