首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >RichTextContent中的Feincms MediaFile

RichTextContent中的Feincms MediaFile
EN

Stack Overflow用户
提问于 2013-04-19 19:16:38
回答 2查看 424关注 0票数 6

有没有一个标准的解决方案可以将feincms MediaFile插入到RichTextContent表单元素(ckeditor或tinyMCE)中?我在文档中找不到任何...现在用户需要在medialib中复制粘贴一个url,然后移动到页面并粘贴...

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-04-20 17:10:21

为此,您必须创建自己的实现。重写dismissRelatedLookupPopup有点老套,但Django似乎缺乏对更好解决方案的支持。

更新:此ticket描述弹出问题。

在'ckeditor‘所在的静态文件夹中,创建一个插件,例如

代码语言:javascript
复制
/app/
    /static/
        /app/
            /js/
                /ckeditor/
                    /plugins/
                        /feincms/
                            /images/
                                mediaFile.png
                            plugin.js

plugin.js

代码语言:javascript
复制
/**
 * Basic sample plugin inserting a feincms mediaFile into the CKEditor editing area.
 */

// Register the plugin with the editor.
// http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.plugins.html
CKEDITOR.plugins.add( 'feincms',
{
    // The plugin initialization logic goes inside this method.
    // http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.pluginDefinition.html#init
    init: function(editor)
    {
        // Define an editor command that inserts a feincms. 
        // http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#addCommand
        editor.addCommand( 'insertMediaFile',
            {
                // Define a function that will be fired when the command is executed.
                // http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.commandDefinition.html#exec
                exec : function(editor)
                {
                    // Define your callback function
                    function insertMediaFile(imageUrl) {
                        // Insert the imageUrl into the document. Style represents some standard props.
                        // http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#insertHtml
                        editor.insertHtml('<img src="/media/' + imageUrl + '" style="float:left;margin-right:10px;margin-bottom:10px;width:200px;" />');
                    }

                    var imageUrl;
                    window.dismissRelatedLookupPopup = function (win, chosenId) {
                        imageUrl = $(win.document.body).find('#_refkey_' + chosenId).val();
                        insertMediaFile(imageUrl);
                        var name = windowname_to_id(win.name);
                        var elem = document.getElementById(name);
                        if (elem) {
                            if (elem.className.indexOf('vManyToManyRawIdAdminField') != -1 && elem.value) {
                                elem.value += ',' + chosenId;
                            } else {
                                document.getElementById(name).value = chosenId;
                            }
                        }
                        win.close();
                    };

                    var win = window.open('/admin/medialibrary/mediafile/?pop=1', 'id_image', 'height=500,width=800,resizable=yes,scrollbars=yes');
                    win.focus();
                }
            });
        // Create a toolbar button that executes the plugin command. 
        // http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.ui.html#addButton
        editor.ui.addButton( 'feincms',
        {
            // Toolbar button tooltip.
            label: 'Insert MediaFile',
            // Reference to the plugin command name.
            command: 'insertMediaFile',
            // Button's icon file path.
            icon: this.path + 'images/mediaFile.png'
        } );
    }
} );

确保将插件添加到ckeditor init脚本中,例如

代码语言:javascript
复制
{ name: 'insert', items : [ 'feincms','HorizontalRule','SpecialChar' ] },
票数 2
EN

Stack Overflow用户

发布于 2013-04-19 22:08:42

就我所知没有。如果您总是(或有时)需要与RichTextContent关联的MediaFile,请编写您自己的内容类型:

代码语言:javascript
复制
from feincms.module.medialibrary.fields import MediaFileForeignKey
from feincms.content.richtext.models import RichTextContent


class RichTextAndMFContent(RichTextContent):
    mf = MediaFileForeignKey(MediaFile)

    class Meta:
        abstract = True

    def render(self, **kwargs):
        ...
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16103352

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档