AJAX - The Complete Reference

(avery) #1

PART II


Chapter 9: Site and Application Architecture with Ajax 449


return $output;
}

function addScript($ratingItems)
{
$output = <<< END_OUTPUT
<script type="text/javascript"
src="http://ajaxref.com/ch9/ajaxtcr.js"></script>
<script type="text/javascript"
src="http://ajaxref.com/ch9/ratingprogressive.js"></script>
<script type="text/javascript">
AjaxTCR.util.event.addWindowLoadEvent(function () {
END_OUTPUT;
for ($i=0;$i<count($ratingItems);$i++)
{
$output .= "var options = {outputTarget: 'ratingResult$i',
form: \$id('ratingForm$i'),ratingContainer : \$id('ratings$i')};\r\n";
$output .= "AjaxTCR.widget.ratingWidget.init(options);\r\n";
}
$output .= "});";
$output .= "</script>";
return $output;
}
?>

The specifics of the syntax aren’t what we care about so much here. That will vary
depending on the development environment you use. We are focusing on the idea of
wrappers and what they do. They are just abstractions as you can see here. We take the
custom markup and we turn it into the specific markup and script.
Free download pdf