From 32dfad4da1aa60b0c939423a1121db8af5643ddd Mon Sep 17 00:00:00 2001 From: James Campos Date: Fri, 2 Sep 2011 20:40:33 -0700 Subject: [PATCH] shuffle --- 4chan_x.user.js | 98 ++++++++++++++++++++++++------------------------- script.coffee | 60 +++++++++++++++--------------- 2 files changed, 79 insertions(+), 79 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index a3e98b478..bf2e3b889 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -1250,6 +1250,23 @@ } } }, + attach: function() { + var div; + div = $.el('div', { + innerHTML: 'X' + }); + $.bind($('input', div), 'change', QR.change); + $.bind($('a', div), 'click', function() { + return $.rm(this.parentNode); + }); + return $.append($('#files', QR.el), div); + }, + autoPost: function() { + if (!QR.hasContent()) { + return; + } + return QR.submit(); + }, captchaNode: function(e) { var c; c = e.target.value; @@ -1282,10 +1299,39 @@ $.set('captchas', captchas); return captcha; }, + change: function() { + $.unbind(this, 'change', QR.change); + return QR.attach(); + }, close: function() { $.rm(QR.el); return QR.el = null; }, + cooldown: function() { + var b, n, now; + if (!QR.el) { + return; + } + cooldown = $.get("cooldown/" + g.BOARD, 0); + now = Date.now(); + n = Math.ceil((cooldown - now) / 1000); + b = $('button', QR.el); + if (n > 0) { + $.extend(b, { + textContent: n, + disabled: true + }); + return setTimeout(QR.cooldown, 1000); + } else { + $.extend(b, { + textContent: 'Submit', + disabled: false + }); + if ($('#auto', QR.el).checked) { + return QR.autoPost(); + } + } + }, dialog: function(text) { var el, l, ta; if (text == null) { @@ -1308,30 +1354,9 @@ ta.setSelectionRange(l, l); return ta.focus(); }, - change: function() { - $.unbind(this, 'change', QR.change); - return QR.attach(); - }, - attach: function() { - var div; - div = $.el('div', { - innerHTML: 'X' - }); - $.bind($('input', div), 'change', QR.change); - $.bind($('a', div), 'click', function() { - return $.rm(this.parentNode); - }); - return $.append($('#files', QR.el), div); - }, hasContent: function() { return $('textarea', QR.el).value || $('[type=file]', QR.el).files.length; }, - autoPost: function() { - if (!QR.hasContent()) { - return; - } - return QR.submit(); - }, keydown: function(e) { if (!(e.keyCode === 13 && this.value)) { return; @@ -1358,34 +1383,6 @@ ta.setSelectionRange(i, i); return ta.focus(); }, - cooldown: function() { - var b, n, now; - if (!QR.el) { - return; - } - cooldown = $.get("cooldown/" + g.BOARD, 0); - now = Date.now(); - n = Math.ceil((cooldown - now) / 1000); - b = $('button', QR.el); - if (n > 0) { - $.extend(b, { - textContent: n, - disabled: true - }); - return setTimeout(QR.cooldown, 1000); - } else { - $.extend(b, { - textContent: 'Submit', - disabled: false - }); - if ($('#auto', QR.el).checked) { - return QR.autoPost(); - } - } - }, - reset: function() { - return $('textarea', QR.el).value = ''; - }, receive: function(e) { var data; data = e.data; @@ -1404,6 +1401,9 @@ } } }, + reset: function() { + return $('textarea', QR.el).value = ''; + }, submit: function(e) { var captcha, challenge, el, response; $('.error', qr.el).textContent = ''; diff --git a/script.coffee b/script.coffee index a4c76e673..b147b296d 100644 --- a/script.coffee +++ b/script.coffee @@ -979,6 +979,15 @@ QR = qr.dialog() if conf['Auto Hide QR'] $('#autohide', QR.el).checked = true + attach: -> + div = $.el 'div', + innerHTML: 'X' + $.bind $('input', div), 'change', QR.change + $.bind $('a', div), 'click', -> $.rm @parentNode + $.append $('#files', QR.el), div + autoPost: -> + return unless QR.hasContent() + QR.submit() captchaNode: (e) -> c = e.target.value $('img', QR.el).src = "http://www.google.com/recaptcha/api/image?c=#{c}" @@ -1002,9 +1011,28 @@ QR = break $.set 'captchas', captchas captcha + change: -> + $.unbind @, 'change', QR.change + QR.attach() close: -> $.rm QR.el QR.el = null + cooldown: -> + return unless QR.el + cooldown = $.get "cooldown/#{g.BOARD}", 0 + now = Date.now() + n = Math.ceil (cooldown - now) / 1000 + b = $ 'button', QR.el + if n > 0 + $.extend b, + textContent: n + disabled: true + setTimeout QR.cooldown, 1000 + else + $.extend b, + textContent: 'Submit' + disabled: false + QR.autoPost() if $('#auto', QR.el).checked dialog: (text='') -> QR.el = el = ui.dialog 'qr', top: '0', left: '0', " X @@ -1035,20 +1063,8 @@ QR = l = text.length ta.setSelectionRange l, l ta.focus() - change: -> - $.unbind @, 'change', QR.change - QR.attach() - attach: -> - div = $.el 'div', - innerHTML: 'X' - $.bind $('input', div), 'change', QR.change - $.bind $('a', div), 'click', -> $.rm @parentNode - $.append $('#files', QR.el), div hasContent: -> $('textarea', QR.el).value or $('[type=file]', QR.el).files.length - autoPost: -> - return unless QR.hasContent() - QR.submit() keydown: (e) -> return unless e.keyCode is 13 and @value #enter, captcha filled return if QR.hasContent() @@ -1067,24 +1083,6 @@ QR = i = ss + text.length ta.setSelectionRange i, i ta.focus() - cooldown: -> - return unless QR.el - cooldown = $.get "cooldown/#{g.BOARD}", 0 - now = Date.now() - n = Math.ceil (cooldown - now) / 1000 - b = $ 'button', QR.el - if n > 0 - $.extend b, - textContent: n - disabled: true - setTimeout QR.cooldown, 1000 - else - $.extend b, - textContent: 'Submit' - disabled: false - QR.autoPost() if $('#auto', QR.el).checked - reset: -> - $('textarea', QR.el).value = '' receive: (e) -> {data} = e if data @@ -1098,6 +1096,8 @@ QR = cooldown = Date.now() + 30*SECOND $.set "cooldown/#{g.BOARD}", cooldown QR.cooldown() + reset: -> + $('textarea', QR.el).value = '' submit: (e) -> #XXX e is undefined if we're called from QR.autoPost $('.error', qr.el).textContent = ''