Drupal 7 中的 CKEditor 缺失/不正确的 basePath

CKEditor missing/incorrect basePath in Drupal 7

本文关键字:不正确 basePath 缺失 中的 CKEditor Drupal      更新时间:2023-09-26

在自定义模块中,我包含了 CKEditor。

drupal_add_js( 'sites/all/libraries/ckeditor/ckeditor.js',array('weight'=>JS_LIBRARY+1));
drupal_add_js( 'sites/all/libraries/ckeditor/adapters/jquery.js',array('weight'=>JS_LIBRARY+2));

在我的 JS 中,我现在使用

jQuery('#myTextArea').ckeditor();

这曾经有效,但现在不是。在Firebug中查看,我看到ckeditor正在尝试访问config.js,并且它正在页面的URL中查找此内容。它应该寻求 http://example.com/sites/all/libraries/ckeditor/。

我想不出最近发生了什么变化可能会破坏它!

我尝试将配置{ basePath: '/sites/all/libraries/ckeditor/' }传递到ckeditor()调用中,但这被忽略了,可能无法在运行时设置它?

任何人都知道我做错了什么,或者如果这是一个错误,是否有解决方法?

正如我评论的那样,这似乎与通过Drupal的JS聚合加载编辑器有关

这是一个丑陋的黑客,它对我有用。

编辑 sites/all/libraries/ckeditor

/ckeditor.js 文件,并在压缩的 js 代码添加之前:

window.CKEDITOR_BASEPATH = 'http://example.com/sites/all/libraries/ckeditor/';

然后请记住每次升级时都这样做。

PS. 基本路径提示上的信用。

CKEditor(测试 4.4.4)在更改默认 ckeditor.js 文件名时在确定正确的基本路径时出现问题。例如,为实时部署添加缓存破坏程序或使用聚合名称时。

您可以使用属性的输出轻松重现该行为:CKEDITOR.basePath

您在一个路径为/a/b/c/d 的网站(假设为 http://example.de),使用原始 ckeditor 文件名/ext/ckeditor/ckeditor.js:

Website: http://example.de/a/b/c/d
CKeditor: http://example.de/ext/ckeditor/ckeditor.js
console.log(CKEDITOR.basePath); //output: http://example.de/ext/ckeditor/ 

您在同一个网站上,相同的路径和 ckeditor.js更改:

Website: http://example.de/a/b/c/d
CKeditor: http://example.de/ext/ckeditor/ckeditor-whatever.js
console.log(CKEDITOR.basePath); //output: http://example.de/a/b/c/ 

通常,JavaScript 控制台会显示如下错误:

Line 1: Uncaught SyntaxError: Unexpected token <
Uncaught TypeError: Cannot set property 'dir' of undefined

因此,如果您更改默认文件名 ckeditor.js,则始终需要设置基本路径。