1/** 2 * fastLiveFilter jQuery plugin 1.0.3 3 * 4 * Copyright (c) 2011, Anthony Bush 5 * License: <http://www.opensource.org/licenses/bsd-license.php> 6 * Project Website: http://anthonybush.com/projects/jquery_fast_live_filter/ 7 **/ 8 9jQuery.fn.fastLiveFilter = function(list, options) { 10 // Options: input, list, timeout, callback 11 options = options || {}; 12 list = jQuery(list); 13 var input = this; 14 var lastFilter = ''; 15 var timeout = options.timeout || 0; 16 var callback = options.callback || function() {}; 17 18 var keyTimeout; 19 20 // NOTE: because we cache lis & len here, users would need to re-init the plugin 21 // if they modify the list in the DOM later. This doesn't give us that much speed 22 // boost, so perhaps it's not worth putting it here. 23 var lis = list.children(); 24 var len = lis.length; 25 var oldDisplay = len > 0 ? lis[0].style.display : "block"; 26 callback(len); // do a one-time callback on initialization to make sure everything's in sync 27 28 input.change(function() { 29 // var startTime = new Date().getTime(); 30 var filter = input.val().toLowerCase(); 31 var li, innerText; 32 var numShown = 0; 33 for (var i = 0; i < len; i++) { 34 li = lis[i]; 35 innerText = !options.selector ? 36 (li.textContent || li.innerText || "") : 37 $(li).find(options.selector).text(); 38 39 if (innerText.toLowerCase().indexOf(filter) >= 0) { 40 if (li.style.display == "none") { 41 li.style.display = oldDisplay; 42 } 43 numShown++; 44 } else { 45 if (li.style.display != "none") { 46 li.style.display = "none"; 47 } 48 } 49 } 50 callback(numShown); 51 // var endTime = new Date().getTime(); 52 // console.log('Search for ' + filter + ' took: ' + (endTime - startTime) + ' (' + numShown + ' results)'); 53 return false; 54 }).keydown(function() { 55 clearTimeout(keyTimeout); 56 keyTimeout = setTimeout(function() { 57 if( input.val() === lastFilter ) return; 58 lastFilter = input.val(); 59 input.change(); 60 }, timeout); 61 }); 62 return this; // maintain jQuery chainability 63}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.