最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - CKEditor hookevent fired up on switching tofrom source view - Stack Overflow

programmeradmin0浏览0评论

I try to convert a div tag into something I can drag and drop in CKEditor (as asked in another question).

Do you know how I can trigger the event when someone switches between source view and WYSIWYG mode?

I try to convert a div tag into something I can drag and drop in CKEditor (as asked in another question).

Do you know how I can trigger the event when someone switches between source view and WYSIWYG mode?

Share edited Dec 5, 2020 at 18:11 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Mar 16, 2012 at 8:48 lonylony 7,82913 gold badges71 silver badges106 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 6

I think this is what you are looking for:

CKEDITOR.on('instanceCreated', function(e) {
    e.editor.on('mode', function(e){
        // Do your stuff here
        alert(e.editor.mode);
    });
}); 

If you mean, you want to capture source mode changes , then you could try something like this:


//add this to your CKeditor’s config.js
$('textarea.cke_source').live('keyup', function() {
  $(this)
    .closest('.cke_wrapper')
    .parent()
    .parent()
    .prev()
    .ckeditorGet()
    .fire('change');
});

This discussion might help as well: ckEditor Hope it helps

CKEditor onChange plugin:

Get a notification (new event) whenever the content of CKEditor changes.

http://ckeditor./addon/onchange

I think you should write a plugin to make a fake element for the wysiwyg-view.

Ckeditor is able to recognize elements that need to be replaced with fake-elements.

I made a start for you:

(function() {
    CKEDITOR.plugins.add('myPlugin', {
        requires : ['fakeobjects'],
        init: function(editor) {
            var me = this;
            var pluginName = 'myPlugin';
            editor.addCommand(pluginName, new CKEDITOR.dialogCommand(pluginName));
            
            editor.addCss( // your custom css for your placeholder here
                'div.myPluginElement' +
                '{' +
                    'border: 1px solid #a9a9a9;' +
                    'width: 70px;' +
                    'height: 50px;' +
                '}'
            );
        },
        afterInit : function(editor) {
            var dataProcessor = editor.dataProcessor,
                dataFilter = dataProcessor && dataProcessor.dataFilter;

            if (dataFilter) {
                dataFilter.addRules({
                    elements : {
                        div : function(element) {
                            if (typeof element.attributes['class'] !== 'undefined' && element.attributes['class'].indexOf('myPluginElement') != -1)
                                return editor.createFakeParserElement(element, 'myPluginElement', 'div', false);
                            else return;
                        }
                    }
                });
            }
        }
    });
})();
发布评论

评论列表(0)

  1. 暂无评论