QR.el -> QR.qr

This commit is contained in:
James Campos 2011-09-03 00:29:14 -07:00
parent d751784a14
commit b4c43a10bb
2 changed files with 68 additions and 66 deletions

View File

@ -1259,13 +1259,13 @@
if (conf['Persistent QR']) { if (conf['Persistent QR']) {
QR.dialog(); QR.dialog();
if (conf['Auto Hide QR']) { if (conf['Auto Hide QR']) {
return $('#autohide', QR.el).checked = true; return $('#autohide', QR.qr).checked = true;
} }
} }
}, },
attach: function() { attach: function() {
var div, file; var div, file;
$('#auto', QR.el).checked = true; $('#auto', QR.qr).checked = true;
div = $.el('div', { div = $.el('div', {
innerHTML: "<input name=upfile type=file accept=" + QR.accept + "><a class=close>X</a>" innerHTML: "<input name=upfile type=file accept=" + QR.accept + "><a class=close>X</a>"
}); });
@ -1274,13 +1274,13 @@
$.bind($('a', div), 'click', function() { $.bind($('a', div), 'click', function() {
return $.rm(this.parentNode); return $.rm(this.parentNode);
}); });
$.append($('#files', QR.el), div); $.append($('#files', QR.qr), div);
return file.click(); return file.click();
}, },
attachNext: function() { attachNext: function() {
var file, oldFile; var file, oldFile;
oldFile = $('[type=file]', QR.el); oldFile = $('[type=file]', QR.qr);
if (file = $('#files input', QR.el)) { if (file = $('#files input', QR.qr)) {
$.rm(file.parentNode); $.rm(file.parentNode);
} else { } else {
file = $.el('input', { file = $.el('input', {
@ -1300,7 +1300,7 @@
captchaNode: function(e) { captchaNode: function(e) {
var c; var c;
c = e.target.value; c = e.target.value;
$('img', QR.el).src = "http://www.google.com/recaptcha/api/image?c=" + c; $('img', QR.qr).src = "http://www.google.com/recaptcha/api/image?c=" + c;
return QR.captcha = { return QR.captcha = {
challenge: c, challenge: c,
time: Date.now() time: Date.now()
@ -1327,7 +1327,7 @@
} }
} }
$.set('captchas', captchas); $.set('captchas', captchas);
$('#cl', QR.el).textContent = captchas.length; $('#cl', QR.qr).textContent = captchas.length;
return captcha; return captcha;
}, },
change: function() { change: function() {
@ -1335,18 +1335,18 @@
return QR.attach(); return QR.attach();
}, },
close: function() { close: function() {
$.rm(QR.el); $.rm(QR.qr);
return QR.el = null; return QR.qr = null;
}, },
cooldown: function() { cooldown: function() {
var b, n, now; var b, n, now;
if (!QR.el) { if (!QR.qr) {
return; return;
} }
cooldown = $.get("cooldown/" + g.BOARD, 0); cooldown = $.get("cooldown/" + g.BOARD, 0);
now = Date.now(); now = Date.now();
n = Math.ceil((cooldown - now) / 1000); n = Math.ceil((cooldown - now) / 1000);
b = $('button', QR.el); b = $('button', QR.qr);
if (n > 0) { if (n > 0) {
$.extend(b, { $.extend(b, {
textContent: n, textContent: n,
@ -1358,35 +1358,35 @@
textContent: 'Submit', textContent: 'Submit',
disabled: false disabled: false
}); });
if ($('#auto', QR.el).checked) { if ($('#auto', QR.qr).checked) {
return QR.autoPost(); return QR.autoPost();
} }
} }
}, },
dialog: function(text) { dialog: function(text) {
var el, l, ta; var l, qr, ta;
if (text == null) { if (text == null) {
text = ''; text = '';
} }
QR.el = el = ui.dialog('qr', { QR.qr = qr = ui.dialog('qr', {
top: '0', top: '0',
left: '0' left: '0'
}, " <a class=close title=close>X</a><input type=checkbox id=autohide title=autohide> <div class=move><input placeholder=Name name=name form=qr_form>Quick Reply</div> <form enctype=multipart/form-data method=post action=http://sys.4chan.org/" + g.BOARD + "/post target=iframe id=qr_form> <input type=hidden name=resto value=" + g.THREAD_ID + "> <input type=hidden name=mode value=regist> <input type=hidden name=recaptcha_challenge_field id=challenge> <input type=hidden name=recaptcha_response_field id=response> <div><input placeholder=Email name=email>" + QR.spoiler + "</div> <div><input placeholder=Subject name=sub><button>Submit</button><label>auto<input id=auto type=checkbox></label></div> <div><textarea placeholder=Comment name=com>" + text + "</textarea></div> <div><img src=http://www.google.com/recaptcha/api/image?c=" + QR.captcha.challenge + "></div> <div><input placeholder=Verification autocomplete=off id=recaptcha_response_field><span id=cl>" + ($.get('captchas', []).length) + " captchas</span></div> <div><input name=upfile type=file accept=" + QR.accept + "></div> </form> <div id=files></div> <div><input placeholder=Password name=pwd type=password><a id=attach>attach another file</a></div> <a class=error></a> "); }, " <a class=close title=close>X</a><input type=checkbox id=autohide title=autohide> <div class=move><input placeholder=Name name=name form=qr_form>Quick Reply</div> <form enctype=multipart/form-data method=post action=http://sys.4chan.org/" + g.BOARD + "/post target=iframe id=qr_form> <input type=hidden name=resto value=" + g.THREAD_ID + "> <input type=hidden name=mode value=regist> <input type=hidden name=recaptcha_challenge_field id=challenge> <input type=hidden name=recaptcha_response_field id=response> <div><input placeholder=Email name=email>" + QR.spoiler + "</div> <div><input placeholder=Subject name=sub><button>Submit</button><label>auto<input id=auto type=checkbox></label></div> <div><textarea placeholder=Comment name=com>" + text + "</textarea></div> <div><img src=http://www.google.com/recaptcha/api/image?c=" + QR.captcha.challenge + "></div> <div><input placeholder=Verification autocomplete=off id=recaptcha_response_field><span id=cl>" + ($.get('captchas', []).length) + " captchas</span></div> <div><input name=upfile type=file accept=" + QR.accept + "></div> </form> <div id=files></div> <div><input placeholder=Password name=pwd type=password><a id=attach>attach another file</a></div> <a class=error></a> ");
if (conf['Cooldown']) { if (conf['Cooldown']) {
QR.cooldown; QR.cooldown;
} }
$.bind($('.close', el), 'click', QR.close); $.bind($('.close', qr), 'click', QR.close);
$.bind($('form', el), 'submit', QR.submit); $.bind($('form', qr), 'submit', QR.submit);
$.bind($('#recaptcha_response_field', el), 'keydown', QR.keydown); $.bind($('#recaptcha_response_field', qr), 'keydown', QR.keydown);
$.bind($('#attach', el), 'click', QR.attach); $.bind($('#attach', qr), 'click', QR.attach);
$.append(d.body, el); $.append(d.body, qr);
ta = $('textarea', el); ta = $('textarea', qr);
l = text.length; l = text.length;
ta.setSelectionRange(l, l); ta.setSelectionRange(l, l);
return ta.focus(); return ta.focus();
}, },
hasContent: function() { hasContent: function() {
return $('textarea', QR.el).value || $('[type=file]', QR.el).files.length; return $('textarea', QR.qr).value || $('[type=file]', QR.qr).files.length;
}, },
keydown: function(e) { keydown: function(e) {
if (!(e.keyCode === 13 && this.value)) { if (!(e.keyCode === 13 && this.value)) {
@ -1401,11 +1401,11 @@
var i, ss, ta, text, v; var i, ss, ta, text, v;
e.preventDefault(); e.preventDefault();
text = ">>" + this.textContent + "\n"; text = ">>" + this.textContent + "\n";
if (!QR.el) { if (!QR.qr) {
QR.dialog(text); QR.dialog(text);
return; return;
} }
ta = $('textarea', QR.el); ta = $('textarea', QR.qr);
v = ta.value; v = ta.value;
ss = ta.selectionStart; ss = ta.selectionStart;
ta.value = v.slice(0, ss) + text + v.slice(ss); ta.value = v.slice(0, ss) + text + v.slice(ss);
@ -1418,7 +1418,7 @@
data = e.data; data = e.data;
if (data) { if (data) {
data = JSON.parse(data); data = JSON.parse(data);
$.extend($('a.error', QR.el), data); $.extend($('a.error', QR.qr), data);
tc = data.textContent; tc = data.textContent;
if (tc === 'Error: Duplicate file entry detected.') { if (tc === 'Error: Duplicate file entry detected.') {
QR.attachNext(); QR.attachNext();
@ -1428,7 +1428,7 @@
} }
return; return;
} }
if (conf['Persistent QR'] || ((_ref = $('#files input', QR.el)) != null ? _ref.files.length : void 0)) { if (conf['Persistent QR'] || ((_ref = $('#files input', QR.qr)) != null ? _ref.files.length : void 0)) {
QR.reset(); QR.reset();
} else { } else {
QR.close(); QR.close();
@ -1442,17 +1442,18 @@
reset: function() { reset: function() {
var _ref; var _ref;
if (!conf['Remember Spoiler']) { if (!conf['Remember Spoiler']) {
if ((_ref = $('[name=spoiler]', QR.el)) != null) { if ((_ref = $('[name=spoiler]', QR.qr)) != null) {
_ref.checked = false; _ref.checked = false;
} }
} }
$('textarea', QR.el).value = ''; $('textarea', QR.qr).value = '';
return QR.attachNext(); return QR.attachNext();
}, },
submit: function(e) { submit: function(e) {
var captcha, challenge, el, response; var captcha, challenge, el, qr, response;
$('.error', qr.el).textContent = ''; qr = QR.qr;
if ((el = $('#recaptcha_response_field', QR.el)).value) { $('.error', qr).textContent = '';
if ((el = $('#recaptcha_response_field', qr)).value) {
QR.captchaPush(el); QR.captchaPush(el);
} }
if (!(captcha = QR.captchaShift())) { if (!(captcha = QR.captchaShift())) {
@ -1463,13 +1464,13 @@
return; return;
} }
challenge = captcha.challenge, response = captcha.response; challenge = captcha.challenge, response = captcha.response;
$('#challenge', QR.el).value = challenge; $('#challenge', qr).value = challenge;
$('#response', QR.el).value = response; $('#response', qr).value = response;
if (conf['Auto Hide QR']) { if (conf['Auto Hide QR']) {
$('#autohide', QR.el).checked = true; $('#autohide', qr).checked = true;
} }
if (!e) { if (!e) {
return $('#qr_form', QR.el).submit(); return $('#qr_form', qr).submit();
} }
}, },
sys: function() { sys: function() {

View File

@ -988,19 +988,19 @@ QR =
if conf['Persistent QR'] if conf['Persistent QR']
QR.dialog() QR.dialog()
if conf['Auto Hide QR'] if conf['Auto Hide QR']
$('#autohide', QR.el).checked = true $('#autohide', QR.qr).checked = true
attach: -> attach: ->
$('#auto', QR.el).checked = true $('#auto', QR.qr).checked = true
div = $.el 'div', div = $.el 'div',
innerHTML: "<input name=upfile type=file accept=#{QR.accept}><a class=close>X</a>" innerHTML: "<input name=upfile type=file accept=#{QR.accept}><a class=close>X</a>"
file = $ 'input', div file = $ 'input', div
$.bind file, 'change', QR.change $.bind file, 'change', QR.change
$.bind $('a', div), 'click', -> $.rm @parentNode $.bind $('a', div), 'click', -> $.rm @parentNode
$.append $('#files', QR.el), div $.append $('#files', QR.qr), div
file.click() file.click()
attachNext: -> attachNext: ->
oldFile = $ '[type=file]', QR.el oldFile = $ '[type=file]', QR.qr
if file = $ '#files input', QR.el if file = $ '#files input', QR.qr
$.rm file.parentNode $.rm file.parentNode
else else
file = $.el 'input', file = $.el 'input',
@ -1013,7 +1013,7 @@ QR =
QR.submit() QR.submit()
captchaNode: (e) -> captchaNode: (e) ->
c = e.target.value c = e.target.value
$('img', QR.el).src = "http://www.google.com/recaptcha/api/image?c=#{c}" $('img', QR.qr).src = "http://www.google.com/recaptcha/api/image?c=#{c}"
QR.captcha = QR.captcha =
challenge: c challenge: c
time: Date.now() time: Date.now()
@ -1033,20 +1033,20 @@ QR =
if captcha.time > cutoff if captcha.time > cutoff
break break
$.set 'captchas', captchas $.set 'captchas', captchas
$('#cl', QR.el).textContent = captchas.length $('#cl', QR.qr).textContent = captchas.length
captcha captcha
change: -> change: ->
$.unbind @, 'change', QR.change $.unbind @, 'change', QR.change
QR.attach() QR.attach()
close: -> close: ->
$.rm QR.el $.rm QR.qr
QR.el = null QR.qr = null
cooldown: -> cooldown: ->
return unless QR.el return unless QR.qr
cooldown = $.get "cooldown/#{g.BOARD}", 0 cooldown = $.get "cooldown/#{g.BOARD}", 0
now = Date.now() now = Date.now()
n = Math.ceil (cooldown - now) / 1000 n = Math.ceil (cooldown - now) / 1000
b = $ 'button', QR.el b = $ 'button', QR.qr
if n > 0 if n > 0
$.extend b, $.extend b,
textContent: n textContent: n
@ -1056,9 +1056,9 @@ QR =
$.extend b, $.extend b,
textContent: 'Submit' textContent: 'Submit'
disabled: false disabled: false
QR.autoPost() if $('#auto', QR.el).checked QR.autoPost() if $('#auto', QR.qr).checked
dialog: (text='') -> dialog: (text='') ->
QR.el = el = ui.dialog 'qr', top: '0', left: '0', " QR.qr = qr = ui.dialog 'qr', top: '0', left: '0', "
<a class=close title=close>X</a><input type=checkbox id=autohide title=autohide> <a class=close title=close>X</a><input type=checkbox id=autohide title=autohide>
<div class=move><input placeholder=Name name=name form=qr_form>Quick Reply</div> <div class=move><input placeholder=Name name=name form=qr_form>Quick Reply</div>
<form enctype=multipart/form-data method=post action=http://sys.4chan.org/#{g.BOARD}/post target=iframe id=qr_form> <form enctype=multipart/form-data method=post action=http://sys.4chan.org/#{g.BOARD}/post target=iframe id=qr_form>
@ -1078,17 +1078,17 @@ QR =
<a class=error></a> <a class=error></a>
" "
QR.cooldown if conf['Cooldown'] QR.cooldown if conf['Cooldown']
$.bind $('.close', el), 'click', QR.close $.bind $('.close', qr), 'click', QR.close
$.bind $('form', el), 'submit', QR.submit $.bind $('form', qr), 'submit', QR.submit
$.bind $('#recaptcha_response_field', el), 'keydown', QR.keydown $.bind $('#recaptcha_response_field', qr), 'keydown', QR.keydown
$.bind $('#attach', el), 'click', QR.attach $.bind $('#attach', qr), 'click', QR.attach
$.append d.body, el $.append d.body, qr
ta = $ 'textarea', el ta = $ 'textarea', qr
l = text.length l = text.length
ta.setSelectionRange l, l ta.setSelectionRange l, l
ta.focus() ta.focus()
hasContent: -> hasContent: ->
$('textarea', QR.el).value or $('[type=file]', QR.el).files.length $('textarea', QR.qr).value or $('[type=file]', QR.qr).files.length
keydown: (e) -> keydown: (e) ->
return unless e.keyCode is 13 and @value #enter, captcha filled return unless e.keyCode is 13 and @value #enter, captcha filled
QR.captchaPush @ QR.captchaPush @
@ -1096,10 +1096,10 @@ QR =
quote: (e) -> quote: (e) ->
e.preventDefault() e.preventDefault()
text = ">>#{@textContent}\n" text = ">>#{@textContent}\n"
if not QR.el if not QR.qr
QR.dialog text QR.dialog text
return return
ta = $ 'textarea', QR.el ta = $ 'textarea', QR.qr
v = ta.value v = ta.value
ss = ta.selectionStart ss = ta.selectionStart
ta.value = v[0...ss] + text + v[ss..] ta.value = v[0...ss] + text + v[ss..]
@ -1110,7 +1110,7 @@ QR =
{data} = e {data} = e
if data if data
data = JSON.parse data data = JSON.parse data
$.extend $('a.error', QR.el), data $.extend $('a.error', QR.qr), data
tc = data.textContent tc = data.textContent
if tc is 'Error: Duplicate file entry detected.' if tc is 'Error: Duplicate file entry detected.'
QR.attachNext() QR.attachNext()
@ -1118,7 +1118,7 @@ QR =
else if tc is 'You seem to have mistyped the verification.' else if tc is 'You seem to have mistyped the verification.'
setTimeout QR.submit, 1000 setTimeout QR.submit, 1000
return return
if conf['Persistent QR'] or $('#files input', QR.el)?.files.length if conf['Persistent QR'] or $('#files input', QR.qr)?.files.length
QR.reset() QR.reset()
else else
QR.close() QR.close()
@ -1127,23 +1127,24 @@ QR =
$.set "cooldown/#{g.BOARD}", cooldown $.set "cooldown/#{g.BOARD}", cooldown
QR.cooldown() QR.cooldown()
reset: -> reset: ->
$('[name=spoiler]', QR.el)?.checked = false unless conf['Remember Spoiler'] $('[name=spoiler]', QR.qr)?.checked = false unless conf['Remember Spoiler']
$('textarea', QR.el).value = '' $('textarea', QR.qr).value = ''
QR.attachNext() QR.attachNext()
submit: (e) -> submit: (e) ->
#XXX e is undefined if we're called from QR.autoPost #XXX e is undefined if we're called from QR.autoPost
$('.error', qr.el).textContent = '' {qr} = QR
if (el = $('#recaptcha_response_field', QR.el)).value $('.error', qr).textContent = ''
if (el = $('#recaptcha_response_field', qr)).value
QR.captchaPush el QR.captchaPush el
if not captcha = QR.captchaShift() if not captcha = QR.captchaShift()
alert 'You forgot to type in the verification.' alert 'You forgot to type in the verification.'
e?.preventDefault() e?.preventDefault()
return return
{challenge, response} = captcha {challenge, response} = captcha
$('#challenge', QR.el).value = challenge $('#challenge', qr).value = challenge
$('#response', QR.el).value = response $('#response', qr).value = response
$('#autohide', QR.el).checked = true if conf['Auto Hide QR'] $('#autohide', qr).checked = true if conf['Auto Hide QR']
$('#qr_form', QR.el).submit() if not e $('#qr_form', qr).submit() if not e
sys: -> sys: ->
$.globalEval -> $.globalEval ->
if node = document.querySelector('table font b')?.firstChild if node = document.querySelector('table font b')?.firstChild