1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| tinymce.init({
selector: 'textarea#file-picker',
ui_mode: 'split',
/*mobile: {
menubar: true
}
mobile: {
theme: 'mobile'
}*/
/*width:1200,
height:300,*/
resize: 'both',
statusbar: false,
language_url: "assets/js/tymce_fr_fr.js", // ici le chemin d'accès au fichier de traduction
language : "fr_FR",
plugins: 'image code',
toolbar: 'undo redo | styles | bold italic | link image ',
/* enable title field in the Image dialog*/
image_title: true,
/* enable automatic uploads of images represented by blob or data URIs*/
automatic_uploads: true,
/*
URL of our upload handler (for more details check: https://www.tiny.cloud/docs/configure/file-image-upload/#images_upload_url)
images_upload_url: 'postAcceptor.php',
here we add custom filepicker only to Image dialog
*/
images_upload_url: "<?= URL_LOCALHOST.'/admin-upload' ?>",
file_picker_types: 'image',
/* and here's our custom image picker*/
file_picker_callback: function (cb, value, meta) {
let input = document.createElement('input');
input.setAttribute('type', 'file');
input.setAttribute('accept', 'image/*');
/*
Note: In modern browsers input[type="file"] is functional without
even adding it to the DOM, but that might not be the case in some older
or quirky browsers like IE, so you might want to add it to the DOM
just in case, and visually hide it. And do not forget do remove it
once you do not need it anymore.
*/
input.onchange = function () {
let file = this.files[0];
let reader = new FileReader();
reader.onload = function () {
/*j
Note: Now we need to register the blob in TinyMCEs image blob
registry. In the next release this part hopefully won't be
necessary, as we are looking to handle it internally.*/
//var id = 'blobid' + (new Date()).getTime();
let id = file.name.split(".")[0]; // alert('head 50 filename='+file.name); // mettre ici le nom du fichier
let blobCache = tinymce.activeEditor.editorUpload.blobCache;
let base64 = reader.result.split(',')[1];
let blobInfo = blobCache.create(id, file, base64);
//var blobInfo = blobCache.create(id);
blobCache.add(blobInfo);
/* call the callback and populate the Title field with the file name */
cb(blobInfo.blobUri(), { title: file.name });
};
reader.readAsDataURL(file);
};
input.click();
},
content_style: 'body { font-family:Helvetica,Arial,sans-serif; font-size:14px }'
}); |
Partager