summaryrefslogtreecommitdiffstats
path: root/client/lib/pasteImage.js
diff options
context:
space:
mode:
authorfloatinghotpot <rjfun.mobile@gmail.com>2015-11-13 11:13:54 +0800
committerfloatinghotpot <rjfun.mobile@gmail.com>2015-11-13 11:13:54 +0800
commiteaf2afb44cb9de64b1ed13cb795efd0f44c541ec (patch)
treea806c9fecfa22bcb8a0f9ff3375aefa3652818f9 /client/lib/pasteImage.js
parent41b23f88aea0f421226f92b081cdb1b61c64bde4 (diff)
downloadwekan-eaf2afb44cb9de64b1ed13cb795efd0f44c541ec.tar.gz
wekan-eaf2afb44cb9de64b1ed13cb795efd0f44c541ec.tar.bz2
wekan-eaf2afb44cb9de64b1ed13cb795efd0f44c541ec.zip
add preview attached image, allow upload image from clipboard and drag & drp
Diffstat (limited to 'client/lib/pasteImage.js')
-rw-r--r--client/lib/pasteImage.js57
1 files changed, 57 insertions, 0 deletions
diff --git a/client/lib/pasteImage.js b/client/lib/pasteImage.js
new file mode 100644
index 00000000..264d77ac
--- /dev/null
+++ b/client/lib/pasteImage.js
@@ -0,0 +1,57 @@
+/* eslint-disable */
+
+// ------------------------------------------------------------------------
+// Created by STRd6
+// MIT License
+// https://github.com/distri/jquery-image_reader/blob/master/paste.coffee.md
+//
+// Raymond re-write it to javascript
+
+(function($) {
+ $.event.fix = (function(originalFix) {
+ return function(event) {
+ event = originalFix.apply(this, arguments);
+ if (event.type.indexOf('copy') === 0 || event.type.indexOf('paste') === 0) {
+ event.clipboardData = event.originalEvent.clipboardData;
+ }
+ return event;
+ };
+ })($.event.fix);
+
+ const defaults = {
+ callback: $.noop,
+ matchType: /image.*/,
+ };
+
+ return $.fn.pasteImageReader = function(options) {
+ if (typeof options === 'function') {
+ options = {
+ callback: options,
+ };
+ }
+ options = $.extend({}, defaults, options);
+ return this.each(function() {
+ const element = this;
+ return $(element).bind('paste', function(event) {
+ const types = event.clipboardData.types;
+ const items = event.clipboardData.items;
+ for(let i=0; i<types.length; i++) {
+ if(types[i].match(options.matchType) || items[i].type.match(options.matchType)) {
+ const f = items[i].getAsFile();
+ const reader = new FileReader();
+ reader.onload = function(evt) {
+ return options.callback.call(element, {
+ dataURL: evt.target.result,
+ event: evt,
+ file: f,
+ name: f.name,
+ });
+ };
+ reader.readAsDataURL(f);
+ return;
+ }
+ }
+ });
+ });
+ };
+})(jQuery);