nextwebgen.com

The Next Generation Web Now

Symfony Unobtrusive JavaScript Plug-In

Filed under: Web 2.0 News — Dion Almaer at 11:15 am on Wednesday, February 28, 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. //  <![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.  
Share and Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
  • blogmarks
  • del.icio.us
  • De.lirio.us
  • digg
  • NewsVine
  • YahooMyWeb

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>