From 07990f29a2333150a141fc3454f3ff8c983d21b1 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Fri, 30 Dec 2011 23:22:56 +0100 Subject: [PATCH] Some changes in elements, preparing submit function, sync name/mail/subject only on submit because we have to take into account the mail field containing sage or not. --- 4chan_x.user.js | 59 ++++++++++++++++++++++++++++++++----------------- script.coffee | 50 +++++++++++++++++++++++++---------------- 2 files changed, 70 insertions(+), 39 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 11d2e7434..101674e9b 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -1243,28 +1243,27 @@ return ta.selectionEnd = ta.selectionStart = caretPos + text.length; }, dialog: function() { - var input, inputs, _i, _len; + var input, _i, _len, _ref; qr.el = ui.dialog('qr', 'top:0;right:0;', '\ \ \
\ \ \
\ -
\ -
\ - \ +
\ +
\ + \
\ - \ -
'); + \ +'); $.on($('#autohide', qr.el), 'click', qr.hide); $.on($('.close', qr.el), 'click', qr.close); - inputs = [$('[name=name]', qr.el), $('[name=email]', qr.el)]; - if (conf['Remember Subject']) inputs.push($('[name=subject]', qr.el)); - for (_i = 0, _len = inputs.length; _i < _len; _i++) { - input = inputs[_i]; + $.on($('form', qr.el), 'submit', qr.submit); + qr.inputs = [$('[name=name]', qr.el), $('[name=email]', qr.el)]; + if (conf['Remember Subject']) qr.inputs.push($('[name=subject]', qr.el)); + _ref = qr.inputs; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + input = _ref[_i]; input.value = $.get("qr_" + input.name, null); - $.on(input, 'change', function() { - return $.set("qr_" + this.name, this.value); - }); } $.on(window, 'storage', function(e) { var match; @@ -1306,6 +1307,24 @@ } }); return $.add(d.body, qr.el); + }, + submit: function(e) { + var input, _i, _len, _ref, _results; + if (e != null) e.preventDefault(); + if (conf['Auto Hide QR']) qr.hide(); + if (/sage/i.test(qr.inputs[1].value)) { + qr.sage = true; + qr.inputs[1].value = null; + } + _ref = qr.inputs; + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + input = _ref[_i]; + _results.push($.on(input, 'change', function() { + return $.set("qr_" + this.name, this.value); + })); + } + return _results; } }; diff --git a/script.coffee b/script.coffee index 293a7f70a..9c2511b23 100644 --- a/script.coffee +++ b/script.coffee @@ -887,7 +887,6 @@ qr = if this.checked $.addClass qr.el, 'autohide' else - $.removeClass qr.el, 'autohide' close: -> @@ -916,25 +915,24 @@ qr = dialog: -> qr.el = ui.dialog 'qr', 'top:0;right:0;', '
-
-
- +
+
+
- -
' - $.on $('#autohide', qr.el), 'click', qr.hide - $.on $('.close', qr.el), 'click', qr.close + +' + $.on $('#autohide', qr.el), 'click', qr.hide + $.on $('.close', qr.el), 'click', qr.close + $.on $('form', qr.el), 'submit', qr.submit # save & load inputs' value with localStorage - inputs = [$('[name=name]', qr.el), $('[name=email]', qr.el)] - inputs.push $('[name=subject]', qr.el) if conf['Remember Subject'] - for input in inputs + qr.inputs = [$('[name=name]', qr.el), $('[name=email]', qr.el)] + qr.inputs.push $('[name=subject]', qr.el) if conf['Remember Subject'] + for input in qr.inputs input.value = $.get "qr_#{input.name}", null - $.on input, 'change', -> $.set "qr_#{@name}", @value # sync between tabs $.on window, 'storage', (e) -> if match = e.key.match /qr_(.+)$/ @@ -974,6 +975,17 @@ qr = $.add d.body, qr.el + submit: (e) -> + e?.preventDefault() + qr.hide() if conf['Auto Hide QR'] + + if /sage/i.test qr.inputs[1].value + qr.sage = true + qr.inputs[1].value = null + + for input in qr.inputs + $.on input, 'change', -> $.set "qr_#{@name}", @value + options = init: -> home = $ '#navtopr a'