var Filter; var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; Filter = (function() { function Filter(options) { this.list = options.list; this.icon = options.icon; this.form = options.form; this.attrs = options.attrs; this.open = options.open; this.close = options.close; this.draw(); } Filter.prototype.draw = function() { var form, text; $(this.icon).addClass('filter-button'); form = $('
').appendTo(this.form); text = $('').appendTo(form); new Button(this.icon, ICONS.search, { scale: 0.5, translation: '-8 -8' }); form.submit(function() { return false; }); text.keyup(__bind(function() { return this.filter(text); }, this)); text.change(__bind(function() { return this.filter(text); }, this)); text.click(__bind(function() { return this.filter(text); }, this)); return $(this.icon).click(__bind(function() { if (form.is(':hidden')) { this.filter(text); form.show(); if (this.open) { return this.open(); } } else { form.hide(); form[0].reset(); this.filter(text); if (this.close) { return this.close(); } } }, this)); }; Filter.prototype.filter = function(input) { var test, text; text = input.val().toLowerCase(); if (text === '') { $('li', this.list).show(); return; } test = function(node, attr) { var val; val = (node.attr(attr) || '').toLowerCase(); return val.indexOf(text) !== -1; }; return $('li', this.list).each(__bind(function(ix, node) { var attr, matches; node = $(node); matches = (function() { var _i, _len, _ref, _results; _ref = this.attrs; _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { attr = _ref[_i]; if (test(node, attr)) { _results.push(true); } } return _results; }).call(this); if (matches.length > 0) { return node.show(); } else { return node.hide(); } }, this)); }; return Filter; })();