From 84057f65c1b155099c42676d2a3f8569f9b69e6e Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Tue, 10 Jan 2012 16:35:29 +0100 Subject: [PATCH] Drag and drop fixes, let it drop text into text inputs. It won't let it drop files into text inputs though. --- 4chan_x.user.js | 3 ++- script.coffee | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index a352ad5d0..4b2fbeb55 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -1265,11 +1265,12 @@ return ta.selectionEnd = ta.selectionStart = caretPos + text.length; }, fileDrop: function(e) { - if (!e.dataTransfer.files.length) return; + if (/TEXTAREA|INPUT/.test(e.target.nodeName)) return; e.preventDefault(); e.stopPropagation(); e.dataTransfer.dropEffect = 'copy'; if (e.type === 'drop') { + if (!e.dataTransfer.files.length) return; qr.open(); qr.fileInput.call(e.dataTransfer); return $.addClass(qr.el, 'dump'); diff --git a/script.coffee b/script.coffee index d1b44fca5..583947872 100644 --- a/script.coffee +++ b/script.coffee @@ -881,8 +881,8 @@ qr = if conf['Persistent QR'] qr.dialog() $.id('autohide').click() if conf['Auto Hide QR'] - $.on d, 'dragover', qr.fileDrop - $.on d, 'drop', qr.fileDrop + $.on d, 'dragover', qr.fileDrop + $.on d, 'drop', qr.fileDrop open: -> if qr.el @@ -933,11 +933,12 @@ qr = ta.selectionEnd = ta.selectionStart = caretPos + text.length fileDrop: (e) -> - return unless e.dataTransfer.files.length # let it only drop files + return if /TEXTAREA|INPUT/.test e.target.nodeName e.preventDefault() e.stopPropagation() e.dataTransfer.dropEffect = 'copy' # cursor feedback if e.type is 'drop' + return unless e.dataTransfer.files.length # let it only drop files qr.open() qr.fileInput.call e.dataTransfer $.addClass qr.el, 'dump'