首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用CKEditor的focusManager类?

如何使用CKEditor的focusManager类?
EN

Stack Overflow用户
提问于 2014-04-23 04:17:53
回答 2查看 1.7K关注 0票数 1

我目前正在写一个js脚本,当使用触摸设备时,它会改变一些样式,以便隐藏固定的页脚和绝对位置的页眉。

我已经能够用普通的文本输入字段和文本区域成功地实现它,但是由于CKEditor不能在DOM中解析为文本区域,所以我被迫使用它的focusManager类,以便在用户关注我的站点中它的一个实例时触发更改。

问题是我以前从来没有使用过CKEditor的API,在做了一些研究之后,我在使用它的focusManager类时遇到了一些问题。

下面是我当前的脚本。

它适用于文本格式和文本输入,但不适用于CKEditor。

据我所知,您看到的"cke_1“是编辑器的实例名称,但它不起作用。

此外,我在我的网站上有多个CKEditor实例,它需要在所有这些实例上工作。

任何帮助都将不胜感激。

谢谢!

代码语言:javascript
复制
var focusManager = new CKEDITOR.focusManager(cke_1); 
var editor = CKEDITOR.instances.cke_1;

$(document)
.on("focus", "input", function(e) {
    $body.addClass('fix');
    $('footer').hide();
})
.on("blur", "input", function(e) {
    $body.removeClass('fix');
    $('footer').show();
});

$(document).on("focus", "textarea", function(e){
    $body.addClass('fix');
    $('footer').hide();
})
.on("blur", "textarea", function(e){
    $body.removeClass('fix');
    $('footer').show();
});

$(document).on("focus", editor.focusManager, function(e){
    $body.addClass('fix');
    $('footer').hide();
})
.on("blur", editor.focusManager, function(e){
    $body.removeClass('fix');
    $('footer').show();
});
EN

回答 2

Stack Overflow用户

发布于 2014-04-24 22:55:32

我把它弄好了。因为我有多个ckeditor实例,所以我编写了一个函数,当创建一个实例并且用户在移动设备上时将调用该函数。我是这样做的:

代码语言:javascript
复制
function renderMobile(){

console.log("Mobile device detected");

// Set focus and blur listeners for all editors to be created.
CKEDITOR.on( 'instanceReady', function() {

    var editor;
    for(var i in CKEDITOR.instances) {
        editor = CKEDITOR.instances[i];
    }
    var $body = CKEDITOR.document.getBody();

    editor.on('focus', function() {
        $body.addClass( 'fix' );
    });

    editor.on('blur', function() {
        $body.removeClass( 'fix' );
    });
});
}
票数 1
EN

Stack Overflow用户

发布于 2014-04-23 21:07:26

您根本不需要使用focusManager类。只需在editor#focuseditor#blur (JSFiddle)上收听:

代码语言:javascript
复制
// Set focus and blur listeners for all editors to be created.
CKEDITOR.on( 'instanceReady', function( evt ) {
    var editor = evt.editor,
        body = CKEDITOR.document.getBody();

    editor.on( 'focus', function() {
        // Use jQuery if you want.
        body.addClass( 'fix' );
    } );

    editor.on( 'blur', function() {
        // Use jQuery if you want.
        body.removeClass( 'fix' );
    } );    
} );

CKEDITOR.replace( 'editor', {
    plugins: 'wysiwygarea,sourcearea,basicstyles,toolbar',
    on: {
        // Focus and blur listeners can be set per-instance,
        // if needed.
        // focus: function() {},
        // blur: function() {}
    }
} );
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23229370

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档