Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
gins0023 committed Jan 24, 2014
1 parent 145032b commit 96e43d0
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions backgrid-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@
*/
placeholder: null,

/**
@property [wait=false] The time in milliseconds to wait since the last
change to the search box's value before searching. This value can be
adjusted depending on how often the search box is used and how large the
search index is. For ServerSideFilter this is turned off by default.
*/
wait: false,

/**
@param {Object} options
@param {Backbone.Collection} options.collection
Expand All @@ -72,6 +80,12 @@
this.name = options.name || this.name;
this.placeholder = options.placeholder || this.placeholder;
this.template = options.template || this.template;
this.wait = options.wait || this.wait;

if (this.wait !== false) {
this.events["keydown input[type=search]"] = "search";
this._debounceMethods(["search", "clear"]);
}

// Persist the query on pagination
var collection = this.collection, self = this;
Expand All @@ -83,7 +97,20 @@
};
}
},

_debounceMethods: function(methodNames) {
if (_.isString(methodNames)) methodNames = [methodNames];

this.undelegateEvents();

for (var i = 0, l = methodNames.length; i < l; i++) {
var methodName = methodNames[i];
var method = this[methodName];
this[methodName] = _.debounce(method, this.wait);
}

this.delegateEvents();
},
/**
Event handler. Show the clear button when the search box has text, hide
it otherwise.
Expand Down Expand Up @@ -248,20 +275,6 @@
});
},

_debounceMethods: function (methodNames) {
if (_.isString(methodNames)) methodNames = [methodNames];

this.undelegateEvents();

for (var i = 0, l = methodNames.length; i < l; i++) {
var methodName = methodNames[i];
var method = this[methodName];
this[methodName] = _.debounce(method, this.wait);
}

this.delegateEvents();
},

/**
Constructs a Javascript regular expression object for #makeMatcher.
Expand Down

0 comments on commit 96e43d0

Please sign in to comment.