Manage file drag and drop into the window. It will open the QR if it's closed.

This commit is contained in:
Nicolas Stepien 2012-01-02 06:29:30 +01:00
parent 4e2f3efef6
commit 9cf6aa1079
2 changed files with 29 additions and 8 deletions

View File

@ -1260,6 +1260,16 @@
ta.focus();
return ta.selectionEnd = ta.selectionStart = caretPos + text.length;
},
fileDrop: function(e) {
if (!e.dataTransfer.files.length) return;
e.preventDefault();
e.stopPropagation();
e.dataTransfer.dropEffect = 'copy';
if (e.type === 'drop') {
qr.open();
return qr.fileInput.call(e.dataTransfer);
}
},
fileInput: function() {
var file, _i, _len, _ref;
qr.cleanError();
@ -1321,6 +1331,9 @@
return qr.el.classList.toggle('dump');
});
$.on($('form', qr.el), 'submit', qr.submit);
$.on($('[type=file]', qr.el), 'change', qr.fileInput);
$.on(d, 'dragover', qr.fileDrop);
$.on(d, 'drop', qr.fileDrop);
qr.inputs = {
name: $('[name=name]', qr.el),
email: $('[name=email]', qr.el)
@ -1337,7 +1350,6 @@
return qr.inputs[match[1]].value = JSON.parse(e.newValue);
}
});
$.on($('[type=file]', qr.el), 'change', qr.fileInput);
return $.add(d.body, qr.el);
},
submit: function(e) {

View File

@ -926,6 +926,14 @@ qr =
#move the caret to the end of the new quote
ta.selectionEnd = ta.selectionStart = caretPos + text.length
fileDrop: (e) ->
return unless e.dataTransfer.files.length # let it only drop files
e.preventDefault()
e.stopPropagation()
e.dataTransfer.dropEffect = 'copy' # cursor feedback
if e.type is 'drop'
qr.open()
qr.fileInput.call e.dataTransfer
fileInput: ->
qr.cleanError()
if @files.length is 1
@ -1067,11 +1075,14 @@ textarea.field {
<div class=error></div>
</form>"
unless g.REPLY
$.on $('select', qr.el), 'mousedown', (e) -> e.stopPropagation()
$.on $('#autohide', qr.el), 'click', qr.hide
$.on $('.close', qr.el), 'click', qr.close
$.on $('#dump', qr.el), 'click', -> qr.el.classList.toggle 'dump'
$.on $('form', qr.el), 'submit', qr.submit
$.on $('select', qr.el), 'mousedown', (e) -> e.stopPropagation()
$.on $('#autohide', qr.el), 'click', qr.hide
$.on $('.close', qr.el), 'click', qr.close
$.on $('#dump', qr.el), 'click', -> qr.el.classList.toggle 'dump'
$.on $('form', qr.el), 'submit', qr.submit
$.on $('[type=file]', qr.el), 'change', qr.fileInput
$.on d, 'dragover', qr.fileDrop
$.on d, 'drop', qr.fileDrop
# save & load inputs' value with localStorage
qr.inputs =
@ -1085,8 +1096,6 @@ textarea.field {
if match = e.key.match /qr_(.+)$/
qr.inputs[match[1]].value = JSON.parse e.newValue
$.on $('[type=file]', qr.el), 'change', qr.fileInput
$.add d.body, qr.el
submit: (e) ->