Prevent filesize errors. Prepare single and multiple file selection.
This commit is contained in:
parent
ff34fa6de1
commit
c547815b7c
@ -1216,6 +1216,13 @@
|
|||||||
close: function() {
|
close: function() {
|
||||||
return qr.el.hidden = true;
|
return qr.el.hidden = true;
|
||||||
},
|
},
|
||||||
|
error: function(err) {
|
||||||
|
$('.error', qr.el).textContent = err;
|
||||||
|
return alert(err);
|
||||||
|
},
|
||||||
|
cleanError: function() {
|
||||||
|
return $('.error', qr.el).textContent = null;
|
||||||
|
},
|
||||||
quote: function(e) {
|
quote: function(e) {
|
||||||
var caretPos, id, s, sel, ta, text, _ref;
|
var caretPos, id, s, sel, ta, text, _ref;
|
||||||
if (e != null) e.preventDefault();
|
if (e != null) e.preventDefault();
|
||||||
@ -1233,6 +1240,27 @@
|
|||||||
ta.focus();
|
ta.focus();
|
||||||
return ta.selectionEnd = ta.selectionStart = caretPos + text.length;
|
return ta.selectionEnd = ta.selectionStart = caretPos + text.length;
|
||||||
},
|
},
|
||||||
|
fileInput: function() {
|
||||||
|
var file, _i, _len, _ref;
|
||||||
|
qr.cleanError();
|
||||||
|
if (this.files.length === 1) {
|
||||||
|
if (this.files[0].size > this.max) {
|
||||||
|
qr.error('File too large.');
|
||||||
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_ref = this.files;
|
||||||
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||||
|
file = _ref[_i];
|
||||||
|
if (file.size > this.max) {
|
||||||
|
qr.error("File " + file.name + " is too large.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $.addClass(qr.el, 'dump');
|
||||||
|
},
|
||||||
dialog: function() {
|
dialog: function() {
|
||||||
var file, input, name, _ref;
|
var file, input, name, _ref;
|
||||||
qr.el = ui.dialog('qr', 'top:0;right:0;', '\
|
qr.el = ui.dialog('qr', 'top:0;right:0;', '\
|
||||||
@ -1311,7 +1339,7 @@ textarea.field {\
|
|||||||
<div><textarea title=Comment placeholder=Comment class=field></textarea><div>\
|
<div><textarea title=Comment placeholder=Comment class=field></textarea><div>\
|
||||||
<div class=captcha><img></div>\
|
<div class=captcha><img></div>\
|
||||||
<div><input name=captcha title=Verification placeholder=Verification class=field size=1></div>\
|
<div><input name=captcha title=Verification placeholder=Verification class=field size=1></div>\
|
||||||
<div><input type=file name=upfile><input type=submit value=Submit></div>\
|
<div><input type=file name=upfile multiple><input type=submit value=Submit></div>\
|
||||||
<div class=error></div>\
|
<div class=error></div>\
|
||||||
</form>');
|
</form>');
|
||||||
$.on($('#autohide', qr.el), 'click', qr.hide);
|
$.on($('#autohide', qr.el), 'click', qr.hide);
|
||||||
@ -1347,12 +1375,14 @@ textarea.field {\
|
|||||||
return 'image/' + type;
|
return 'image/' + type;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
file.max = $('[name=MAX_FILE_SIZE]').value;
|
||||||
|
$.on(file, 'change', qr.fileInput);
|
||||||
return $.add(d.body, qr.el);
|
return $.add(d.body, qr.el);
|
||||||
},
|
},
|
||||||
submit: function(e) {
|
submit: function(e) {
|
||||||
if (e != null) e.preventDefault();
|
if (e != null) e.preventDefault();
|
||||||
if (conf['Auto Hide QR']) qr.hide();
|
if (conf['Auto Hide QR']) qr.hide();
|
||||||
return $('.error', qr.el).textContent = null;
|
return qr.cleanError();
|
||||||
},
|
},
|
||||||
response: function(e) {
|
response: function(e) {
|
||||||
var input, name, _ref, _results;
|
var input, name, _ref, _results;
|
||||||
|
|||||||
@ -877,16 +877,20 @@ qr =
|
|||||||
qr.hide.call input
|
qr.hide.call input
|
||||||
else
|
else
|
||||||
qr.dialog()
|
qr.dialog()
|
||||||
|
|
||||||
hide: ->
|
hide: ->
|
||||||
if this.checked
|
if this.checked
|
||||||
$.addClass qr.el, 'autohide'
|
$.addClass qr.el, 'autohide'
|
||||||
else
|
else
|
||||||
$.removeClass qr.el, 'autohide'
|
$.removeClass qr.el, 'autohide'
|
||||||
|
|
||||||
close: ->
|
close: ->
|
||||||
qr.el.hidden = true
|
qr.el.hidden = true
|
||||||
|
|
||||||
|
error: (err) ->
|
||||||
|
$('.error', qr.el).textContent = err
|
||||||
|
alert err
|
||||||
|
cleanError: ->
|
||||||
|
$('.error', qr.el).textContent = null
|
||||||
|
|
||||||
quote: (e) ->
|
quote: (e) ->
|
||||||
e?.preventDefault()
|
e?.preventDefault()
|
||||||
qr.open()
|
qr.open()
|
||||||
@ -907,6 +911,22 @@ qr =
|
|||||||
#move the caret to the end of the new quote
|
#move the caret to the end of the new quote
|
||||||
ta.selectionEnd = ta.selectionStart = caretPos + text.length
|
ta.selectionEnd = ta.selectionStart = caretPos + text.length
|
||||||
|
|
||||||
|
fileInput: ->
|
||||||
|
qr.cleanError()
|
||||||
|
if @files.length is 1
|
||||||
|
if @files[0].size > @max
|
||||||
|
qr.error 'File too large.'
|
||||||
|
else
|
||||||
|
# modify selected reply's file
|
||||||
|
return
|
||||||
|
for file in @files
|
||||||
|
if file.size > @max
|
||||||
|
qr.error "File #{file.name} is too large."
|
||||||
|
break
|
||||||
|
# add new reply
|
||||||
|
# set reply's file
|
||||||
|
$.addClass qr.el, 'dump'
|
||||||
|
|
||||||
dialog: ->
|
dialog: ->
|
||||||
qr.el = ui.dialog 'qr', 'top:0;right:0;', '
|
qr.el = ui.dialog 'qr', 'top:0;right:0;', '
|
||||||
<style>
|
<style>
|
||||||
@ -984,7 +1004,7 @@ textarea.field {
|
|||||||
<div><textarea title=Comment placeholder=Comment class=field></textarea><div>
|
<div><textarea title=Comment placeholder=Comment class=field></textarea><div>
|
||||||
<div class=captcha><img></div>
|
<div class=captcha><img></div>
|
||||||
<div><input name=captcha title=Verification placeholder=Verification class=field size=1></div>
|
<div><input name=captcha title=Verification placeholder=Verification class=field size=1></div>
|
||||||
<div><input type=file name=upfile><input type=submit value=Submit></div>
|
<div><input type=file name=upfile multiple><input type=submit value=Submit></div>
|
||||||
<div class=error></div>
|
<div class=error></div>
|
||||||
</form>'
|
</form>'
|
||||||
$.on $('#autohide', qr.el), 'click', qr.hide
|
$.on $('#autohide', qr.el), 'click', qr.hide
|
||||||
@ -1014,13 +1034,15 @@ textarea.field {
|
|||||||
'application/PDF'
|
'application/PDF'
|
||||||
else
|
else
|
||||||
'image/' + type
|
'image/' + type
|
||||||
|
file.max = $('[name=MAX_FILE_SIZE]').value
|
||||||
|
$.on file, 'change', qr.fileInput
|
||||||
|
|
||||||
$.add d.body, qr.el
|
$.add d.body, qr.el
|
||||||
|
|
||||||
submit: (e) ->
|
submit: (e) ->
|
||||||
e?.preventDefault()
|
e?.preventDefault()
|
||||||
qr.hide() if conf['Auto Hide QR']
|
qr.hide() if conf['Auto Hide QR']
|
||||||
$('.error', qr.el).textContent = null
|
qr.cleanError()
|
||||||
# magical xhr2
|
# magical xhr2
|
||||||
|
|
||||||
response: (e) ->
|
response: (e) ->
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user