MaketRandevu/assets/ext/trumbowyg/plugins/pasteimage/trumbowyg.pasteimage.js

50 lines
1.9 KiB
JavaScript
Raw Normal View History

/* ===========================================================
* trumbowyg.pasteimage.js v1.0
* Basic base64 paste plugin for Trumbowyg
* http://alex-d.github.com/Trumbowyg
* ===========================================================
* Author : Alexandre Demode (Alex-D)
* Twitter : @AlexandreDemode
* Website : alex-d.fr
*/
(function ($) {
'use strict';
$.extend(true, $.trumbowyg, {
plugins: {
pasteImage: {
init: function (trumbowyg) {
trumbowyg.pasteHandlers.push(function (pasteEvent) {
try {
var items = (pasteEvent.originalEvent || pasteEvent).clipboardData.items,
2020-05-12 21:47:37 +03:00
mustPreventDefault = false,
reader;
for (var i = items.length - 1; i >= 0; i -= 1) {
if (items[i].type.match(/^image\//)) {
reader = new FileReader();
/* jshint -W083 */
reader.onloadend = function (event) {
2020-05-12 21:47:37 +03:00
trumbowyg.execCmd('insertImage', event.target.result, false, true);
};
/* jshint +W083 */
reader.readAsDataURL(items[i].getAsFile());
2020-05-12 21:47:37 +03:00
mustPreventDefault = true;
}
}
2020-05-12 21:47:37 +03:00
if (mustPreventDefault) {
pasteEvent.stopPropagation();
pasteEvent.preventDefault();
}
} catch (c) {
}
});
}
}
}
});
})(jQuery);