30/09/2010 Development / java script

Imports
// http://code.jquery.com/jquery.js
// jquery.tmpl.js

<SCRIPT>

    var data = [{ stock: "PETR4", id: 1, value: "R$40,00" }, { stock: "CESP6", id: 2, value: "R$50,00" }, { stock: "ITAU4", id: 3, value: "R$60,00"}];

    function update() {
        $("ul").html("");
        $("#Template").tmpl($.shuffle(data)).appendTo("ul");
    }

    jQuery(function(){
        setInterval("update()", 1000)
    });

    // Extendo a funcao para jQuery * Realiza um random do Array
    $.shuffle = function(arr) {
        for(var j, x, i = arr.length; i; j = parseInt(Math.random() * i), x = arr[--i], arr[i] = arr[j], arr[j] = x);
        return arr;
    }

</SCRIPT>

<ul></ul>

<script id="Template" type="text/html">
    <li><a href="${id}">${stock}</a> - ${value}</li>
<script>