forked from honza/suggestr.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.suggestr.min.js
3 lines (3 loc) · 1.16 KB
/
jquery.suggestr.min.js
1
2
3
(function(d){var e={up:38,down:40,enter:13},g={listStyle:"none",backgroundColor:"#ececec"},h={listStyle:"none",backgroundColor:"#fff"},j={width:"200px",position:"absolute"};d.fn.suggestr=function(k){function l(b){var c=a.data("active"),b=b==e.up?c-1:c+1;-1<b&&b<a.children().length&&(a.children().each(function(a,b){d(b).css(h)}),d(a.children()[b]).css(g),a.data("active",b))}function i(){a.data("active",0);a.children().remove()}var a,c,f;c=this;a=d('<div id="suggestr-div"></div>');a.css(j);a.data("active",
0);a.delegate("li","mouseover",function(){d(this).css(g)});a.delegate("li","mouseout",function(){d(this).css(h)});a.delegate("li","click",function(){var a=d(this).text();c.val(a);i()});this.keyup(function(b){if(b.keyCode==e.enter)b=d(a.children()[a.data("active")]).text(),c.val(b),i();else{if(b.keyCode==e.up||b.keyCode==e.down)return l(b.keyCode),!1;a.children().remove();f=c.val().toLowerCase();f.length&&(d.each(k,function(b,c){if(c.toLowerCase().indexOf(f)>-1){var c=c.replace(RegExp("(?![^&;]+;)(?!<[^<>]*)("+
f+")(?![^<>]*>)(?![^&;]+;)","gi"),"<strong>$1</strong>"),e=d("<li>"+c+"</li>");d(e).css(h);a.append(e)}}),c.after(a),a.children().first().css(g))}})}})(jQuery);