Permalink
Browse files

300ms delay on the search with dotimeout plugin

  • Loading branch information...
1 parent 9eb64b5 commit a8dcaa861ea67677fe7bfb75ef28add058de09e4 @mustardamus mustardamus committed Feb 1, 2010
Showing with 59 additions and 37 deletions.
  1. +3 −1 index.html
  2. +9 −0 js/jquery.ba-dotimeout.min.js
  3. +38 −36 js/main.js
  4. +9 −0 js/main.min.js
View
@@ -13,6 +13,7 @@
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/highlight.js"></script>
<script type="text/javascript" src="js/jquery.ba-bbq.min.js"></script>
+ <script type="text/javascript" src="js/jquery.ba-dotimeout.min.js"></script>
<script type="text/javascript" src="js/main.js"></script>
<!--<script type="text/javascript" src="js/main.min.js"></script>-->
</head>
@@ -83,7 +84,8 @@ <h2><span class="name">Credits</span><span class="returns">And props.</span></h2
<a href="http://jquery.com">jQuery</a>, <a href="http://api.jquery.com/">jQuery documentation</a>,
<a href="http://railsapi.com/">Rails API</a>,
<a href="http://devthought.com/blog/client-side/2009/04/javascript-regexp-based-highlighting-function-for-mootools-and-jquery/">Highlight Plugin</a>,
- <a href="http://benalman.com/projects/jquery-bbq-plugin/">BBQ Plugin</a>,
+ <a href="http://benalman.com/">'Cowboy' Ben Alman</a>: <a href="http://benalman.com/projects/jquery-bbq-plugin/">BBQ Plugin</a> /
+ <a href="http://benalman.com/projects/jquery-dotimeout-plugin/">doTimeout Plugin</a> / Feedback,
<a href="http://search.twitter.com/search?q=jqapi">Tweople for spreding the word and their feedback</a>, Beer. To be continued (hopefully).
</p>
</div>

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -196,45 +196,47 @@ $(document).ready(function() {
search_field.keyup(function(event) {
if(!checkKey(event.keyCode, false)) return false;
- var term = search_field.val();
+ search_field.doTimeout('text-type', 300, function() {
+ var term = search_field.val();
- results.html('');
-
- if(term.length) {
- results.show();
- static_el.hide();
-
- var last_pos = 100;
- var winner = $;
-
- $('.searchable', static_el).each(function() {
- var el = $(this);
- var daddy = el.parent().parent();
- var name = el.text();
- var pos = name.toLowerCase().indexOf(term.toLowerCase());
-
- if(pos != -1) {
- if(results.text().indexOf(name) == -1) {
- var lastli = jQuery('<li>', {
- 'class': 'sub',
- html: daddy.html()
- }).appendTo(results);
-
- if(pos < last_pos) {
- last_pos = pos;
- winner = lastli;
+ results.html('');
+
+ if(term.length) {
+ results.show();
+ static_el.hide();
+
+ var last_pos = 100;
+ var winner = $;
+
+ $('.searchable', static_el).each(function() {
+ var el = $(this);
+ var daddy = el.parent().parent();
+ var name = el.text();
+ var pos = name.toLowerCase().indexOf(term.toLowerCase());
+
+ if(pos != -1) {
+ if(results.text().indexOf(name) == -1) {
+ var lastli = jQuery('<li>', {
+ 'class': 'sub',
+ html: daddy.html()
+ }).appendTo(results);
+
+ if(pos < last_pos) {
+ last_pos = pos;
+ winner = lastli;
+ }
}
}
- }
- });
-
- results.prepend(winner).highlight(term, true, 'highlight').children('li:first').addClass('selected');
- zebraItems(results);
- bindItemClicks(results);
- } else { //empty search
- results.hide();
- static_el.show();
- }
+ });
+
+ results.prepend(winner).highlight(term, true, 'highlight').children('li:first').addClass('selected');
+ zebraItems(results);
+ bindItemClicks(results);
+ } else { //empty search
+ results.hide();
+ static_el.show();
+ }
+ });
});
});
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit a8dcaa8

Please sign in to comment.