Add text files support for the QR. Close #777.
This commit is contained in:
parent
bda10a5a0d
commit
5c1f2128af
@ -5981,7 +5981,7 @@
|
|||||||
return $.addClass(QR.nodes.el, 'dump');
|
return $.addClass(QR.nodes.el, 'dump');
|
||||||
},
|
},
|
||||||
fileInput: function(files) {
|
fileInput: function(files) {
|
||||||
var file, length, max, _i, _len, _ref, _ref1;
|
var file, length, max, post, _i, _len, _ref, _ref1;
|
||||||
if (!(files instanceof FileList)) {
|
if (!(files instanceof FileList)) {
|
||||||
files = __slice.call(this.files);
|
files = __slice.call(this.files);
|
||||||
}
|
}
|
||||||
@ -5994,7 +5994,9 @@
|
|||||||
QR.cleanNotifications();
|
QR.cleanNotifications();
|
||||||
if (length === 1) {
|
if (length === 1) {
|
||||||
file = files[0];
|
file = files[0];
|
||||||
if (file.size > max) {
|
if (/^text/.test(file.type)) {
|
||||||
|
QR.selected.pasteText(file);
|
||||||
|
} else if (file.size > max) {
|
||||||
QR.error("File too large (file: " + ($.bytesToString(file.size)) + ", max: " + ($.bytesToString(max)) + ").");
|
QR.error("File too large (file: " + ($.bytesToString(file.size)) + ", max: " + ($.bytesToString(max)) + ").");
|
||||||
} else if (_ref = file.type, __indexOf.call(QR.mimeTypes, _ref) < 0) {
|
} else if (_ref = file.type, __indexOf.call(QR.mimeTypes, _ref) < 0) {
|
||||||
QR.error('Unsupported file type.');
|
QR.error('Unsupported file type.');
|
||||||
@ -6005,14 +6007,19 @@
|
|||||||
}
|
}
|
||||||
for (_i = 0, _len = files.length; _i < _len; _i++) {
|
for (_i = 0, _len = files.length; _i < _len; _i++) {
|
||||||
file = files[_i];
|
file = files[_i];
|
||||||
if (file.size > max) {
|
if (/^text/.test(file.type)) {
|
||||||
|
if ((post = QR.posts[QR.posts.length - 1]).com) {
|
||||||
|
post = new QR.post();
|
||||||
|
}
|
||||||
|
post.pasteText(file);
|
||||||
|
} else if (file.size > max) {
|
||||||
QR.error("" + file.name + ": File too large (file: " + ($.bytesToString(file.size)) + ", max: " + ($.bytesToString(max)) + ").");
|
QR.error("" + file.name + ": File too large (file: " + ($.bytesToString(file.size)) + ", max: " + ($.bytesToString(max)) + ").");
|
||||||
} else if (_ref1 = file.type, __indexOf.call(QR.mimeTypes, _ref1) < 0) {
|
} else if (_ref1 = file.type, __indexOf.call(QR.mimeTypes, _ref1) < 0) {
|
||||||
QR.error("" + file.name + ": Unsupported file type.");
|
QR.error("" + file.name + ": Unsupported file type.");
|
||||||
} else if (!QR.posts[QR.posts.length - 1].file) {
|
} else if ((post = QR.posts[QR.posts.length - 1]).file) {
|
||||||
QR.posts[QR.posts.length - 1].setFile(file);
|
post = new QR.post();
|
||||||
} else {
|
} else {
|
||||||
new QR.post().setFile(file);
|
post.setFile(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $.addClass(QR.nodes.el, 'dump');
|
return $.addClass(QR.nodes.el, 'dump');
|
||||||
@ -6258,6 +6265,26 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
_Class.prototype.pasteText = function(file) {
|
||||||
|
var reader,
|
||||||
|
_this = this;
|
||||||
|
reader = new FileReader();
|
||||||
|
reader.onload = function(e) {
|
||||||
|
var text;
|
||||||
|
text = e.target.result;
|
||||||
|
if (_this.com) {
|
||||||
|
_this.com += "\n" + text;
|
||||||
|
} else {
|
||||||
|
_this.com = text;
|
||||||
|
}
|
||||||
|
if (QR.selected === _this) {
|
||||||
|
QR.nodes.com.value = _this.com;
|
||||||
|
}
|
||||||
|
return _this.nodes.span.textContent = _this.com;
|
||||||
|
};
|
||||||
|
return reader.readAsText(file);
|
||||||
|
};
|
||||||
|
|
||||||
_Class.prototype.dragStart = function() {
|
_Class.prototype.dragStart = function() {
|
||||||
return $.addClass(this, 'drag');
|
return $.addClass(this, 'drag');
|
||||||
};
|
};
|
||||||
@ -6487,7 +6514,7 @@
|
|||||||
QR.mimeTypes.push('');
|
QR.mimeTypes.push('');
|
||||||
nodes.fileInput.max = $('input[name=MAX_FILE_SIZE]').value;
|
nodes.fileInput.max = $('input[name=MAX_FILE_SIZE]').value;
|
||||||
if ($.engine !== 'presto') {
|
if ($.engine !== 'presto') {
|
||||||
nodes.fileInput.accept = mimeTypes;
|
nodes.fileInput.accept = "text/*, " + mimeTypes;
|
||||||
}
|
}
|
||||||
QR.spoiler = !!$('input[name=spoiler]');
|
QR.spoiler = !!$('input[name=spoiler]');
|
||||||
nodes.spoiler.hidden = !QR.spoiler;
|
nodes.spoiler.hidden = !QR.spoiler;
|
||||||
|
|||||||
@ -16,6 +16,7 @@ beta
|
|||||||
Delete links in the post menu will only appear for your posts.
|
Delete links in the post menu will only appear for your posts.
|
||||||
|
|
||||||
QR changes:
|
QR changes:
|
||||||
|
Opening text files will insert their content in the comment field.
|
||||||
Cooldown start time is now more accurate, which means shorter cooldown period and faster auto-posting.
|
Cooldown start time is now more accurate, which means shorter cooldown period and faster auto-posting.
|
||||||
Clicking the submit button while uploading will abort the upload and won't start re-uploading automatically anymore.
|
Clicking the submit button while uploading will abort the upload and won't start re-uploading automatically anymore.
|
||||||
Closing the QR while uploading will abort the upload and won't close the QR anymore.
|
Closing the QR while uploading will abort the upload and won't close the QR anymore.
|
||||||
|
|||||||
@ -307,7 +307,9 @@ QR =
|
|||||||
# Set or change current post's file.
|
# Set or change current post's file.
|
||||||
if length is 1
|
if length is 1
|
||||||
file = files[0]
|
file = files[0]
|
||||||
if file.size > max
|
if /^text/.test file.type
|
||||||
|
QR.selected.pasteText file
|
||||||
|
else if file.size > max
|
||||||
QR.error "File too large (file: #{$.bytesToString file.size}, max: #{$.bytesToString max})."
|
QR.error "File too large (file: #{$.bytesToString file.size}, max: #{$.bytesToString max})."
|
||||||
else unless file.type in QR.mimeTypes
|
else unless file.type in QR.mimeTypes
|
||||||
QR.error 'Unsupported file type.'
|
QR.error 'Unsupported file type.'
|
||||||
@ -316,15 +318,18 @@ QR =
|
|||||||
return
|
return
|
||||||
# Create new posts with these files.
|
# Create new posts with these files.
|
||||||
for file in files
|
for file in files
|
||||||
if file.size > max
|
if /^text/.test file.type
|
||||||
|
if (post = QR.posts[QR.posts.length - 1]).com
|
||||||
|
post = new QR.post()
|
||||||
|
post.pasteText file
|
||||||
|
else if file.size > max
|
||||||
QR.error "#{file.name}: File too large (file: #{$.bytesToString file.size}, max: #{$.bytesToString max})."
|
QR.error "#{file.name}: File too large (file: #{$.bytesToString file.size}, max: #{$.bytesToString max})."
|
||||||
else unless file.type in QR.mimeTypes
|
else unless file.type in QR.mimeTypes
|
||||||
QR.error "#{file.name}: Unsupported file type."
|
QR.error "#{file.name}: Unsupported file type."
|
||||||
else unless QR.posts[QR.posts.length - 1].file
|
else if (post = QR.posts[QR.posts.length - 1]).file
|
||||||
# set last post's file
|
post = new QR.post()
|
||||||
QR.posts[QR.posts.length - 1].setFile file
|
|
||||||
else
|
else
|
||||||
new QR.post().setFile file
|
post.setFile file
|
||||||
$.addClass QR.nodes.el, 'dump'
|
$.addClass QR.nodes.el, 'dump'
|
||||||
resetThreadSelector: ->
|
resetThreadSelector: ->
|
||||||
if g.VIEW is 'thread'
|
if g.VIEW is 'thread'
|
||||||
@ -504,6 +509,18 @@ QR =
|
|||||||
$.addClass QR.nodes.fileSubmit, 'has-file'
|
$.addClass QR.nodes.fileSubmit, 'has-file'
|
||||||
else
|
else
|
||||||
$.rmClass QR.nodes.fileSubmit, 'has-file'
|
$.rmClass QR.nodes.fileSubmit, 'has-file'
|
||||||
|
pasteText: (file) ->
|
||||||
|
reader = new FileReader()
|
||||||
|
reader.onload = (e) =>
|
||||||
|
text = e.target.result
|
||||||
|
if @com
|
||||||
|
@com += "\n#{text}"
|
||||||
|
else
|
||||||
|
@com = text
|
||||||
|
if QR.selected is @
|
||||||
|
QR.nodes.com.value = @com
|
||||||
|
@nodes.span.textContent = @com
|
||||||
|
reader.readAsText file
|
||||||
dragStart: ->
|
dragStart: ->
|
||||||
$.addClass @, 'drag'
|
$.addClass @, 'drag'
|
||||||
dragEnd: ->
|
dragEnd: ->
|
||||||
@ -705,7 +722,7 @@ QR =
|
|||||||
# Add empty mimeType to avoid errors with URLs selected in Window's file dialog.
|
# Add empty mimeType to avoid errors with URLs selected in Window's file dialog.
|
||||||
QR.mimeTypes.push ''
|
QR.mimeTypes.push ''
|
||||||
nodes.fileInput.max = $('input[name=MAX_FILE_SIZE]').value
|
nodes.fileInput.max = $('input[name=MAX_FILE_SIZE]').value
|
||||||
nodes.fileInput.accept = mimeTypes if $.engine isnt 'presto' # Opera's accept attribute is fucked up
|
nodes.fileInput.accept = "text/*, #{mimeTypes}" if $.engine isnt 'presto' # Opera's accept attribute is fucked up
|
||||||
|
|
||||||
QR.spoiler = !!$ 'input[name=spoiler]'
|
QR.spoiler = !!$ 'input[name=spoiler]'
|
||||||
nodes.spoiler.hidden = !QR.spoiler
|
nodes.spoiler.hidden = !QR.spoiler
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user