/    Sign up×
Community /Pin to ProfileBookmark

Converting a script to use with jQuery instead of MooTools

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>[/CODE]

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

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@rootMar 01.2014 — Please ask in the Javascript frameworks forum...
Copy linkTweet thisAlerts:
@MaxRyanauthorMar 02.2014 — sorry!
×

Success!

Help @MaxRyan spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...