Go Back   vb.org Archive > vBulletin Modifications > Archive > vB.org Archives > vBulletin 3.6 > vBulletin 3.6 Add-ons
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
Display groups of content in random order Details »»
Display groups of content in random order
Version: 1.00, by Get Shorty Get Shorty is offline
Developer Last Online: Jul 2010 Show Printable Version Email this Page

Category: Miscellaneous Hacks - Version: 3.6.x Rating:
Released: 04-23-2007 Last Update: Never Installs: 5
Template Edits
Additional Files  
No support by the author.

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.

Supporters / CoAuthors

Show Your Support

  • This modification may not be copied, reproduced or published elsewhere without author's permission.

Comments
  #2  
Old 04-24-2007, 03:05 PM
Get Shorty's Avatar
Get Shorty Get Shorty is offline
 
Join Date: Jun 2006
Location: Baton Rouge, LA
Posts: 65
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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

Attachment 63603 Attachment 63604
Reply With Quote
  #3  
Old 04-24-2007, 07:04 PM
ninjamaster's Avatar
ninjamaster ninjamaster is offline
 
Join Date: Oct 2006
Posts: 213
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

thanks m8 will look at this later
Reply With Quote
  #4  
Old 04-24-2007, 07:14 PM
dj_melayu dj_melayu is offline
 
Join Date: Aug 2006
Posts: 117
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Screenshot please
Reply With Quote
  #5  
Old 04-24-2007, 07:30 PM
Get Shorty's Avatar
Get Shorty Get Shorty is offline
 
Join Date: Jun 2006
Location: Baton Rouge, LA
Posts: 65
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by ninjamaster View Post
thanks m8 will look at this later


Quote:
Originally Posted by dj_melayu View Post
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.
Reply With Quote
  #6  
Old 08-17-2007, 01:24 AM
paulvon paulvon is offline
 
Join Date: Jul 2007
Posts: 4
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

This is really 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
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:49 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03922 seconds
  • Memory Usage 2,256KB
  • Queries Executed 22 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (4)bbcode_code
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_post
  • (1)navbar
  • (6)navbar_link
  • (120)option
  • (6)post_thanks_box
  • (6)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (6)post_thanks_postbit_info
  • (5)postbit
  • (6)postbit_onlinestatus
  • (6)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete