实例化CKEditor4实例时如何将自定义值传递给CKFinder3? [英] How do I pass custom values to CKFinder3 when instantiating a CKEditor4 instance?

查看:179
本文介绍了实例化CKEditor4实例时如何将自定义值传递给CKFinder3?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用CKEditor4时,使用 pass 将变量传递到CKFinder3(ASP)连接器时遇到了一些麻烦。



我使用以下命令创建编辑器实例:

  CKFinder.setupCKEditor(myEditor,{
pass:'testVar' ,
testVar:'nooice',
...
});

但该变量似乎并没有传递给CKFinder。



如果我直接将此代码添加到CKFinder配置中,它确实可以工作:

  config。通过='testVar'; 
config.testVar ='nooice';

那太好了,但是我想传递的值是动态的,所以我需要传递它们当我在页面上调用 .setupCKEditor()时。我也尝试使用 connectorInfo:'testVar = nooice',但这也不起作用。



有人碰到这个吗?我在这个问题上找到了一个很好的答案和示例,






如果使用手动集成方法,则需要将参数附加到 filebrowserXYZBrowseUrl 配置设置中如下所示:

  var editor = CKEDITOR.replace('editor1',{

filebrowserBrowseUrl: '../ckfinder/ckfinder.html?id=abc&foo=bar&test=custom',
filebrowserImageBrowseUrl:'/ckfinder/ckfinder.html?type=Images&id=abc&foo=bar&test = custom',
filebrowserUploadUrl:'/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files&id=abc&custom=test',
filebrowserImageUploadUrl:'/ ckfinder /核心/连接器/ php / connector.php?command = QuickUpload& type = Images& id = abc& custom = test’,
});

现在的问题是CKFinder仅传递预定义的集合或URL参数: id 类型资源类型 langCode CKEditor CKEditorFuncNum 。如果您想使用更多参数,则需要手动将其作为CKFinder配置设置传递,并且需要在 ckfinder / ckfinder.html 文件中进行设置(您需要修改

 < html> 
< head>
< meta charset = utf-8>
< meta name = viewport content = width = device-width,initial-scale = 1,user-scalable = no>
< title> CKFinder 3-文件浏览器< / title>
< / head>
< body>

< script src = ckfinder.js>< / script>
< script>
函数getUrlParams(){
var vars = {};
window.location.href.replace(/ [?&] +([^ =&] +)=([^&] *)/ gi,function(match,key,value){
vars [key] = value;
});

返回变量;
}


var params = getUrlParams(),
config = {pass:''},
ckfServicedParams = [''id','type ','resourceType','langCode','CKEditor','CKEditorFuncNum'];

for(var key in params){
if(ckfServicedParams.indexOf(key)< 0){
config.pass = config.pass.concat(config.pass ?','+ key:key);
config [key] = params [key];
}
}

CKFinder.start(config);
< / script>

< / body>
< / html>

注:




  • 如果您希望在使用CKEditor图像对话框上载选项卡上载文件时发送额外的参数,则需要将它们添加到 filebrowserXYZUploadUrl 配置设置(也可以使用上面示例中显示的其他参数)。

  • 请注意,这些参数并非完全动态。您每次加载编辑器时都定义一次,除非您销毁/创建编辑器实例或使用编辑器重新加载页面,否则以后就不能更改它们。


I'm having some trouble using pass to pass variables to my CKFinder3 (ASP) connector when using CKEditor4.

I create my editor instance with:

CKFinder.setupCKEditor( myEditor, {
    pass:         'testVar',
    testVar:    'nooice',
    ...
});

but the variable just doesn't seem to make it over to CKFinder.

If I add this code to the CKFinder config directly it does work though:

config.pass = 'testVar';
config.testVar = 'nooice';

That's great, but the values I want to pass will be dynamic, so I need to pass them in when I call .setupCKEditor() on the page. I've also tried using connectorInfo: 'testVar=nooice', but that doesn't work either.

Has anyone run into this? I found a great answer and example on this question, How to pass query string parameters in ckeditor for the picture (ckfinder) button?, but the described solution is basically what I'm doing and has no affect for me.

I have been able to get this working in a CKEditor5 test using:

ClassicEditor.create( document.querySelector( '#bodyContent' ), {
    ckfinder: {
        uploadUrl: '/ckfinder3/connector?command=QuickUpload&type=Images&responseType=json',
        options: {
            pass: 'testVar',
            testVar: 'nooice'
        }
    },
    ...
} );

But I cannot figure it out in CKEditor4.

解决方案

You pass them like so:

    var editor = CKEDITOR.replace( 'editor1', {
        language : 'en',        
    } );

    CKFinder.setupCKEditor( editor, {           
        test : 'testvalA',
        token : '7901a26e4bc422aef54eb45A',
        pass : 'token,test' 
    });

In the example above you are passing test and token parameters.


If you are using manual integration method, you need to attach parameters to filebrowserXYZBrowseUrl configuration settings as shown below:

    var editor = CKEDITOR.replace( 'editor1', {     

        filebrowserBrowseUrl: '../ckfinder/ckfinder.html?id=abc&foo=bar&test=custom',
        filebrowserImageBrowseUrl: '/ckfinder/ckfinder.html?type=Images&id=abc&foo=bar&test=custom',
        filebrowserUploadUrl: '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files&id=abc&custom=test',
        filebrowserImageUploadUrl: '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images&id=abc&custom=test',
    } );

Now the problem is that CKFinder will only pass a predefined set or URL parameters: id, type, resourceType, langCode, CKEditor and CKEditorFuncNum. If you would like to use more parameters, you need to pass them manually as CKFinder configuration settings and you need to do that in ckfinder/ckfinder.html file (you need to modify it) e.g.

<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
    <title>CKFinder 3 - File Browser</title>
</head>
<body>

<script src="ckfinder.js"></script>
<script>
    function getUrlParams()  {
            var vars = {};
            window.location.href.replace( /[?&]+([^=&]+)=([^&]*)/gi, function( match, key, value ) {
                vars[ key ] = value;
            } );

            return vars;
    }


    var params = getUrlParams(),
        config  = { pass : '' },
        ckfServicedParams = [ 'id', 'type', 'resourceType', 'langCode', 'CKEditor', 'CKEditorFuncNum' ];

    for( var key in params ){
        if ( ckfServicedParams.indexOf( key ) < 0 ) {
            config.pass = config.pass.concat( config.pass ? ','+key : key);
            config[key] = params[key];
        }
    }

    CKFinder.start( config ); 
</script>

</body>
</html>

NOTES:

  • If you would like extra parameters to be sent when you upload files using CKEditor Image Dialog Upload Tab, you need to add them to filebrowserXYZUploadUrl configuration settings as well (you can use different parameters as shown in example above).
  • Please note these parameters aren't exactly dynamic. You define them once per editor load and can't change them afterwards unless you destroy/create editor instance or reload page with the editor.

这篇关于实例化CKEditor4实例时如何将自定义值传递给CKFinder3?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆