add change()

This commit is contained in:
James Campos 2010-04-28 00:45:32 -07:00
parent 5bcb903bac
commit 1be8310310
2 changed files with 40 additions and 18 deletions

View File

@ -154,6 +154,8 @@ filterSingle: (table, filter) ->
filterAll: -> filterAll: ->
#save current filters
#this should be in its own function to play nice with change()
filter: {} filter: {}
inputs: $$('input', box) inputs: $$('input', box)
for input in inputs for input in inputs
@ -162,11 +164,12 @@ filterAll: ->
filters[select.value]: filter filters[select.value]: filter
GM_setValue('filters', JSON.stringify(filters)) GM_setValue('filters', JSON.stringify(filters))
#so ugly #better way of doing this?
compiled: filters compiled: {}
for filter of compiled for filter of filters
for field of compiled[filter] compiled[filter]: {}
compiled[filter][field]: new RegExp(compiled[filter][field], 'i') for field of filters[filter]
compiled[filter][field]: new RegExp(filters[filter][field], 'i')
tables: reset() tables: reset()
for table in tables for table in tables
@ -268,6 +271,13 @@ options: ->
document.body.appendChild(opt) document.body.appendChild(opt)
change: ->
filter: filters[@value]
inputs: $$('input', box)
for input in inputs
input.value: filter[input.name] || ''
box: tag('div') box: tag('div')
box.id: 'box' box.id: 'box'
box.className: GM_getValue('className', 'reply') box.className: GM_getValue('className', 'reply')
@ -279,6 +289,7 @@ bar.addEventListener('mousedown', mousedown, true)
box.appendChild(bar) box.appendChild(bar)
select: tag('select') select: tag('select')
select.addEventListener('change', change, true)
filters: JSON.parse(GM_getValue('filters', '{ "hide": {} }')) filters: JSON.parse(GM_getValue('filters', '{ "hide": {} }'))
for filter of filters for filter of filters
option: tag('option') option: tag('option')
@ -286,9 +297,6 @@ for filter of filters
select.appendChild(option) select.appendChild(option)
box.appendChild(select) box.appendChild(select)
#currently displayed filter
filter: filters[select.value]
fields: [ fields: [
'Name', 'Name',
'Tripcode', 'Tripcode',
@ -302,13 +310,14 @@ for field in fields
label: tag('label') label: tag('label')
label.textContent: field label.textContent: field
input: tag('input') input: tag('input')
input.value: filter[field] || ''
input.name: field input.name: field
input.addEventListener('keydown', keydown, true) input.addEventListener('keydown', keydown, true)
label.appendChild(input) label.appendChild(input)
div.appendChild(label) div.appendChild(label)
box.appendChild(div) box.appendChild(div)
change.call(select)
div: tag('div') div: tag('div')
div.className: 'bottom' div.className: 'bottom'
for name in ['apply', 'reset', 'options', 'autohide'] for name in ['apply', 'reset', 'options', 'autohide']

View File

@ -1,5 +1,5 @@
(function(){ (function(){
var $, $$, _a, _b, _c, _d, _e, _f, _g, a, addClass, autoHide, bar, box, cancel, div, f, field, fields, filter, filterAll, filterSingle, filters, inBefore, input, keydown, label, mousedown, mousemove, mouseup, move, name, option, options, position, remove, reset, save, select, tag, text, x; var $, $$, _a, _b, _c, _d, _e, _f, _g, a, addClass, autoHide, bar, box, cancel, change, div, f, field, fields, filter, filterAll, filterSingle, filters, inBefore, input, keydown, label, mousedown, mousemove, mouseup, move, name, option, options, position, remove, reset, save, select, tag, text, x;
var __hasProp = Object.prototype.hasOwnProperty; var __hasProp = Object.prototype.hasOwnProperty;
x = function x(path, root) { x = function x(path, root) {
root = root || document.body; root = root || document.body;
@ -185,6 +185,8 @@ display: none; \
}; };
filterAll = function filterAll() { filterAll = function filterAll() {
var _a, _b, _c, _d, _e, _f, _g, _h, _i, compiled, field, filter, imagesCount, input, inputs, table, tables, value; var _a, _b, _c, _d, _e, _f, _g, _h, _i, compiled, field, filter, imagesCount, input, inputs, table, tables, value;
//save current filters
//this should be in its own function to play nice with change()
filter = {}; filter = {};
inputs = $$('input', box); inputs = $$('input', box);
_b = inputs; _b = inputs;
@ -194,13 +196,14 @@ display: none; \
} }
filters[select.value] = filter; filters[select.value] = filter;
GM_setValue('filters', JSON.stringify(filters)); GM_setValue('filters', JSON.stringify(filters));
//so ugly //better way of doing this?
compiled = filters; compiled = {};
_d = compiled; _d = filters;
for (filter in _d) { if (__hasProp.call(_d, filter)) { for (filter in _d) { if (__hasProp.call(_d, filter)) {
_e = compiled[filter]; compiled[filter] = {};
_e = filters[filter];
for (field in _e) { if (__hasProp.call(_e, field)) { for (field in _e) { if (__hasProp.call(_e, field)) {
compiled[filter][field] = new RegExp(compiled[filter][field], 'i'); compiled[filter][field] = new RegExp(filters[filter][field], 'i');
}} }}
}} }}
tables = reset(); tables = reset();
@ -307,6 +310,17 @@ display: none; \
return document.body.appendChild(opt); return document.body.appendChild(opt);
} }
}; };
change = function change() {
var _a, _b, _c, _d, filter, input, inputs;
filter = filters[this.value];
inputs = $$('input', box);
_a = []; _c = inputs;
for (_b = 0, _d = _c.length; _b < _d; _b++) {
input = _c[_b];
_a.push((input.value = filter[input.name] || ''));
}
return _a;
};
box = tag('div'); box = tag('div');
box.id = 'box'; box.id = 'box';
box.className = GM_getValue('className', 'reply'); box.className = GM_getValue('className', 'reply');
@ -316,6 +330,7 @@ display: none; \
bar.addEventListener('mousedown', mousedown, true); bar.addEventListener('mousedown', mousedown, true);
box.appendChild(bar); box.appendChild(bar);
select = tag('select'); select = tag('select');
select.addEventListener('change', change, true);
filters = JSON.parse(GM_getValue('filters', '{ "hide": {} }')); filters = JSON.parse(GM_getValue('filters', '{ "hide": {} }'));
_a = filters; _a = filters;
for (filter in _a) { if (__hasProp.call(_a, filter)) { for (filter in _a) { if (__hasProp.call(_a, filter)) {
@ -324,8 +339,6 @@ display: none; \
select.appendChild(option); select.appendChild(option);
}} }}
box.appendChild(select); box.appendChild(select);
//currently displayed filter
filter = filters[select.value];
fields = ['Name', 'Tripcode', 'Email', 'Subject', 'Comment', 'File']; fields = ['Name', 'Tripcode', 'Email', 'Subject', 'Comment', 'File'];
_c = fields; _c = fields;
for (_b = 0, _d = _c.length; _b < _d; _b++) { for (_b = 0, _d = _c.length; _b < _d; _b++) {
@ -334,13 +347,13 @@ display: none; \
label = tag('label'); label = tag('label');
label.textContent = field; label.textContent = field;
input = tag('input'); input = tag('input');
input.value = filter[field] || '';
input.name = field; input.name = field;
input.addEventListener('keydown', keydown, true); input.addEventListener('keydown', keydown, true);
label.appendChild(input); label.appendChild(input);
div.appendChild(label); div.appendChild(label);
box.appendChild(div); box.appendChild(div);
} }
change.call(select);
div = tag('div'); div = tag('div');
div.className = 'bottom'; div.className = 'bottom';
_f = ['apply', 'reset', 'options', 'autohide']; _f = ['apply', 'reset', 'options', 'autohide'];