From b82ba8b620b47d541048506087e50eeceab8042b Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Sun, 19 Jan 2014 05:14:59 -0700 Subject: [PATCH] A bit of cleanup of Rice. --- LICENSE | 2 +- builds/appchan-x.user.js | 117 ++++++++++++++++++++------------------- builds/crx/script.js | 117 ++++++++++++++++++++------------------- src/Posting/QR.coffee | 4 +- src/Theming/Rice.coffee | 90 ++++++++++++++++-------------- 5 files changed, 174 insertions(+), 156 deletions(-) diff --git a/LICENSE b/LICENSE index 2111cc847..d9832e2db 100644 --- a/LICENSE +++ b/LICENSE @@ -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. * https://github.com/zixaphir/appchan-x/blob/master/LICENSE diff --git a/builds/appchan-x.user.js b/builds/appchan-x.user.js index 7464bf148..92840647f 100644 --- a/builds/appchan-x.user.js +++ b/builds/appchan-x.user.js @@ -22,7 +22,7 @@ // ==/UserScript== /* -* appchan x - Version 2.8.5 - 2014-01-18 +* appchan x - Version 2.8.5 - 2014-01-19 * * Licensed under the MIT license. * https://github.com/zixaphir/appchan-x/blob/master/LICENSE @@ -8561,7 +8561,7 @@ thread = _ref[_i]; options.push($.el('option', { value: thread, - textContent: "Thread No." + thread + textContent: "No." + thread })); } val = list.value; @@ -8571,7 +8571,10 @@ if (!list.value) { 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() { var check, dialog, elm, event, i, items, key, mimeTypes, name, node, nodes, save, value, _ref; @@ -13369,15 +13372,66 @@ }; Rice = { + ul: $.el('ul', { + id: "selectrice" + }), init: function() { - $.ready(function() { - return Rice.nodes(d.body); - }); + $.ready(this.initReady); return Post.callbacks.push({ name: 'Rice Checkboxes', 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: "
" + (((_ref = select.options[select.selectedIndex || '0']) != null ? _ref.textContent : void 0) || '') + "
" + }); + $.on(div, 'click', Rice.cb.select); + $.on(div, 'keydown', Rice.cb.keybind); + $.after(select, div); + return $.addClass(select, 'riced'); + }, cb: { check: function(e) { e.preventDefault(); @@ -13399,12 +13453,7 @@ var bottom, clientHeight, left, li, nodes, option, select, style, top, ul, width, _i, _len, _ref, _ref1; e.stopPropagation(); e.preventDefault(); - if (!(ul = Rice.ul, Rice)) { - Rice.ul = ul = $.el('ul', { - id: "selectrice" - }); - $.add(d.body, ul); - } + ul = Rice.ul; if (ul.children.length > 0) { return Rice.cleanup(); } @@ -13430,50 +13479,6 @@ }); 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: "
" + (((_ref = select.options[select.selectedIndex || '0']) != null ? _ref.textContent : void 0) || '') + "
" - }); - $.on(div, "click", Rice.cb.select); - return $.after(select, div); } }; diff --git a/builds/crx/script.js b/builds/crx/script.js index f806656b8..a64ae8c74 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -1,6 +1,6 @@ // 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. * https://github.com/zixaphir/appchan-x/blob/master/LICENSE @@ -8569,7 +8569,7 @@ thread = _ref[_i]; options.push($.el('option', { value: thread, - textContent: "Thread No." + thread + textContent: "No." + thread })); } val = list.value; @@ -8579,7 +8579,10 @@ if (!list.value) { 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() { var check, dialog, event, i, items, key, mimeTypes, name, node, nodes, save, value, _ref; @@ -13358,15 +13361,66 @@ }; Rice = { + ul: $.el('ul', { + id: "selectrice" + }), init: function() { - $.ready(function() { - return Rice.nodes(d.body); - }); + $.ready(this.initReady); return Post.callbacks.push({ name: 'Rice Checkboxes', 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: "
" + (((_ref = select.options[select.selectedIndex || '0']) != null ? _ref.textContent : void 0) || '') + "
" + }); + $.on(div, 'click', Rice.cb.select); + $.on(div, 'keydown', Rice.cb.keybind); + $.after(select, div); + return $.addClass(select, 'riced'); + }, cb: { check: function(e) { e.preventDefault(); @@ -13388,12 +13442,7 @@ var bottom, clientHeight, left, li, nodes, option, select, style, top, ul, width, _i, _len, _ref, _ref1; e.stopPropagation(); e.preventDefault(); - if (!(ul = Rice.ul, Rice)) { - Rice.ul = ul = $.el('ul', { - id: "selectrice" - }); - $.add(d.body, ul); - } + ul = Rice.ul; if (ul.children.length > 0) { return Rice.cleanup(); } @@ -13419,50 +13468,6 @@ }); 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: "
" + (((_ref = select.options[select.selectedIndex || '0']) != null ? _ref.textContent : void 0) || '') + "
" - }); - $.on(div, "click", Rice.cb.select); - return $.after(select, div); } }; diff --git a/src/Posting/QR.coffee b/src/Posting/QR.coffee index 0a0c06546..b52533fb1 100644 --- a/src/Posting/QR.coffee +++ b/src/Posting/QR.coffee @@ -328,7 +328,7 @@ QR = for thread in g.BOARD.threads.keys options.push $.el 'option', value: thread - textContent: "Thread No.#{thread}" + textContent: "No.#{thread}" val = list.value $.rmAll list $.add list, options @@ -339,6 +339,8 @@ QR = g.THREADID else 'new' + list.nextElementSibling.firstChild.textContent = list.options[list.selectedIndex].textContent if $.hasClass list, 'riced' + dialog: -> QR.nodes = nodes = diff --git a/src/Theming/Rice.coffee b/src/Theming/Rice.coffee index 285425013..c308ae1f7 100644 --- a/src/Theming/Rice.coffee +++ b/src/Theming/Rice.coffee @@ -1,12 +1,53 @@ Rice = + ul: $.el 'ul', id: "selectrice" init: -> - $.ready -> - Rice.nodes d.body + $.ready @initReady Post.callbacks.push name: 'Rice Checkboxes' 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: "
#{select.options[select.selectedIndex or '0']?.textContent or ''}
" + $.on div, 'click', Rice.cb.select + $.on div, 'keydown', Rice.cb.keybind + + $.after select, div + $.addClass select, 'riced' + cb: check: (e)-> e.preventDefault() @@ -16,10 +57,13 @@ Rice = option: (e) -> e.stopPropagation() e.preventDefault() - select = Rice.input + + select = Rice.input container = select.nextElementSibling + container.firstChild.textContent = @textContent select.value = @dataset.value + $.event 'change', null, select Rice.cleanup() @@ -27,9 +71,7 @@ Rice = e.stopPropagation() e.preventDefault() - unless {ul} = Rice - Rice.ul = ul = $.el 'ul', id: "selectrice" - $.add d.body, ul + {ul} = Rice if ul.children.length > 0 return Rice.cleanup() @@ -54,39 +96,3 @@ Rice = e.stopPropagation() $.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: "
#{select.options[select.selectedIndex or '0']?.textContent or ''}
" - $.on div, "click", Rice.cb.select - - $.after select, div \ No newline at end of file