vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3.6 Add-ons (https://vborg.vbsupport.ru/forumdisplay.php?f=194)
-   -   Miscellaneous Hacks - Display groups of content in random order (https://vborg.vbsupport.ru/showthread.php?t=145676)

Get Shorty 04-23-2007 10:00 PM

Display groups of content in random order
 
This is not just another banner rotator mod...
This will not increase your server load...
This will not break your XHTML vadlidation...

This will allow you to define an array of content (banners, links, text, whatever), then have them display in a random order with each page refresh. :)

Copy this code and save it as random.js or download the attached file:

Code:

function randomizeContent(classname){

var contents=randomizeContent.collectElementbyClass(classname)

contents.text.sort(function() {return 0.5 - Math.random();})

for (var i=0; i<contents.ref.length; i++){

contents.ref[i].innerHTML=contents.text[i]

contents.ref[i].style.visibility="visible"

}

}



randomizeContent.collectElementbyClass=function(classname){ //return two arrays containing elements with specified classname, plus their innerHTML content

var classnameRE=new RegExp("(^|\\s+)"+classname+"($|\\s+)", "i") //regular expression to screen for classname within element

var contentobj=new Object()

contentobj.ref=new Array() //array containing references to the participating contents

contentobj.text=new Array() //array containing participating contents' contents (innerHTML property)

var alltags=document.all? document.all : document.getElementsByTagName("*")

for (var i=0; i<alltags.length; i++){

if (typeof alltags[i].className=="string" && alltags[i].className.search(classnameRE)!=-1){

contentobj.ref[contentobj.ref.length]=alltags[i]

contentobj.text[contentobj.text.length]=alltags[i].innerHTML

}

}

return contentobj

}

Upload random.js to your clientscript folder.

Copy the follow to your 'Additional CSS' section of your style

Code:

.group1{
visibility: hidden;
}

Add the following code to the bottom of your HEADINCLUDE template

Code:

<script type="text/javascript" src="clientscript/random.js"></script>
Insert your content using <div class=group1> tags. Be sure to include the code below the html

Code:

<div class="group1">
Content 1
</div>

<div class="group1">
Content 2
</div>

<div class="group1">
Content 3
</div>

<div class="group1">
Content 4
</div>

<div class="group1">
Content 5
</div>


<script type="text/javascript">

//randomize order of contents with DIV class="group1"
randomizeContent("group1")

</script>

You can make as many groups as needed, and call this script multiple times. Just be sure to repeat the CSS and div classes using group2, group3, etc...

Live Demo - Look at the small banners on the right. Refresh the page to watch them rotate.

Get Shorty 04-24-2007 03:05 PM

Some screenshots of how I'm using this...

Attachment 63603 Attachment 63604

ninjamaster 04-24-2007 07:04 PM

thanks m8 will look at this later

dj_melayu 04-24-2007 07:14 PM

Screenshot please :)

Get Shorty 04-24-2007 07:30 PM

Quote:

Originally Posted by ninjamaster (Post 1234880)
thanks m8 will look at this later

:)

Quote:

Originally Posted by dj_melayu (Post 1234885)
Screenshot please :)

I'll include some, but I don't see how that will be helpful. Just imagine any group of DIV's that you would like to show in a random order. :o

paulvon 08-17-2007 01:24 AM

This is really cool :cool: and I am looking forward to using it.

One quick question. If I have fifteen content items for example and want to display just the first three. How do I change the script?

Thank you


All times are GMT. The time now is 01:43 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.02876 seconds
  • Memory Usage 1,730KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (4)bbcode_code_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (6)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete