Support image pasting in Firefox without selecting paste icon in Quick Reply.

This commit is contained in:
ccd0 2016-07-10 05:40:29 -07:00
parent d4d6bb9c06
commit 7e1682cfe2

View File

@ -353,16 +353,21 @@ QR =
paste: (e) -> paste: (e) ->
return unless e.clipboardData.items return unless e.clipboardData.items
files = [] file = null
for item in e.clipboardData.items when item.kind is 'file' score = -1
blob = item.getAsFile() for item in e.clipboardData.items when item.kind is 'file' and (file2 = item.getAsFile())
blob.name = 'file' score2 = 2*(file2.size <= QR.max_size) + (file2.type is 'image/png')
blob.name += '.' + blob.type.split('/')[1] if blob.type if score2 > score
files.push blob file = file2
return unless files.length score = score2
QR.open() if file
QR.handleFiles files {type} = file
$.addClass QR.nodes.el, 'dump' blob = new Blob [file], {type}
blob.name = "file.#{QR.extensionFromType[type] or 'jpg'}"
QR.open()
QR.handleFiles [blob]
$.addClass QR.nodes.el, 'dump'
return
pasteFF: -> pasteFF: ->
{pasteArea} = QR.nodes {pasteArea} = QR.nodes
@ -520,7 +525,9 @@ QR =
# We don't receive blur events from captcha iframe. # We don't receive blur events from captcha iframe.
$.on d, 'click', QR.focus $.on d, 'click', QR.focus
if $.engine is 'gecko' # XXX Workaround for image pasting in Firefox, obsolete as of v50.
# https://bugzilla.mozilla.org/show_bug.cgi?id=906420
if $.engine is 'gecko' and not window.DataTransferItemList
nodes.pasteArea.hidden = false nodes.pasteArea.hidden = false
new MutationObserver(QR.pasteFF).observe nodes.pasteArea, {childList: true} new MutationObserver(QR.pasteFF).observe nodes.pasteArea, {childList: true}