fix images being dumped out of order
This commit is contained in:
parent
1e915c29ae
commit
b931fb33d0
@ -355,44 +355,52 @@ QR =
|
|||||||
files = [@files...]
|
files = [@files...]
|
||||||
@value = null
|
@value = null
|
||||||
return unless files.length
|
return unless files.length
|
||||||
max = QR.nodes.fileInput.max
|
|
||||||
isSingle = files.length is 1
|
|
||||||
QR.cleanNotifications()
|
QR.cleanNotifications()
|
||||||
for file in files
|
for file, i in files
|
||||||
QR.checkDimensions file, isSingle, max
|
QR.handleFile file, i, files.length
|
||||||
$.addClass QR.nodes.el, 'dump' unless isSingle
|
$.addClass QR.nodes.el, 'dump' unless files.length is 1
|
||||||
|
|
||||||
checkDimensions: (file, isSingle, max) ->
|
handleFile: (file, index, nfiles) ->
|
||||||
|
if file.type in QR.mimeTypes
|
||||||
|
max = QR.nodes.fileInput.max
|
||||||
|
if file.size > max
|
||||||
|
return QR.error "#{file.name}: File too large (file: #{$.bytesToString file.size}, max: #{$.bytesToString max})."
|
||||||
|
isNewPost = false
|
||||||
|
if nfiles is 1
|
||||||
|
post = QR.selected
|
||||||
|
else if index isnt 0 or (post = QR.posts[QR.posts.length - 1]).file
|
||||||
|
isNewPost = true
|
||||||
|
post = new QR.post()
|
||||||
|
QR.checkDimensions file, (pass) ->
|
||||||
|
if pass
|
||||||
|
post.setFile file
|
||||||
|
else if isNewPost
|
||||||
|
post.rm()
|
||||||
|
else if /^text/.test file.type
|
||||||
|
if nfiles is 1
|
||||||
|
post = QR.selected
|
||||||
|
else if index isnt 0 or (post = QR.posts[QR.posts.length - 1]).com
|
||||||
|
post = new QR.post()
|
||||||
|
post.pasteText file
|
||||||
|
else
|
||||||
|
QR.error "#{file.name}: Unsupported file type."
|
||||||
|
|
||||||
|
checkDimensions: (file, cb) ->
|
||||||
if /^image\//.test file.type
|
if /^image\//.test file.type
|
||||||
img = new Image()
|
img = new Image()
|
||||||
img.onload = =>
|
img.onload = =>
|
||||||
{height, width} = img
|
{height, width} = img
|
||||||
return QR.error "#{file.name}: Image too large (image: #{img.height}x#{img.width}px, max: #{QR.max_heigth}x#{QR.max_width}px)" if height > QR.max_heigth or width > QR.max_heigth
|
if height > QR.max_heigth or width > QR.max_heigth
|
||||||
return QR.error "#{file.name}: Image too small (image: #{img.height}x#{img.width}px, min: #{QR.min_heigth}x#{QR.min_width}px)" if height < QR.min_heigth or width < QR.min_heigth
|
QR.error "#{file.name}: Image too large (image: #{img.height}x#{img.width}px, max: #{QR.max_heigth}x#{QR.max_width}px)"
|
||||||
QR.handleFile file, isSingle, max
|
cb false
|
||||||
|
else if height < QR.min_heigth or width < QR.min_heigth
|
||||||
|
QR.error "#{file.name}: Image too small (image: #{img.height}x#{img.width}px, min: #{QR.min_heigth}x#{QR.min_width}px)"
|
||||||
|
cb false
|
||||||
|
else
|
||||||
|
cb true
|
||||||
img.src = URL.createObjectURL file
|
img.src = URL.createObjectURL file
|
||||||
else
|
else
|
||||||
QR.handleFile file, isSingle, max
|
cb true
|
||||||
|
|
||||||
handleFile: (file, isSingle, max) ->
|
|
||||||
if file.size > max
|
|
||||||
QR.error "#{file.name}: File too large (file: #{$.bytesToString file.size}, max: #{$.bytesToString max})."
|
|
||||||
return
|
|
||||||
else unless file.type in QR.mimeTypes
|
|
||||||
unless /^text/.test file.type
|
|
||||||
QR.error "#{file.name}: Unsupported file type."
|
|
||||||
return
|
|
||||||
if isSingle
|
|
||||||
post = QR.selected
|
|
||||||
else if (post = QR.posts[QR.posts.length - 1]).com
|
|
||||||
post = new QR.post()
|
|
||||||
post.pasteText file
|
|
||||||
return
|
|
||||||
if isSingle
|
|
||||||
post = QR.selected
|
|
||||||
else if (post = QR.posts[QR.posts.length - 1]).file
|
|
||||||
post = new QR.post()
|
|
||||||
post.setFile file
|
|
||||||
|
|
||||||
openFileInput: (e) ->
|
openFileInput: (e) ->
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user