I've got lists of links which change order when you click the "most" or "least" buttons, have a quick look at it, easier to understand: http://pinchweb.com/browse/
The problem is, I see a lot of repeated code, which seems pretty inefficient. There's 4 filters - leastrec (least recent), mostrec, leastpop (least popular) and mostpop, and I've had to make a JQuery function for each of them, even though they all do pretty similar things. Is there any way I can configure the JQuery to take parameters, and reduce it to one function?
Here's what they look like:
<script>
<!--
var $j = jQuery.noConflict();
$j(function() {
$j(".mostrec").click(function(evt) {
$j("#1").load("content.php?order=most&f=recent")
evt.preventDefault();
})
})
//-->
</script>
<script>
<!--
var $j = jQuery.noConflict();
$j(function() {
$j(".leastrec").click(function(evt) {
$j("#1").load("content.php?order=least&f=recent")
evt.preventDefault();
})
})
//-->
</script>
<script>
<!--
var $j = jQuery.noConflict();
$j(function() {
$j(".mostpop").click(function(evt) {
$j("#2").load("content.php?order=most&f=popular")
evt.preventDefault();
})
})
//-->
</script>
<script>
<!--
var $j = jQuery.noConflict();
$j(function() {
$j(".leastpop").click(function(evt) {
$j("#2").load("content.php?order=least&f=popular")
evt.preventDefault();
})
})
//-->
</script>
With each link having the relative #id ("recent" or "popular" column), and filter (least or most).
But I notice they're all activated by different link objects, maybe could cut it down to 2 at best?
Or even, would it be better to put them all in 1 function that waits on all 4?
Any help is greatly appreciated.