better attachNext & co

This commit is contained in:
James Campos 2011-09-02 23:07:30 -07:00
parent 4f6c79a371
commit 796e383654
2 changed files with 26 additions and 19 deletions

View File

@ -1265,13 +1265,17 @@
$.append($('#files', QR.el), div);
return file.click();
},
attachNext: function(file) {
var oldFile;
attachNext: function() {
var file, oldFile;
oldFile = $('[type=file]', QR.el);
file || (file = $.el('input', {
type: 'file',
name: 'upfile'
}));
if (file = $('#files input', QR.el)) {
$.rm(file.parentNode);
} else {
file = $.el('input', {
type: 'file',
name: 'upfile'
});
}
return $.replace(oldFile, file);
},
autoPost: function() {
@ -1396,7 +1400,7 @@
return ta.focus();
},
receive: function(e) {
var data, file, tc;
var data, tc, _ref;
data = e.data;
if (data) {
$.extend($('a.error', QR.el), JSON.parse(data));
@ -1406,8 +1410,8 @@
}
return;
}
if (((file = $('#files input', QR.el)) && file.files.length) || conf['Persistent QR']) {
QR.reset(file);
if (conf['Persistent QR'] || ((_ref = $('#files input', QR.el)) != null ? _ref.files.length : void 0)) {
QR.reset();
} else {
QR.close();
}
@ -1417,9 +1421,9 @@
return QR.cooldown();
}
},
reset: function(file) {
reset: function() {
$('textarea', QR.el).value = '';
return QR.attachNext(file);
return QR.attachNext();
},
submit: function(e) {
var captcha, challenge, el, response;

View File

@ -988,11 +988,14 @@ QR =
$.bind $('a', div), 'click', -> $.rm @parentNode
$.append $('#files', QR.el), div
file.click()
attachNext: (file) ->
attachNext: ->
oldFile = $ '[type=file]', QR.el
file or= $.el 'input',
type: 'file'
name: 'upfile'
if file = $ '#files input', QR.el
$.rm file.parentNode
else
file = $.el 'input',
type: 'file'
name: 'upfile'
$.replace oldFile, file
autoPost: ->
return unless QR.hasContent()
@ -1099,17 +1102,17 @@ QR =
if tc is 'Error: Duplicate file entry detected.'
QR.attachNext()
return
if ((file = $('#files input', QR.el)) and file.files.length) or conf['Persistent QR']
QR.reset file
if conf['Persistent QR'] or $('#files input', QR.el)?.files.length
QR.reset()
else
QR.close()
if conf['Cooldown']
cooldown = Date.now() + 30*SECOND
$.set "cooldown/#{g.BOARD}", cooldown
QR.cooldown()
reset: (file) ->
reset: ->
$('textarea', QR.el).value = ''
QR.attachNext file
QR.attachNext()
submit: (e) ->
#XXX e is undefined if we're called from QR.autoPost
$('.error', qr.el).textContent = ''