开发者

change some tinymce behaviour (javascript)

Hi everybody I am using the tinymce format dropdown to apply custom styles to html elements. This is for users without html knowledge One annoying thing for me is that when a user klicks at different styles they all get added and something like this may happen

<div class="floatleft floatright positionup positiondown">

In order to prevent this I searched for the responsible code which is in editor_template.js (compressed) but visible in editor_template_src.js

Is there maybe a way to rewrite this piece of javascript so that each applied style replaces the former?

_createStyleSelect : function(n) {
            var t = this, ed = t.editor, ctrlMan = ed.controlManager, ctrl;

            // Setup style select box
            ctrl = ctrlMan.createListBox('styleselect', {
                title :开发者_运维知识库 'advanced.style_select',
                onselect : function(name) {
                    var matches, formatNames = [];

                    each(ctrl.items, function(item) {
                        formatNames.push(item.value);
                    });

                    ed.focus();
                    ed.undoManager.add();

                    // Toggle off the current format
                    matches = ed.formatter.matchAll(formatNames);
                    if (!name || matches[0] == name)
                        ed.formatter.remove(matches[0]);
                    else
                        ed.formatter.apply(name);

                    ed.undoManager.add();
                    ed.nodeChanged();

                    return false; // No auto select
                }
            });


How about:

if (!name || matches[0] == name)
    ed.formatter.remove(matches[0]);
else
    ed.formatter.remove(matches[0]);
    ed.formatter.apply(name);

Just a wild guess, haven't tried it myself.


This a lot of work to do, but it can be done. I solved this issue writing a custom plugin and using a custom FormatterClass. I suggest you try developing with tiny_mce_dev.js - this way you are able to track down problems to js classes. Then you should have a look at the js-class Formatter.js and try to modify this one in order to fullfill your wishes. The next step will be to save the mofied Formatter.js and make it part of your plugin, so that you can reset the real Formatter.js, cause i suggest not to change the tinymce core files.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜