Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save cdmwebs/1172174 to your computer and use it in GitHub Desktop.

Select an option

Save cdmwebs/1172174 to your computer and use it in GitHub Desktop.

Revisions

  1. Chris Moore revised this gist Aug 26, 2011. 1 changed file with 30 additions and 12 deletions.
    42 changes: 30 additions & 12 deletions losangeles.craigslist.org.js
    Original file line number Diff line number Diff line change
    @@ -4,17 +4,35 @@

    // NOTE: Requires dotjs.

    var markup = '| <label for="result-search">Filter</label> <input type="text" name="result-search" id="result-search" />';
    $("blockquote div").append(markup);
    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 = {};

    $("#result-search").live("keyup", function() {
    var results = $("p.row"),
    search = this.value,
    searchExp = new RegExp(search, "gi");
    filterResults = function(searchString) {
    var searchExpression = new RegExp(searchString, "gi"),
    results = $("p.row");
    results.show().filter(function() {
    if(!$(this).text().match(searchExpression)) { $(this).hide(); }
    });
    }

    results.show().filter(function() {
    if(!$(this).text().match(searchExp)) {
    $(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;
    });
    }
  2. Chris Moore revised this gist Aug 25, 2011. 1 changed file with 12 additions and 21 deletions.
    33 changes: 12 additions & 21 deletions losangeles.craigslist.org.js
    Original file line number Diff line number Diff line change
    @@ -4,26 +4,17 @@

    // NOTE: Requires dotjs.

    var searchBox = $('<input type="text" id="result-search" />')
    var markup = '| <label for="result-search">Filter</label> <input type="text" name="result-search" id="result-search" />';
    $("blockquote div").append(markup);

    $("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()
    }
    })
    $("#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();
    }
    });
    });
  3. @ajsharp ajsharp renamed this gist Aug 25, 2011. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions gistfile1..js → losangeles.craigslist.org.js
    Original 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)
  4. @ajsharp ajsharp created this gist Aug 25, 2011.
    27 changes: 27 additions & 0 deletions gistfile1..js
    Original 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()
    }
    })