It's possible to get your listings display in a random order rather than the default using the following script changes. I've tested this in IE8, Chrome and Safari but obviously offer no guarantees.
It will display in a random order your Priority Entries and then your Normal Entries. As the script has to be included in the t!wdview.html template a problem crops up if you do not have at least one of each listing type. I've overcome that with a quick javascript "hide error message" script as well.
First of all you need 2 javascript files loaded externally. Content is identical in both, call one entryHigh.js and the other entryNorm.js. Upload both files to your web server in same location as all other files.
Here's the code:
// JavaScript Document
/***********************************************
* Random Content Order script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/
function randomizeContent(classname){
var contents=randomizeContent.collectElementbyClass(cl assname)
contents.text.sort(function() {return 0.5 - Math.random();})
var tbodyref=contents.ref[0].tagName=="TR"? contents.ref[0].parentNode : new Object()
for (var i=0; i<contents.ref.length; i++){
if (tbodyref.moveRow) //if IE
tbodyref.moveRow(0, Math.round(Math.random()*(tbodyref.rows.length-1)))
else
contents.ref[i].innerHTML=contents.text[i]
contents.ref[i].style.visibility="visible"
}
}
randomizeContent.collectElementbyClass=function(cl assname){ //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
}
Next we need to add these bits to the t!wdview.html page.
In the head section add just below the grvalidator line (about line22)
<script type="text/javascript" src="entryHigh.js"></script>
<script type="text/javascript" src="entryNorm.js"></script>
<script type="text/javascript">
function noError(){return true;}
window.onerror = noError;
</script>
<style type="text/css">
.entryHigh{
visibility: hidden;
}
.entryNorm{
visibility: hidden;
}
</style>
Then look for
<!--/entryList-->
{$listings}
Immediately below that add the following
<script type="text/javascript">
randomizeContent("entryHigh")
</script>
<script type="text/javascript">
randomizeContent("entryNorm")
</script>
Save and upload. If you only want to display one type randomly just delete the other from all places. You must leave the error code checker script in if any page does not have the type of listing you want to randomise.
So far this has worked well but I only have listings on one page. When the script starts adding additional pages (set here in wdcfg.php define('WDENTPPAGE', 20); not yet sure how will react.
Hope you like it.
Mike


Reply With Quote
Bookmarks