Django TinyMCE 问题

发布于 2024-12-09 06:35:11 字数 3181 浏览 0 评论 0原文

所有文本区域都是内联的,StackedInline

所有文本区域在此模型change_view 中都工作正常。但是,当我添加新行时,最后一行在文本区域中不可编辑。

如果我删除 tunyMCE Init 中的 mode:"textareas" ,它会删除 wsgi 编辑器,但随后在添加新文本区域时文本区域会起作用。所以我猜是tinyMCE破坏了它。

但我已经从另一个可以运行的项目中复制了这个tinyMCE 文件。所以我不知道wtf!

我的tinymce设置如下:

media/js/tinymce

然后我在模板中设置:

templates/admin/app_name/model_name/change_form.html

这是我的change_form.html

{% extends "admin/change_form.html" %}
{% load i18n %}

{% block extrahead %}{{ block.super }}
{% url 'admin:jsi18n' as jsi18nurl %}
<script type="text/javascript" src="{{ jsi18nurl|default:"../../../jsi18n/" }}"></script>
{{ media }}

<script type="text/javascript" src="{{ MEDIA_URL }}js/jquery-1.6.4.min.js"></script>
<script type="text/javascript" src="{{ MEDIA_URL }}js/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
function CustomFileBrowser(field_name, url, type, win) {

    var cmsURL = "/admin/filebrowser/browse/?pop=2";
    cmsURL = cmsURL + "&type=" + type;

    tinyMCE.activeEditor.windowManager.open({
        file: cmsURL,
        width: 850,  // Your dimensions may differ - toy around with them!
        height: 650,
        resizable: "yes",
        scrollbars: "yes",
        inline: "no",  // This parameter only has an effect if you use the inlinepopups plugin!
        close_previous: "no",
    }, {
        window: win,
        input: field_name,
        editor_id: tinyMCE.selectedInstance.editorId,
    });
    return false;
};

    tinyMCE.init({
        // add these two lines for absolute urls
        remove_script_host : false,
        convert_urls : false,
        // General options
        mode : "textareas",
        theme : "advanced",
        plugins : "safari,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media",
        file_browser_callback: 'CustomFileBrowser',
        // Theme options
        theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|styleselect,formatselect,|,undo,redo,|,link,unlink,image,code",
        theme_advanced_buttons3 : "",
        theme_advanced_buttons4 : "",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        // theme_advanced_statusbar_location : "bottom",
        theme_advanced_resizing : false,
        width:300,
        height:300,
    });

</script>

{% endblock %}

{% block object-tools %}
{% if change %}{% if not is_popup %}
  <ul class="object-tools">
    <li><a href="history/" class="historylink">{% trans "History" %}</a></li>
    {% if has_absolute_url %}
        <li><a href="../../../r/{{ content_type_id }}/{{ object_id }}/" class="viewsitelink">
            {% trans "View on site" %}</a>
        </li>
        <li><a href="../../../r/{{ content_type_id }}/{{ object_id }}/html/" class="viewsitelink">
            {% trans "View source" %}</a>
        </li>
    {% endif%}
  </ul>
{% endif %}{% endif %}
{% endblock %}

即使我在textareas.js中执行此操作并将其包含在chnage_form.html extrahead 块的作用相同。

All the textareas are inline, StackedInline

All textareas works fine in this model change_view. BUT, when I add a new row the last row is not editiable in the textarea.

If I remove the mode:"textareas" in the tunyMCE Init, it abviasly removes the wsgi editor but then the textareas work when adding new ones. So I guess its tinyMCE that breaks it.

But I haved copied this tinyMCE files form another project where it works. So I dont know wtf!

I have my tinymce setup like this:

media/js/tinymce

then I have in templates:

templates/admin/app_name/model_name/change_form.html

and this is my change_form.html

{% extends "admin/change_form.html" %}
{% load i18n %}

{% block extrahead %}{{ block.super }}
{% url 'admin:jsi18n' as jsi18nurl %}
<script type="text/javascript" src="{{ jsi18nurl|default:"../../../jsi18n/" }}"></script>
{{ media }}

<script type="text/javascript" src="{{ MEDIA_URL }}js/jquery-1.6.4.min.js"></script>
<script type="text/javascript" src="{{ MEDIA_URL }}js/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
function CustomFileBrowser(field_name, url, type, win) {

    var cmsURL = "/admin/filebrowser/browse/?pop=2";
    cmsURL = cmsURL + "&type=" + type;

    tinyMCE.activeEditor.windowManager.open({
        file: cmsURL,
        width: 850,  // Your dimensions may differ - toy around with them!
        height: 650,
        resizable: "yes",
        scrollbars: "yes",
        inline: "no",  // This parameter only has an effect if you use the inlinepopups plugin!
        close_previous: "no",
    }, {
        window: win,
        input: field_name,
        editor_id: tinyMCE.selectedInstance.editorId,
    });
    return false;
};

    tinyMCE.init({
        // add these two lines for absolute urls
        remove_script_host : false,
        convert_urls : false,
        // General options
        mode : "textareas",
        theme : "advanced",
        plugins : "safari,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media",
        file_browser_callback: 'CustomFileBrowser',
        // Theme options
        theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|styleselect,formatselect,|,undo,redo,|,link,unlink,image,code",
        theme_advanced_buttons3 : "",
        theme_advanced_buttons4 : "",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        // theme_advanced_statusbar_location : "bottom",
        theme_advanced_resizing : false,
        width:300,
        height:300,
    });

</script>

{% endblock %}

{% block object-tools %}
{% if change %}{% if not is_popup %}
  <ul class="object-tools">
    <li><a href="history/" class="historylink">{% trans "History" %}</a></li>
    {% if has_absolute_url %}
        <li><a href="../../../r/{{ content_type_id }}/{{ object_id }}/" class="viewsitelink">
            {% trans "View on site" %}</a>
        </li>
        <li><a href="../../../r/{{ content_type_id }}/{{ object_id }}/html/" class="viewsitelink">
            {% trans "View source" %}</a>
        </li>
    {% endif%}
  </ul>
{% endif %}{% endif %}
{% endblock %}

Even If I do this in textareas.js and include that in the chnage_form.html extrahead block it does the same.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

江湖彼岸 2024-12-16 06:35:11

好吧,我知道出了什么问题了。也许有人遇到同样的问题

问题是当添加新行时,texarea 不是由tinymce启动的,因为它只在页面加载时执行一次。效果很完美,因此您需要在添加新行后再次向文本区域添加功能。

我就是这样做的:

change_form.html,将其添加到文件底部

$(".add-row a").click(function () {
        // this is the span that the current wsgi editor is in, so I remove it
        $($(this).parent().prev().prev().find("span")[2]s).remove();
        // Now I display the original textarea
        $(this).parent().prev().prev().find("textarea").show();
        // and Finaly lets add MCE control to this area.
        tinyMCE.execCommand(
                            'mceAddControl',
                            false,
                            $(this).parent().prev().prev().find("textarea").attr('id')
                        );
    });

Well, I figured out what was wrong. Maybee someone runs into the same problem

The problem is thart when adding a new row, that texarea is not initiated by tinymce, bacause it only does that once, when the pages loads. Makses perfect sence, so you need to add functionality to the textarea again after adding anew row.

This is how I did it:

change_form.html, added this to the bottom of the file

$(".add-row a").click(function () {
        // this is the span that the current wsgi editor is in, so I remove it
        $($(this).parent().prev().prev().find("span")[2]s).remove();
        // Now I display the original textarea
        $(this).parent().prev().prev().find("textarea").show();
        // and Finaly lets add MCE control to this area.
        tinyMCE.execCommand(
                            'mceAddControl',
                            false,
                            $(this).parent().prev().prev().find("textarea").attr('id')
                        );
    });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文