TinyMCE:j未定义

时间:2011-07-14 04:35:25

标签: javascript tinymce

这段代码有什么问题?插入图像后,我得到“J is undefined message”。我认为这会在我试图关闭时发生。

var ImageDialog = 
{
    init : function()
    {
        var f = document.forms[0], ed = tinyMCEPopup.editor;
        e = ed.selection.getNode();
        if (e.nodeName == 'IMG')
        {
            f.src.value = ed.dom.getAttrib(e, 'src');
        }
    },

    update : function()
    {
        var f = document.forms[0], nl = f.elements, ed = tinyMCEPopup.editor, args = {}, el;

        tinyMCEPopup.restoreSelection();

        if (f.src.value === '')
        {
            if (ed.selection.getNode().nodeName == 'IMG')
            {
                ed.dom.remove(ed.selection.getNode());
                ed.execCommand('mceRepaint');
            }

            tinyMCEPopup.close();
            return;
        }

        tinymce.extend(args,
        {
            src : f.src.value
        });

        el = ed.selection.getNode();

        if (el && el.nodeName == 'IMG')
        {
            ed.dom.setAttribs(el, args);
            tinyMCEPopup.editor.execCommand('mceRepaint');
            tinyMCEPopup.editor.focus();
        }
        else
        {
            ed.execCommand('mceInsertContent', false, '<img src="'+args['src']+'" id="_mce_temp_rob" alt="" />', {skip_undo : 1});
            ed.undoManager.add();
            ed.focus();
            ed.selection.select(ed.dom.select('#_mce_temp_rob')[0]);
            ed.selection.collapse(0);
            ed.dom.setAttrib('_mce_temp_rob', 'id', '');
            tinyMCEPopup.storeSelection();
        }

        tinyMCEPopup.close();
    },

    getImageData : function()
    {
        var f = document.forms[0];
        this.preloadImg = new Image();
        this.preloadImg.src = tinyMCEPopup.editor.documentBaseURI.toAbsolute(f.src.value);
    }
};

tinyMCEPopup.onInit.add(ImageDialog.init, ImageDialog);

1 个答案:

答案 0 :(得分:4)

这是一个小小的错误。在内部,tinymce代码使用<span id="mce_marker"></span>来记住粘贴时的插入位置。在验证生成的片段时,在粘贴之后,跨度被视为无效并被移除,从而通过移除标记来破坏代码。 这个问题将在下一个正式的小版本中修复。这类问题有一些解决方法。一种是添加idmce-data-type属性添加到spans as valid elements (init setting)。例如:

// The valid_elements option defines which elements will remain in the edited text when the editor saves.
    valid_elements: "@[id|class|title|style]," +
    "a[name|href|target|title]," +
    "#p,-ol,-ul,-li,br,img[src],-sub,-sup,-b,-i,-u" +
    "-span[data-mce-type]",