Author Topic

Jorge estévez

Monday 24 November 2008 9:22:02 am

Comment50401

Thanks Piotrek Karaś, and thanks to all!

This is how I manage to set it all:

First at the folder's view line I have this:

<div id="{$node.node_id}">Data is being loaded...</div>

every instance of the template has a unique DIV named node_id (unique it is!)

The code:

{*cache-block expiry=86412*}
{cache-block expiry=10}
{set-block variable=$shuffle_1}...operations1...{/set-block}
{set-block variable=$shuffle_2}...operations2...{/set-block}
{set-block variable=$shuffle_3}...operations3...{/set-block}
{set-block variable=$shuffle_4}...operations4...{/set-block}
{set-block variable=$shuffle_5}...operations5...{/set-block}

{literal}
<script type="text/javascript" language="javascript">
    //<![CDATA[
    // some JS random function to pick var $shuffle 1-5
    var i=0;    
    var dameunaleatoreo=aleatorio(0,4);
    
    //alert(dameunaleatoreo);    
    
    if(dameunaleatoreo==0)
        document.getElementById('{/literal}{/cache-block}{$node.node_id}{cache-block expiry=10}{literal}').innerHTML = '{/literal}{$shuffle_1}{literal}'; 
    if(dameunaleatoreo==1)
        document.getElementById('{/literal}{/cache-block}{$node.node_id}{cache-block expiry=10}{literal}').innerHTML = '{/literal}{$shuffle_2}{literal}'; 
    if(dameunaleatoreo==2)
        document.getElementById('{/literal}{/cache-block}{$node.node_id}{cache-block expiry=10}{literal}').innerHTML = '{/literal}{$shuffle_3}{literal}'; 
    if(dameunaleatoreo==3)
        document.getElementById('{/literal}{/cache-block}{$node.node_id}{cache-block expiry=10}{literal}').innerHTML = '{/literal}{$shuffle_4}{literal}'; 
    if(dameunaleatoreo==4)
        document.getElementById('{/literal}{/cache-block}{$node.node_id}{cache-block expiry=10}{literal}').innerHTML = '{/literal}{$shuffle_5}{literal}'; 
    

    //]]>
</script>
{/literal}
{/cache-block}

Notice the {cache-block} inside the javascript code and also the {literal} stuff.

And of course I had to build up a javascript function for a random number

<script type="text/javascript" language="javascript"> 
function aleatorio(inferior,superior){ 
    numPosibilidades = superior - inferior 
    aleat = Math.random() * numPosibilidades 
    aleat = Math.round(aleat) 
    return parseInt(inferior) + aleat 
    } 
</script>    

Now I have to tidy up to make an efficient code all over the place.

Thanks

By the way my pages are a little big and still they keep showing in less than 5 seconds, I think this is great!

Diseño Web Cuba
Web Design Cuba
www.elfosdesign.com