Filter Your Ads on Classipress Dashboard - firestormcs Freebie
hey guys,
sorry, this is a re-post because like a bonehead i put it in the legacy forum. my bad
.
Anyhoo, here's some code that you can include on your site to let your users filter their ads in real time right on their dashboard. This is a simple tutorial that will give you the code and basic instructions on how to implement this mod. if you run into problems, PM me and i'll try to help as best i can but this mod is of course supplied without warranty.
This feature requires jQuery (already part of ClassiPress) and that JavaScript be enabled in your browser to function properly.
Here we go!
Open your 'tpl-dashboard.php' file from ClassiPress.
Look for the table around line 93:
Code:
<table border="0" cellpadding="4" cellspacing="1" class="tblwide" id="myads">...</table>
You'll need to add the 'ID' attribute ( id="myads" ) as shown above. This is important because it's how we're going to tell jQuery where the ads are.
copy and paste this line of code directly above it:
Code:
<h3 class="" id="adheader">Search Your Ads</h3>
This will be where the search field and heading will be located. jQuery will find it and create a field for you. if you want to add a search icon, you add this line:
Code:
<img src="<?php bloginfo('template_url'); ?>/images/search_16.png" class=""/>
And if you don't have any styles for the field, you can use this and modify to your taste (put it in your main style sheet style.css or whichever child theme stylesheet you are using):
Code:
input.filterinput {
border:1px solid #BBBBBB;
color:#4F4F4F;
margin:10px 0;
padding:6px;
width:289px;
}
where search_16.png is any16px by 16px search icon you choose.
Now that we have set up the heading and target for jQuery, we get to the code that performs the filtering. Paste this JavaScript code at the very bottom of your page just above the get_footer() function:
Code:
<script type="text/javascript">
// custom css expression for a case-insensitive contains()
//convert all text to uppercase then compare it
jQuery.expr[':'].Contains = function(a,i,m){
return (a.textContent || a.innerText || "").toUpperCase().indexOf(m[3].toUpperCase())>=0;
};
function listFilter(header, list) { // header is any element, list is an unordered list
// create and add the filter form to the header
var form = jQuery("<form>").attr({"class":"filterform","action":"#"}),
input = jQuery("<input>").attr({"class":"filterinput","type":"text"});
jQuery(form).append(input).appendTo(header);
//
jQuery(input).change( function () {
var filter = jQuery(this).val();
if(filter) {
// this finds all links in a list that contain the input,
// and hide the ones not containing the input while showing the ones that do
jQuery(list).find("td h3:not(:Contains(" + filter + "))").parent().parent().hide();
jQuery(list).find("td h3:Contains(" + filter + ")").parent().parent().fadeIn('medium');
} else {
jQuery(list).find("tr").fadeIn('medium');
}
return false;
}).keyup( function () {
// fire the above change event after every letter
jQuery(this).change();
});
}
//initiate the search form
jQuery(function () {
listFilter(jQuery("#adheader"), jQuery("#myads"));
});
</script>
That's it! You should now see a search box appear just above your ad listings with the title "Search your ads". Start typing a word and you should see your ads filter down to ones that match what you entered into the search field.
thanks again, and i hope you guys find this useful!