Skip to content

Instantly share code, notes, and snippets.

@bmavity
Forked from just3ws/Refactored.js
Created April 14, 2011 18:45
Show Gist options
  • Save bmavity/920186 to your computer and use it in GitHub Desktop.
Save bmavity/920186 to your computer and use it in GitHub Desktop.
// assumes that the title content is lowercase.
// I'm aware of the duplication of some functionality.
// this is just a POC for the work I'm doing on ccs. :)
$(function() {
var $allSessions = $('#content .show'),
elementsAndTitles = $.map($allSessions, function(sessionElement) {
var $session = $('h3 a', sessionElement);
return {
$session: $session,
title: $session.text() // may need to use .html()
}
});
$("<input>", {
"placeholder" : "type to filter by title",
class: "search",
keyup: function(eventData) {
var searchTerm = this.val(),
matchingTitlesAndElements = $.grep(elementsAndTitles, function(elementAndTitle) {
return elementAndTitle.title.indexOf(searchTerm) !== -1;
}) ;
$allSessions.hide();
$.each(matchingTitlesAndElements, function() {
this.$session.show();
});
}
}).appendTo("#content h4");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment