Symfony Unobtrusive JavaScript Plug-In
François Zaninotto has been talking about a new Unobtrusive JavaScript Plug-In for symfony.
Simple Example
PHP:
-
-
<div id="foobar">
-
I'm here !
-
</div>
-
<?php UJS("$('#foobar').css('display', 'none')") ?>
-
How it is generated
PHP:
-
-
<?php UJS_write('<a href="#" onclick="$(\'#foobar\').toggle();return false;">click me') ?>
-
<div id="foobar">
-
I'm here !
-
</div>
-
<?php UJS_change_style('#foobar', 'display:none') ?>
-
this becomes...
HTML:
-
-
<span style="display: none" class="UJS_placeholder" id="UJS_0"></span>
-
<div id="foobar">
-
I'm here !
-
</div>
-
...
-
// <![CDATA[
-
$().ready(function(){
-
$('#UJS_0').after('<a href="#" onclick="$(\'#foobar\').toggle();return false;">click me');
-
$('#UJS_0').remove();
-
$('#foobar').css('display', 'none');
-
})
-
// ]]>
-
</script>
-
Source: Ajaxian
Original Article: http://ajaxian.com/archives/symfony-unobtrusive-javascript-plug-in