Author: sevein
Date: Tue Mar 27 17:36:15 2012
New Revision: 11296
Log:
Cleanups, add timer to avoid query the server while typing
Modified:
trunk/plugins/qtDominionPlugin/js/dominion.js
Modified: trunk/plugins/qtDominionPlugin/js/dominion.js
==============================================================================
--- trunk/plugins/qtDominionPlugin/js/dominion.js Tue Mar 27 16:27:36
2012 (r11295)
+++ trunk/plugins/qtDominionPlugin/js/dominion.js Tue Mar 27 17:36:15
2012 (r11296)
@@ -14,6 +14,7 @@
this.$menu = $('<div id="search-suggestions"></div>').appendTo('body');
this.shown = false;
this.source = element.closest('form').data('autocomplete');
+ this.timeout = 150;
this.listen();
};
@@ -22,8 +23,6 @@
constructor: Autocomplete,
- select: function() { },
-
show: function()
{
var pos = $.extend({}, this.$element.offset(), {
@@ -38,6 +37,7 @@
this.$menu.show();
this.shown = true;
+
return this;
},
@@ -45,6 +45,7 @@
{
this.$menu.hide();
this.shown = false;
+
return this;
},
@@ -52,6 +53,11 @@
{
this.query = this.$element.val();
+ if (!this.query)
+ {
+ return this.shown ? this.hide() : this;
+ }
+
$.ajax(this.source,
{
context: this,
@@ -69,14 +75,8 @@
this.hide();
}
});
-
- // return this.render(html).show();
},
- // matcher
- // sorter
- // highlighter
-
render: function (html)
{
this.$menu.html(html);
@@ -84,8 +84,8 @@
return this;
},
- next: function(event) { },
- prev: function(event) { },
+ next: function (e) { },
+ prev: function (e) { },
listen: function()
{
@@ -99,9 +99,7 @@
this.$element.on('keydown', $.proxy(this.keypress, this));
}
- this.$menu
- .on('click', $.proxy(this.click, this))
- .on('mouseenter', 'li', $.proxy(this.mouseenter, this))
+ this.$menu.on('mouseenter', 'li', $.proxy(this.mouseenter, this));
},
keyup: function (e)
@@ -131,7 +129,15 @@
break;
default:
- this.lookup();
+ if (this.timer)
+ {
+ clearTimeout(this.timer);
+ }
+ var self = this;
+ this.timer = setTimeout(function()
+ {
+ self.lookup();
+ }, this.timeout);
}
e.stopPropagation()
@@ -176,13 +182,6 @@
}, 150);
},
- click: function(e)
- {
- e.stopPropagation();
- e.preventDefault();
- this.select();
- },
-
mouseenter: function(e)
{
this.$menu.find('active').removeClass('active');
--
You received this message because you are subscribed to the Google Groups
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/qubit-commits?hl=en.