A bit of cleanup of Rice.

This commit is contained in:
Zixaphir 2014-01-19 05:14:59 -07:00
parent a1a427dbda
commit b82ba8b620
5 changed files with 174 additions and 156 deletions

View File

@ -1,5 +1,5 @@
/* /*
* appchan x - Version 2.8.5 - 2014-01-18 * appchan x - Version 2.8.5 - 2014-01-19
* *
* Licensed under the MIT license. * Licensed under the MIT license.
* https://github.com/zixaphir/appchan-x/blob/master/LICENSE * https://github.com/zixaphir/appchan-x/blob/master/LICENSE

View File

@ -22,7 +22,7 @@
// ==/UserScript== // ==/UserScript==
/* /*
* appchan x - Version 2.8.5 - 2014-01-18 * appchan x - Version 2.8.5 - 2014-01-19
* *
* Licensed under the MIT license. * Licensed under the MIT license.
* https://github.com/zixaphir/appchan-x/blob/master/LICENSE * https://github.com/zixaphir/appchan-x/blob/master/LICENSE
@ -8561,7 +8561,7 @@
thread = _ref[_i]; thread = _ref[_i];
options.push($.el('option', { options.push($.el('option', {
value: thread, value: thread,
textContent: "Thread No." + thread textContent: "No." + thread
})); }));
} }
val = list.value; val = list.value;
@ -8571,7 +8571,10 @@
if (!list.value) { if (!list.value) {
return; return;
} }
return list.value = g.VIEW === 'thread' ? g.THREADID : 'new'; list.value = g.VIEW === 'thread' ? g.THREADID : 'new';
if ($.hasClass(list, 'riced')) {
return list.nextElementSibling.firstChild.textContent = list.options[list.selectedIndex].textContent;
}
}, },
dialog: function() { dialog: function() {
var check, dialog, elm, event, i, items, key, mimeTypes, name, node, nodes, save, value, _ref; var check, dialog, elm, event, i, items, key, mimeTypes, name, node, nodes, save, value, _ref;
@ -13369,15 +13372,66 @@
}; };
Rice = { Rice = {
ul: $.el('ul', {
id: "selectrice"
}),
init: function() { init: function() {
$.ready(function() { $.ready(this.initReady);
return Rice.nodes(d.body);
});
return Post.callbacks.push({ return Post.callbacks.push({
name: 'Rice Checkboxes', name: 'Rice Checkboxes',
cb: this.node cb: this.node
}); });
}, },
initReady: function() {
Rice.nodes(d.body);
return $.add(d.body, Rice.ul);
},
node: function() {
return Rice.checkbox($('.postInfo input', this.nodes.post));
},
nodes: function(root) {
var process;
root || (root = d.body);
process = Rice.process;
process($$('[type=checkbox]:not(.riced)', root), 'checkbox');
return process($$('select:not(.riced)', root), 'select');
},
process: function(items, type) {
var fn, item, _i, _len;
fn = Rice[type];
for (_i = 0, _len = items.length; _i < _len; _i++) {
item = items[_i];
fn(item);
}
},
cleanup: function() {
$.off(d, 'click scroll blur resize', Rice.cleanup);
$.rmAll(Rice.ul);
},
checkbox: function(input) {
var div;
if ($.hasClass(input, 'riced')) {
return;
}
$.addClass(input, 'riced');
div = $.el('div', {
className: 'rice'
});
div.check = input;
$.after(input, div);
return $.on(div, 'click', Rice.cb.check);
},
select: function(select) {
var div, _ref;
div = $.el('div', {
className: 'selectrice',
innerHTML: "<div>" + (((_ref = select.options[select.selectedIndex || '0']) != null ? _ref.textContent : void 0) || '') + "</div>"
});
$.on(div, 'click', Rice.cb.select);
$.on(div, 'keydown', Rice.cb.keybind);
$.after(select, div);
return $.addClass(select, 'riced');
},
cb: { cb: {
check: function(e) { check: function(e) {
e.preventDefault(); e.preventDefault();
@ -13399,12 +13453,7 @@
var bottom, clientHeight, left, li, nodes, option, select, style, top, ul, width, _i, _len, _ref, _ref1; var bottom, clientHeight, left, li, nodes, option, select, style, top, ul, width, _i, _len, _ref, _ref1;
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();
if (!(ul = Rice.ul, Rice)) { ul = Rice.ul;
Rice.ul = ul = $.el('ul', {
id: "selectrice"
});
$.add(d.body, ul);
}
if (ul.children.length > 0) { if (ul.children.length > 0) {
return Rice.cleanup(); return Rice.cleanup();
} }
@ -13430,50 +13479,6 @@
}); });
return $.on(d, 'click scroll blur resize', Rice.cleanup); return $.on(d, 'click scroll blur resize', Rice.cleanup);
} }
},
cleanup: function() {
$.off(d, 'click scroll blur resize', Rice.cleanup);
$.rmAll(Rice.ul);
},
nodes: function(root) {
var fn;
root || (root = d.body);
fn = function(items, type) {
var func, item, _i, _len;
func = Rice[type];
for (_i = 0, _len = items.length; _i < _len; _i++) {
item = items[_i];
func(item);
}
};
fn($$('[type=checkbox]:not(.riced)', root), 'checkbox');
return fn($$('select:not(.riced)', root), 'select');
},
node: function() {
return Rice.checkbox($('.postInfo input', this.nodes.post));
},
checkbox: function(input) {
var div;
if ($.hasClass(input, 'riced')) {
return;
}
$.addClass(input, 'riced');
div = $.el('div', {
className: 'rice'
});
div.check = input;
$.after(input, div);
return $.on(div, 'click', Rice.cb.check);
},
select: function(select) {
var div, _ref;
$.addClass(select, 'riced');
div = $.el('div', {
className: 'selectrice',
innerHTML: "<div>" + (((_ref = select.options[select.selectedIndex || '0']) != null ? _ref.textContent : void 0) || '') + "</div>"
});
$.on(div, "click", Rice.cb.select);
return $.after(select, div);
} }
}; };

View File

@ -1,6 +1,6 @@
// Generated by CoffeeScript // Generated by CoffeeScript
/* /*
* appchan x - Version 2.8.5 - 2014-01-18 * appchan x - Version 2.8.5 - 2014-01-19
* *
* Licensed under the MIT license. * Licensed under the MIT license.
* https://github.com/zixaphir/appchan-x/blob/master/LICENSE * https://github.com/zixaphir/appchan-x/blob/master/LICENSE
@ -8569,7 +8569,7 @@
thread = _ref[_i]; thread = _ref[_i];
options.push($.el('option', { options.push($.el('option', {
value: thread, value: thread,
textContent: "Thread No." + thread textContent: "No." + thread
})); }));
} }
val = list.value; val = list.value;
@ -8579,7 +8579,10 @@
if (!list.value) { if (!list.value) {
return; return;
} }
return list.value = g.VIEW === 'thread' ? g.THREADID : 'new'; list.value = g.VIEW === 'thread' ? g.THREADID : 'new';
if ($.hasClass(list, 'riced')) {
return list.nextElementSibling.firstChild.textContent = list.options[list.selectedIndex].textContent;
}
}, },
dialog: function() { dialog: function() {
var check, dialog, event, i, items, key, mimeTypes, name, node, nodes, save, value, _ref; var check, dialog, event, i, items, key, mimeTypes, name, node, nodes, save, value, _ref;
@ -13358,15 +13361,66 @@
}; };
Rice = { Rice = {
ul: $.el('ul', {
id: "selectrice"
}),
init: function() { init: function() {
$.ready(function() { $.ready(this.initReady);
return Rice.nodes(d.body);
});
return Post.callbacks.push({ return Post.callbacks.push({
name: 'Rice Checkboxes', name: 'Rice Checkboxes',
cb: this.node cb: this.node
}); });
}, },
initReady: function() {
Rice.nodes(d.body);
return $.add(d.body, Rice.ul);
},
node: function() {
return Rice.checkbox($('.postInfo input', this.nodes.post));
},
nodes: function(root) {
var process;
root || (root = d.body);
process = Rice.process;
process($$('[type=checkbox]:not(.riced)', root), 'checkbox');
return process($$('select:not(.riced)', root), 'select');
},
process: function(items, type) {
var fn, item, _i, _len;
fn = Rice[type];
for (_i = 0, _len = items.length; _i < _len; _i++) {
item = items[_i];
fn(item);
}
},
cleanup: function() {
$.off(d, 'click scroll blur resize', Rice.cleanup);
$.rmAll(Rice.ul);
},
checkbox: function(input) {
var div;
if ($.hasClass(input, 'riced')) {
return;
}
$.addClass(input, 'riced');
div = $.el('div', {
className: 'rice'
});
div.check = input;
$.after(input, div);
return $.on(div, 'click', Rice.cb.check);
},
select: function(select) {
var div, _ref;
div = $.el('div', {
className: 'selectrice',
innerHTML: "<div>" + (((_ref = select.options[select.selectedIndex || '0']) != null ? _ref.textContent : void 0) || '') + "</div>"
});
$.on(div, 'click', Rice.cb.select);
$.on(div, 'keydown', Rice.cb.keybind);
$.after(select, div);
return $.addClass(select, 'riced');
},
cb: { cb: {
check: function(e) { check: function(e) {
e.preventDefault(); e.preventDefault();
@ -13388,12 +13442,7 @@
var bottom, clientHeight, left, li, nodes, option, select, style, top, ul, width, _i, _len, _ref, _ref1; var bottom, clientHeight, left, li, nodes, option, select, style, top, ul, width, _i, _len, _ref, _ref1;
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();
if (!(ul = Rice.ul, Rice)) { ul = Rice.ul;
Rice.ul = ul = $.el('ul', {
id: "selectrice"
});
$.add(d.body, ul);
}
if (ul.children.length > 0) { if (ul.children.length > 0) {
return Rice.cleanup(); return Rice.cleanup();
} }
@ -13419,50 +13468,6 @@
}); });
return $.on(d, 'click scroll blur resize', Rice.cleanup); return $.on(d, 'click scroll blur resize', Rice.cleanup);
} }
},
cleanup: function() {
$.off(d, 'click scroll blur resize', Rice.cleanup);
$.rmAll(Rice.ul);
},
nodes: function(root) {
var fn;
root || (root = d.body);
fn = function(items, type) {
var func, item, _i, _len;
func = Rice[type];
for (_i = 0, _len = items.length; _i < _len; _i++) {
item = items[_i];
func(item);
}
};
fn($$('[type=checkbox]:not(.riced)', root), 'checkbox');
return fn($$('select:not(.riced)', root), 'select');
},
node: function() {
return Rice.checkbox($('.postInfo input', this.nodes.post));
},
checkbox: function(input) {
var div;
if ($.hasClass(input, 'riced')) {
return;
}
$.addClass(input, 'riced');
div = $.el('div', {
className: 'rice'
});
div.check = input;
$.after(input, div);
return $.on(div, 'click', Rice.cb.check);
},
select: function(select) {
var div, _ref;
$.addClass(select, 'riced');
div = $.el('div', {
className: 'selectrice',
innerHTML: "<div>" + (((_ref = select.options[select.selectedIndex || '0']) != null ? _ref.textContent : void 0) || '') + "</div>"
});
$.on(div, "click", Rice.cb.select);
return $.after(select, div);
} }
}; };

View File

@ -328,7 +328,7 @@ QR =
for thread in g.BOARD.threads.keys for thread in g.BOARD.threads.keys
options.push $.el 'option', options.push $.el 'option',
value: thread value: thread
textContent: "Thread No.#{thread}" textContent: "No.#{thread}"
val = list.value val = list.value
$.rmAll list $.rmAll list
$.add list, options $.add list, options
@ -339,6 +339,8 @@ QR =
g.THREADID g.THREADID
else else
'new' 'new'
list.nextElementSibling.firstChild.textContent = list.options[list.selectedIndex].textContent if $.hasClass list, 'riced'
dialog: -> dialog: ->
QR.nodes = nodes = QR.nodes = nodes =

View File

@ -1,12 +1,53 @@
Rice = Rice =
ul: $.el 'ul', id: "selectrice"
init: -> init: ->
$.ready -> $.ready @initReady
Rice.nodes d.body
Post.callbacks.push Post.callbacks.push
name: 'Rice Checkboxes' name: 'Rice Checkboxes'
cb: @node cb: @node
initReady: ->
Rice.nodes d.body
$.add d.body, Rice.ul
node: ->
Rice.checkbox $ '.postInfo input', @nodes.post
nodes: (root) ->
root or= d.body
{process} = Rice
process $$('[type=checkbox]:not(.riced)', root), 'checkbox'
process $$('select:not(.riced)', root), 'select'
process: (items, type) ->
fn = Rice[type]
fn item for item in items
return
cleanup: ->
$.off d, 'click scroll blur resize', Rice.cleanup
$.rmAll Rice.ul
return
checkbox: (input) ->
return if $.hasClass input, 'riced'
$.addClass input, 'riced'
div = $.el 'div', className: 'rice'
div.check = input
$.after input, div
$.on div, 'click', Rice.cb.check
select: (select) ->
div = $.el 'div',
className: 'selectrice'
innerHTML: "<div>#{select.options[select.selectedIndex or '0']?.textContent or ''}</div>"
$.on div, 'click', Rice.cb.select
$.on div, 'keydown', Rice.cb.keybind
$.after select, div
$.addClass select, 'riced'
cb: cb:
check: (e)-> check: (e)->
e.preventDefault() e.preventDefault()
@ -16,10 +57,13 @@ Rice =
option: (e) -> option: (e) ->
e.stopPropagation() e.stopPropagation()
e.preventDefault() e.preventDefault()
select = Rice.input
select = Rice.input
container = select.nextElementSibling container = select.nextElementSibling
container.firstChild.textContent = @textContent container.firstChild.textContent = @textContent
select.value = @dataset.value select.value = @dataset.value
$.event 'change', null, select $.event 'change', null, select
Rice.cleanup() Rice.cleanup()
@ -27,9 +71,7 @@ Rice =
e.stopPropagation() e.stopPropagation()
e.preventDefault() e.preventDefault()
unless {ul} = Rice {ul} = Rice
Rice.ul = ul = $.el 'ul', id: "selectrice"
$.add d.body, ul
if ul.children.length > 0 if ul.children.length > 0
return Rice.cleanup() return Rice.cleanup()
@ -54,39 +96,3 @@ Rice =
e.stopPropagation() e.stopPropagation()
$.on d, 'click scroll blur resize', Rice.cleanup $.on d, 'click scroll blur resize', Rice.cleanup
cleanup: ->
$.off d, 'click scroll blur resize', Rice.cleanup
$.rmAll Rice.ul
return
nodes: (root) ->
root or= d.body
fn = (items, type) ->
func = Rice[type]
func item for item in items
return
fn $$('[type=checkbox]:not(.riced)', root), 'checkbox'
fn $$('select:not(.riced)', root), 'select'
node: ->
Rice.checkbox $ '.postInfo input', @nodes.post
checkbox: (input) ->
return if $.hasClass input, 'riced'
$.addClass input, 'riced'
div = $.el 'div', className: 'rice'
div.check = input
$.after input, div
$.on div, 'click', Rice.cb.check
select: (select) ->
$.addClass select, 'riced'
div = $.el 'div',
className: 'selectrice'
innerHTML: "<div>#{select.options[select.selectedIndex or '0']?.textContent or ''}</div>"
$.on div, "click", Rice.cb.select
$.after select, div