ajout plugin pastebase64 (fixes #14)

This commit is contained in:
afornerot 2019-08-22 10:01:02 +02:00
parent f485bb79a4
commit 8a170f3abb
2 changed files with 74 additions and 1 deletions

View File

@ -154,7 +154,7 @@ ivory_ck_editor:
language: fr language: fr
toolbar: "my_toolbar_1" toolbar: "my_toolbar_1"
uiColor: "#ffffff" uiColor: "#ffffff"
extraPlugins: "html5video" extraPlugins: ["html5video","pastebase64"]
light_config: light_config:
language: fr language: fr
toolbar: "my_toolbar_2" toolbar: "my_toolbar_2"
@ -169,6 +169,9 @@ ivory_ck_editor:
html5video: html5video:
path: "ckeditor/plugins/html5video/" # with trailing slash path: "ckeditor/plugins/html5video/" # with trailing slash
filename: "plugin.js" filename: "plugin.js"
pastebase64:
path: "ckeditor/plugins/pastebase64/" # with trailing slash
filename: "plugin.js"
toolbars: toolbars:
configs: configs:
my_toolbar_1: [ "@document1", "-", "@clipboard1", "-", "@basicstyles1", "-", "@paragraph1", "/", "@links1", "-", "@insert1", "-", "@styles1", "-" , "@colors1", "-" , "@tools1" ] my_toolbar_1: [ "@document1", "-", "@clipboard1", "-", "@basicstyles1", "-", "@paragraph1", "/", "@links1", "-", "@insert1", "-", "@styles1", "-" , "@colors1", "-" , "@tools1" ]

View File

@ -0,0 +1,70 @@
(function () {
'use strict';
CKEDITOR.plugins.add('pastebase64', {
init: init
});
function init(editor) {
if (editor.addFeature) {
editor.addFeature({
allowedContent: 'img[alt,id,!src]{width,height};'
});
}
editor.on("contentDom", function () {
var editableElement = editor.editable ? editor.editable() : editor.document;
editableElement.on("paste", onPaste, null, {editor: editor});
});
}
function onPaste(event) {
var editor = event.listenerData && event.listenerData.editor;
var $event = event.data.$;
var clipboardData = $event.clipboardData;
var found = false;
var imageType = /^image/;
if (!clipboardData) {
return;
}
return Array.prototype.forEach.call(clipboardData.types, function (type, i) {
if (found) {
return;
}
if (type.match(imageType) || clipboardData.items[i].type.match(imageType)) {
readImageAsBase64(clipboardData.items[i], editor);
return found = true;
}
});
}
function readImageAsBase64(item, editor) {
if (!item || typeof item.getAsFile !== 'function') {
return;
}
var file = item.getAsFile();
var reader = new FileReader();
reader.onload = function (evt) {
var element = editor.document.createElement('img', {
attributes: {
src: evt.target.result
}
});
// We use a timeout callback to prevent a bug where insertElement inserts at first caret
// position
setTimeout(function () {
editor.insertElement(element);
}, 10);
};
reader.readAsDataURL(file);
}
})();