Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support pasting from clipboard #107

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/js/jquery.dm-uploader.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 28 additions & 2 deletions src/js/jquery.dm-uploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
auto: true,
queue: true,
dnd: true,
paste: true,
hookDocument: true,
multiple: true,
url: document.URL,
Expand Down Expand Up @@ -296,7 +297,11 @@
this.initDnD();
}

if (input.length === 0 && !this.settings.dnd) {
if (this.settings.paste) {
this.initPaste();
}

if (input.length === 0 && !this.settings.dnd && !this.settings.paste) {
// Trigger an error because if this happens the plugin wont do anything.
$.error("Markup error found by jQuery.dmUploader");

Expand Down Expand Up @@ -399,6 +404,27 @@
});
};

DmUploader.prototype.initPaste = function ()
{
var widget = this;
$(document).on("paste." + pluginName, function (evt) {
evt.preventDefault();

var clipboardData = evt.originalEvent && evt.originalEvent.clipboardData;
if (!clipboardData || !clipboardData.files || !clipboardData.files.length) {
return;
}

// Clipboard has only one file (default name: image.png)
var files = [clipboardData.files[0]];
widget.addFiles(files);
});

if (!widget.settings.hookDocument) {
return;
}
};

DmUploader.prototype.releaseEvents = function() {
// Leave everyone ALONE ;_;

Expand Down Expand Up @@ -660,4 +686,4 @@
});
}
};
}));
}));