Created
August 25, 2011 21:39
-
-
Save ajsharp/1172060 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. | |
// Cmd-F live search | |
var searchBox = $('<input type="text" id="result-search" />') | |
$("h4.ban:first").before(searchBox) | |
$("#result-search").live("change", function() { | |
var results = $("p.row") | |
var search = this.value; | |
var searchExp = new RegExp(search, "gi") | |
console.log("search term:" + search) | |
if (search != "") { | |
results.filter(function() { | |
if(!$(this).text().match(searchExp)) { | |
$(this).hide() | |
} | |
}) | |
} else { | |
// show all for a blank search term | |
results.show() | |
} | |
}) | |
// Inline page loading | |
var fetchPage = function() { | |
if($(this).siblings('iframe.inline-page').length == 0) { | |
var newFrame = $('<iframe class="inline-page" width="90%" height="100%" src="'+this.href+'" style="display:none;"></iframe>') | |
$(this).parents("p.row").append(newFrame) | |
} | |
$(this).siblings('iframe.inline-page').slideDown() | |
return false; | |
} | |
var hidePage = function() { | |
$(this).siblings("iframe.inline-page").slideUp(); | |
} | |
$("p.row a").toggle(fetchPage, hidePage) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment