Ajax Blog


Symfony Unobtrusive JavaScript Plug-In

Posted in Ajax News by Dion Almaer on the February 28th, 2007

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. ...
  7. //  <![CDATA[
  8. $().ready(function(){
  9.     $('#UJS_0').after('<a href="#" onclick="$(\'#foobar\').toggle();return false;">click me');
  10.     $('#UJS_0').remove();
  11.     $('#foobar').css('display', 'none');
  12.  })
  13. //  ]]>
  14. </script>
  15.  

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

Comments are closed.