Multiple Randomizer sections on a page?

A place to ask questions and get help. Be the first on your block to post ...

Multiple Randomizer sections on a page?

Postby mjoconnor » Fri Jun 04, 2010 8:28 am

I want to put more than one instance of the Randomizer element onto a page.

http://wdn.unl.edu/wdn/templates_3.0/ex ... mizer.html

I tried putting two on but it doesn't display items from each element consistently; it looks like they're combining. Sometimes items in the first set double up, and sometimes there is no element showing in one set. I also tried using the Javascript once per element and then just using it once for both, but neither seemed to work.

How can this be done? thanks
mjoconnor
 
Posts: 16
Joined: Fri May 16, 2008 11:56 am

Randomizer

Postby CanadianSuperSpy » Fri Jun 04, 2010 2:51 pm

I dont think it will work as it is currently with multiple instances.
Could change the template code to something like this maybe?
Code: Select all
WDN.randomizer = function () {
   return {
      initialize: function () {
         WDN.log('randomizer JS loaded');
         $('.wdn_randomizer').each(function () {
            var $t = $(this).children();
            $t.eq(Math.floor(Math.random() * $t.size())).siblings().remove();
         });
         return true;
      }
   };
} ();


In the mean time you can still follow the example on the examples page.
simply change this:
Code: Select all
<script type="text/javascript">
WDN.initializePlugin('randomizer');
</script>

To:
Code: Select all
<script type="text/javascript">
   //<![CDATA[
   WDN.jQuery(document).ready(function($) {
      $('.wdn_randomizer').each(function () {
         var $t = $(this).children();
         $t.eq(Math.floor(Math.random() * $t.size())).siblings().remove();
      });
   });
   //]]>
</script>
CanadianSuperSpy
 
Posts: 17
Joined: Wed Jul 23, 2008 1:22 pm
Location: CBA Room 13


Return to Help & Assistance

Who is online

Users browsing this forum: No registered users and 1 guest

cron