Fix some compatibility issues with file drag'n'drop. Close #181.

This commit is contained in:
Nicolas Stepien 2012-02-05 21:49:22 +01:00
parent aa5cb8007b
commit 86f0bd6193
3 changed files with 37 additions and 22 deletions

View File

@ -1231,8 +1231,10 @@
qr.dialog(); qr.dialog();
if (conf['Auto Hide QR']) qr.hide(); if (conf['Auto Hide QR']) qr.hide();
} }
$.on(d, 'dragover', qr.fileDrop); $.on(d, 'dragover', qr.dragOver);
$.on(d, 'drop', qr.fileDrop); $.on(d, 'drop', qr.dropFile);
$.on(d, 'dragstart', qr.drag);
$.on(d, 'dragend', qr.drag);
return window.location = 'javascript:void(Recaptcha.focus_response_field=function(){})'; return window.location = 'javascript:void(Recaptcha.focus_response_field=function(){})';
}, },
open: function() { open: function() {
@ -1355,17 +1357,22 @@
ta.focus(); ta.focus();
return ta.selectionEnd = ta.selectionStart = caretPos + text.length; return ta.selectionEnd = ta.selectionStart = caretPos + text.length;
}, },
fileDrop: function(e) { drag: function(e) {
if (/TEXTAREA|INPUT/.test(e.target.nodeName)) return; var i;
i = e.type === 'dragstart' ? 'off' : 'on';
$[i](d, 'dragover', qr.dragOver);
return $[i](d, 'drop', qr.dropFile);
},
dragOver: function(e) {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); return e.dataTransfer.dropEffect = 'copy';
e.dataTransfer.dropEffect = 'copy'; },
if (e.type === 'drop') { dropFile: function(e) {
if (!e.dataTransfer.files.length) return; if (!e.dataTransfer.files.length) return;
qr.open(); e.preventDefault();
qr.fileInput.call(e.dataTransfer); qr.open();
return $.addClass(qr.el, 'dump'); qr.fileInput.call(e.dataTransfer);
} return $.addClass(qr.el, 'dump');
}, },
fileInput: function() { fileInput: function() {
var file, _i, _len, _ref; var file, _i, _len, _ref;

View File

@ -5,6 +5,7 @@ master
Increase Sauce linking possibilites: Increase Sauce linking possibilites:
Thumbnails, full images, MD5 hashes. Thumbnails, full images, MD5 hashes.
Unread Favicon is now optional, independent of Unread Count. Unread Favicon is now optional, independent of Unread Count.
Fix some compatibility issues with file drag and drop, notably with QuickDrag extension.
2.25.5 2.25.5
- Mayhem - Mayhem

View File

@ -889,8 +889,10 @@ qr =
if conf['Persistent QR'] if conf['Persistent QR']
qr.dialog() qr.dialog()
qr.hide() if conf['Auto Hide QR'] qr.hide() if conf['Auto Hide QR']
$.on d, 'dragover', qr.fileDrop $.on d, 'dragover', qr.dragOver
$.on d, 'drop', qr.fileDrop $.on d, 'drop', qr.dropFile
$.on d, 'dragstart', qr.drag
$.on d, 'dragend', qr.drag
# prevent original captcha input from being focused on reload # prevent original captcha input from being focused on reload
window.location = 'javascript:void(Recaptcha.focus_response_field=function(){})' window.location = 'javascript:void(Recaptcha.focus_response_field=function(){})'
@ -1000,16 +1002,21 @@ 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
fileDrop: (e) -> drag: (e) ->
return if /TEXTAREA|INPUT/.test e.target.nodeName # Let it drag anything from the page.
i = if e.type is 'dragstart' then 'off' else 'on'
$[i] d, 'dragover', qr.dragOver
$[i] d, 'drop', qr.dropFile
dragOver: (e) ->
e.preventDefault() e.preventDefault()
e.stopPropagation()
e.dataTransfer.dropEffect = 'copy' # cursor feedback e.dataTransfer.dropEffect = 'copy' # cursor feedback
if e.type is 'drop' dropFile: (e) ->
return unless e.dataTransfer.files.length # let it only drop files # Let it only handle files from the desktop.
qr.open() return unless e.dataTransfer.files.length
qr.fileInput.call e.dataTransfer e.preventDefault()
$.addClass qr.el, 'dump' qr.open()
qr.fileInput.call e.dataTransfer
$.addClass qr.el, 'dump'
fileInput: -> fileInput: ->
qr.cleanError() qr.cleanError()
# Set or change current reply's file. # Set or change current reply's file.