-
-
Save cdmwebs/1172174 to your computer and use it in GitHub Desktop.
Craigslist live filtering
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Adds a live filter box to the results screen on craigslist | |
// that filters the results that are currently on the page by | |
// the search term. Like Cmd-F, but better. | |
// NOTE: Requires dotjs. | |
if (window.location.pathname.match(/\/search\//) && !$('body').html().match(/Nothing found for that search/)) { | |
var searchHash = window.location.hash, | |
searchString = searchHash.split("/")[1], | |
filterResults = {}, | |
addSearchField = {}; | |
filterResults = function(searchString) { | |
var searchExpression = new RegExp(searchString, "gi"), | |
results = $("p.row"); | |
results.show().filter(function() { | |
if(!$(this).text().match(searchExpression)) { $(this).hide(); } | |
}); | |
} | |
addSearchField = function() { | |
var markup = '| <label for = "result-search">Filter</label> <input type = "text" name = "result-search" id = "result-search" />'; | |
$("blockquote div").first().append(markup); | |
} | |
addSearchField(); | |
if (searchString !== "") { | |
filterResults(searchString); | |
$('#result-search').val(searchString).focus(); | |
} | |
$("#result-search").live("keyup", function() { | |
searchString = $(this).val(); | |
filterResults(searchString); | |
if (searchString !== "") window.location.hash = "search/" + searchString; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment