1/* Highlight search query by wrapping searched words in <mark> tag 2 * 3 * Search results are recognized by class "hentry". If not, we search for "#content .post" 4 * 5 */ 6function highlight_searchquery(term){ 7 $j = jQuery; 8 $class_result = ".hentry"; 9 if($j($class_result).length == 0){ 10 $class_result = "#content .post"; 11 } 12 13 $j($class_result).each(function(){ 14 var regex = new RegExp('(<[^>]*>)|('+ term.replace(/([-.*+?^${}()|[\]\/\\])/g,"\\$1") +')', true ? 'ig' : 'g'); 15 $j(this).html($j(this).html().replace(regex, function(a, b, c){ 16 if (jQuery.support.opacity) { 17 return (a.charAt(0) == '<') ? a : '<mark class="highlight">' + c + '</mark>'; 18 } else { 19 return (a.charAt(0) == '<') ? a : '<span class="highlight">' + c + '</span>'; 20 } 21 })); 22 }); 23} 24 25function asf_dosearch(input){ 26 var val = input.val(); 27 if(val != ''){ 28 input.addClass("loading"); 29 suggestion = input.next("span"); 30 31 if(_jAjax != null){ 32 _jAjax.abort(); // abort any waiting ajax request 33 } 34 35 // get current selected categories & tags 36 var cat = ''; 37 var tag = ''; 38 var form = jQuery(input).parent().parent().parent(); 39 40 cat = jQuery('#s-cat',form).val(); 41 42 if(jQuery('.filtered',form).length > 0){ 43 tag = jQuery('.filtered',form).attr('data-slug'); 44 } 45 46 _jAjax = jQuery.post( 47 asf.ajaxurl, 48 { 49 action : 'asf_suggestion', 50 // other parameters can be added along with "action" 51 s : val, 52 cat: cat, 53 tag: tag 54 }, 55 function( response ) { 56 if(jQuery('li',response).length > 0){ 57 suggestion.html(response).css({"display":"block"}); 58 input.removeClass("loading"); 59 60 // Handle hover event on suggestion list 61 jQuery("li",response).each(function(){ 62 jQuery(this).hover(function(){ 63 var active = jQuery(".active",jQuery(this).parent()); 64 active.removeClass("active"); 65 jQuery(this).addClass("active"); 66 }); 67 }); 68 } else { 69 suggestion.css({'display':'none'}); 70 } 71 } 72 ); 73 } 74} 75 76/* Params 77 * @suggestion: The <span class="suggestion"> tag 78 */ 79function asf_suggestion_movedown(suggestion){ 80 $j = jQuery; 81 // go down 82 // get current active item 83 var active = $j("li.active",suggestion); 84 if(active.length > 0){ 85 // get number of items are currently hidden 86 var hidden = - suggestion.children("ul").css("marginTop").replace("px","") / _liHeight; 87 // get total number of items 88 var total = $j("li",suggestion).length; 89 var index = active.index(); 90 if(index < total - 1){ 91 active.removeClass("active"); 92 active.next().addClass("active"); 93 if(index == (hidden + _visibleItems - 1)){ 94 // move the list (minus) up 95 suggestion.children("ul").css("marginTop", - (hidden + 1) * _liHeight); 96 } 97 } 98 } else { 99 $j("li:eq(0)",suggestion).addClass("active"); 100 } 101} 102 103/* Params 104 * @suggestion: The <span class="suggestion"> tag 105 */ 106function asf_suggestion_moveup(suggestion){ 107 $j = jQuery; 108 // go up 109 // get current active item 110 var active = $j("li.active",suggestion); 111 if(active.length > 0){ 112 // get number of items are currently hidden 113 var hidden = - suggestion.children("ul").css("marginTop").replace("px","") / _liHeight; 114 // get total number of items 115 var total = $j("li",suggestion).length; 116 var index = active.index(); 117 if(index > 0){ 118 active.removeClass("active"); 119 active.prev().addClass("active"); 120 if(index == hidden){ 121 // move the list (minus) down 122 suggestion.children("ul").css("marginTop", - (hidden - 1) * _liHeight); 123 } 124 } 125 } 126} 127 128/* Params 129 * @obj: <a> item 130 */ 131function suggestion_onItemClick(obj){ 132 var txt = jQuery(obj).html(); 133 var r = /<[\/](\w+)[^>]*>/gi; 134 txt = txt.replace(r,"");// remove any tag 135 jQuery(obj).parent().parent().parent().prev().val(txt); 136 jQuery(obj).parent().parent().parent().parent().parent().parent().submit(); 137} 138 139var _jAjax = null; 140var _liHeight = 29; 141var _visibleItems = 5; // number of visible items 142jQuery(document).ready(function($){ 143 if($("form .suggestion").length > 0){ 144 $(".ss").each(function(){ 145 suggestion = $(this).parent().children(".suggestion"); 146 if(suggestion.length > 0){ 147 // get max height of suggestion viewport 148 suggestion.css("maxHeight",_visibleItems * _liHeight); 149 suggestion.bind('mousewheel', function(e, delta, deltaX, deltaY) { 150 if(suggestion.is(":visible")){ 151 if(deltaY == 1){ 152 // move up 153 asf_suggestion_moveup(suggestion); 154 } else { 155 // move down 156 asf_suggestion_movedown(suggestion); 157 } 158 159 // stop bubbling event 160 e = e || window.event; 161 if (e.preventDefault) 162 e.preventDefault(); 163 e.returnValue = false;
164 } 165 }); 166 } 167 }); 168 169 // Handle key press on search textbox 170 $(".ss").keypress(function(evt){ 171 if(evt.which != 0){ 172 asf_dosearch($(this)); 173 } 174 }).keyup(function(evt){ 175 if(evt.keyCode == 8 || evt.keyCode == 46){ 176 asf_dosearch($(this)); 177 } 178 }).focus(function(){ 179 suggestion = $(this).parent().children(".suggestion"); 180 if(suggestion === 'undefined' || !suggestion.is(":visible")){ 181 asf_dosearch($(this)); 182 } 183 }); 184 185 // close the suggestion list if click outside 186 window.addEventListener('click', function(e){ 187 if ($('.widget-asf .suggestion').has(e.target).length || $('.widget-asf .searchtext').has(e.target).length){ 188 // Clicked in box 189 // do nothing 190 } else{ 191 // Clicked outside the box 192 $('.widget-asf .suggestion').hide(); 193 } 194 }); 195 196 // Handle Arrow key on suggestion list 197 $(".ss").keydown(function(evt){ 198 suggestion = $(this).parent().children(".suggestion"); 199 if(suggestion !== 'undefined' && suggestion.is(":visible")){ 200 if(evt.keyCode == 38){ 201 asf_suggestion_moveup(suggestion); 202 } else if(evt.keyCode == 40){ 203 asf_suggestion_movedown(suggestion); 204 } 205 } 206 }); 207 } 208});
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.