Would anyone be able to tell me how to go about this..? The script I’m looking to convert is this:
[CODE]<script type=”text/javascript”>
// sort all divs with classname ‘sortitem’ by html content
function sort_div_content() {
//thanks to Thomas Sturm for this lovely little piece of javascript
// copy all divs into array and destroy them in the page
divsbucket = new Array();
divslist = $$(‘div.sortitem’);
for (a=0;a<divslist.length;a++) {
divsbucket[a] = divslist[a].dispose();
}
// sort array by HTML content of divs
divsbucket.sort(function(a, b) {
if (a.innerHTML.toLowerCase() === b.innerHTML.toLowerCase()) {
return 0;
}
if (a.innerHTML.toLowerCase() > b.innerHTML.toLowerCase()) {
return 1;
} else {
return -1;
}
});
// re-inject sorted divs into page
for (a=0;a<divslist.length;a++) {
divsbucket[a].inject($(‘Shelf’));
}
}
// sort by attributes – usage for our example: sort_div_attribute(‘sortweight’);
function sort_div_attribute(attname) {
// copy all divs into array and destroy them in the page
divsbucket = new Array();
divslist = $$(‘div.sortitem’);
for (a=0;a<divslist.length;a++) {
divsbucket[a] = new Array();
// we’vev passed in the name of the attribute to sort by
divsbucket[a][0] = divslist[a].get(attname);
divsbucket[a][1] = divslist[a].dispose();
}
// sort array by sort attribute content
divsbucket.sort(function(a, b) {
if (a[0].toLowerCase() === b[0].toLowerCase()) {
return 0;
}
if (a[0].toLowerCase() > b[0].toLowerCase()) {
return 1;
} else {
return -1;
}
});
// re-inject sorted divs into page
for (a=0;a<divslist.length;a++) {
divsbucket[a][1].inject($(‘Shelf’));
}
}
</script>
The provider of the script seemed to imply it should be fairly easy to amend but in all honesty I have no idea how to… ?
Any replies would be much appreciated!!
Max