gpt4 book ai didi

django - RichTextContent 中的 Feincms MediaFile

转载 作者:行者123 更新时间:2023-12-01 15:52:17 25 4
gpt4 key购买 nike

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

最佳答案

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

更新:这个 ticket描述弹出问题。

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

/app/
/static/
/app/
/js/
/ckeditor/
/plugins/
/feincms/
/images/
mediaFile.png
plugin.js

插件.js
/**
* 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 脚本中,例如
{ name: 'insert', items : [ 'feincms','HorizontalRule','SpecialChar' ] },

关于django - RichTextContent 中的 Feincms MediaFile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16103352/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com