-
-
Save cdmwebs/1172174 to your computer and use it in GitHub Desktop.
Revisions
-
Chris Moore revised this gist
Aug 26, 2011 . 1 changed file with 30 additions and 12 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -4,17 +4,35 @@ // 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; }); } -
Chris Moore revised this gist
Aug 25, 2011 . 1 changed file with 12 additions and 21 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -4,26 +4,17 @@ // NOTE: Requires dotjs. var markup = '| <label for="result-search">Filter</label> <input type="text" name="result-search" id="result-search" />'; $("blockquote div").append(markup); $("#result-search").live("keyup", function() { var results = $("p.row"), search = this.value, searchExp = new RegExp(search, "gi"); results.show().filter(function() { if(!$(this).text().match(searchExp)) { $(this).hide(); } }); }); -
ajsharp renamed this gist
Aug 25, 2011 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -2,6 +2,8 @@ // that filters the results that are currently on the page by // the search term. Like Cmd-F, but better. // NOTE: Requires dotjs. var searchBox = $('<input type="text" id="result-search" />') $("h4.ban:first").before(searchBox) -
ajsharp created this gist
Aug 25, 2011 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ // 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. 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() } })