jquery live filter based on content and tags -
i'm using jquery live filter plugin:
(function($){ $.fn.livefilter = function(inputel, filterel, options){ var defaults = { filterchildselector: null, filter: function(el, val){ return $(el).text().touppercase().indexof(val.touppercase()) >= 0; }, before: function(){}, after: function(){} }; var options = $.extend(defaults, options); var el = $(this).find(filterel); if (options.filterchildselector) el = el.find(options.filterchildselector); var filter = options.filter; $(inputel).keyup(function(){ var val = $(this).val(); var contains = el.filter(function(){ return filter(this, val); }); var containsnot = el.not(contains); if (options.filterchildselector){ contains = contains.parents(filterel); containsnot = containsnot.parents(filterel).hide(); } options.before.call(this, contains, containsnot); contains.show(); containsnot.hide(); if (val === '') { contains.show(); containsnot.show(); } options.after.call(this, contains, containsnot); }); } })(jquery);
what want filter based on tags too, list gets filtered data-tag attribute of each element. how html looks:
<li><a href="#" data-tags="tag1">content</a></li>
currently filters based on content of tags, need data-tags involved in filter too.
here fiddle: http://jsfiddle.net/br7ke/
pass filter options plugins return elements filtering text , data-tag
try this
$('#livefilter-list').livefilter('#livefilter-input', 'li', { filterchildselector: 'a', filter: function(el, val){ return $(el).data('tags') == val || $(el).text().touppercase().indexof(val.touppercase()) >= 0; }, });
no need modify core plugins...
Comments
Post a Comment