【问题标题】:Tiny MCE and Django微型 MCE 和 Django
【发布时间】:2020-10-19 08:57:11
【问题描述】:

我正在尝试建立一个博客网站。为此,我使用了 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',
    });
}

需要帮助!

【问题讨论】:

    标签: javascript django tinymce tinymce-plugins django-tinymce


    【解决方案1】:

    要获得响应式图像,您需要阻止 TinyMCE 向插入的图像添加像素宽度和高度。一种方法是使用image_dimensions: false。然后使用 css 设置图像的宽度,一种常见的方法是使用 img { width: 100%; max-width: 600px; } 其中600px 将是最大图像宽度。 Here is a more complex TinyMCE demo 如果您想深入了解图像样式

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-24
      相关资源
      最近更新 更多