Tiny MCE and Django



我试图建立一个博客网站。为此,我使用了Tiny MCE和Django。我可以添加/上传照片到我的博客。但问题是通过Tiny MCE上传的图像对手机屏幕等较小屏幕没有响应。文本响应良好,但图像溢出。我查阅了Tiny MCE的文档,但没有找到答案。这是我的一套代码:

tinyinject.js:

(我对JS不太好(

var script = document.createElement('script');
script.type = 'text/javascript';
script.src = "https://cdn.tiny.cloud/1/no-api-key/tinymce/5/tinymce.min.js";
document.head.appendChild(script);
script.onload = function () {
tinymce.init({
selector: '#id_content',
plugins: [
'advlist autolink link image imagetools lists charmap print preview hr anchor pagebreak',
'searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking',
'table emoticons template paste help'
],
toolbar: 'insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | ' +
'bullist numlist outdent indent | link image | print preview media fullpage | ' +
'forecolor backcolor emoticons | help | image',
imagetools_toolbar: "rotateleft rotateright | flipv fliph | editimage imageoptions",
image_title: true,
automatic_upload: true,
file_picker_types: 'image',
file_picker_callback: function(cb, value, meta) {
var input = document.createElement('input');
input.setAttribute('type', 'file');
input.setAttribute('accept', 'image/*');
input.onchange = function() {
var file = this.files[0];
var reader = new FileReader();
reader.onload = function() {
var id = 'blobid' + (new Date()).getTime();
var blobCache = tinymce.activeEditor.editorUpload.blobCache;
var base64 = reader.result.split(',')[1];
var blobInfo = blobCache.create(id, file, base64);
blobCache.add(blobInfo);
cb(blobInfo.blobUri(), {title: file.name});
};
reader.readAsDataURL(file);
};
input.click();
},
menu: {
favs: { title: 'My Favorites', items: 'code visualaid | searchreplace | emoticons' }
},
menubar: 'favs file edit view insert format tools table help',
});
}

需要帮助!

要获得响应图像,您需要停止TinyMCE向插入的图像添加像素宽度和高度。一种方法是使用image_dimensions: false。然后使用css设置图像的宽度,一种常见的方法是使用img { width: 100%; max-width: 600px; },其中600px将是最大图像宽度。如果你想深入了解图像造型,这里有一个更复杂的TinyMCE演示

最新更新