开发者

Django TinyMCE issues

开发者 https://www.devze.com 2023-04-12 05:16 出处:网络
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.

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>
 开发者_Python百科   {% 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.


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')
                        );
    });
0

精彩评论

暂无评论...
验证码 换一张
取 消