$(function() {
  var pageToFetch = 2;

  $(".more").click(function() {
    $(this).addClass("loading");
    $.get("/home/mock_set", {page: pageToFetch}, function(data) {
      $(".more").removeClass("loading");
      if (data.trim().length > 0) {
        $(data).insertBefore('.more');
      }
      if (pageToFetch === TOTAL_PAGES) {
        $(".more").hide();
      }
      pageToFetch++;
    });
  });

  $('#show_all_projects').click(function(evt) {
    evt.preventDefault();
    $('#all_projects').show();
    $('#show_all_projects').hide();
  });

  $('.project_filter').keyup(function() {
    var projects = $('.project_list li');
    var filter = $.trim($(this).val());
    projects.show();
    if (filter) {
      filter = new RegExp(filter ,'i');
      projects
        .filter(function() { return !filter.test($(this).text()); })
        .hide();
    }
  });
});

$(function() {
  var pageToFetch = 2;
  var prevQueryLength = 0;

  $(".more").click(function() {
    $(this).addClass("loading");
    $.get("/home/mock_set", {page: pageToFetch}, function(data) {
      $(".more").removeClass("loading");
      if (data.trim().length > 0) {
        $(data).insertBefore('.more');
      }
      if (pageToFetch === TOTAL_PAGES) {
        $(".more").hide();
      }
      pageToFetch++;
    });
  });

  $('#show_all_projects').click(function(evt) {
    evt.preventDefault();
    $('#all_projects').show();
    $('#show_all_projects').hide();
  });

  $('.project_filter').keyup(function() {
    var $projects = $('.project_list li');
    var filter = $.trim($(this).val());

    if (filter) {
      filterRegexp = new RegExp(filter ,'i');
      $projects
        .filter(':visible')
        .filter(function() { return !filterRegexp.test(this.textContent); })
        .hide();

      if (filter.length <= prevQueryLength) {
        $projects
          .filter(':hidden')
          .filter(function() { return filterRegexp.test(this.textContent); })
          .show();
      }
    } else {
      $projects.show();
    }

    prevQueryLength = filter.length;
  });
});

Improve mockr project search speed
Improve mockr project search speed

As a hackathon project, we use some smarter search techniques to hide
and show fewer list elements when each search is performed. For each
keystroke, this narrows down or broadens the existing list instead of
hiding and showing everything.

This is motivated by the slowdown in speed with large quantities of
projects.

Change-Id: I6f5e916c2f2ac1a8a4e339e69116a513a23ac0da
Reviewed-on: https://gerrit.causes.com/18733
Reviewed-by: Joe Lencioni <1dd72cf724deaab5db236f616560fc7067b734e1@causes.com>
Tested-by: Tom Dooner <b3e827da77b8b5a24f08875e81b25cd8f6ab5d10@causes.com>
