-
Notifications
You must be signed in to change notification settings - Fork 4
/
admin-scripts.js
30 lines (26 loc) · 990 Bytes
/
admin-scripts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
jQuery.fn.filterByText = function(textbox) {
return this.each(function() {
var select = this;
var options = [];
jQuery(select).find('option').each(function() {
options.push({value: jQuery(this).val(), text: jQuery(this).text()});
});
jQuery(select).data('options', options);
jQuery(textbox).bind('change keyup', function() {
var options = jQuery(select).empty().data('options');
var search = jQuery.trim(jQuery(this).val());
var regex = new RegExp(search,"gi");
jQuery.each(options, function(i) {
var option = options[i];
if(option.text.match(regex) !== null) {
jQuery(select).append(
jQuery('<option>').text(option.text).val(option.value)
);
}
});
});
});
};
jQuery(function() {
jQuery('select').filterByText(jQuery('#filter'));
});