From eaf2afb44cb9de64b1ed13cb795efd0f44c541ec Mon Sep 17 00:00:00 2001 From: floatinghotpot Date: Fri, 13 Nov 2015 11:13:54 +0800 Subject: add preview attached image, allow upload image from clipboard and drag & drp --- client/lib/pasteImage.js | 57 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 client/lib/pasteImage.js (limited to 'client/lib/pasteImage.js') 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