假设我已经安装了 CKEditor 4.3(我确实这样做了)和 jquery 加载器。我已经加载了一个插件(我们称之为“foobar”),它几乎可以完成我想要的功能。插件的plugin.js 文件中有一个函数,我想在页面内手动调用该函数。对于此示例,我们调用函数 hello()。
我想在单击特定链接时调用它。
如何引用 ckeditor 插件中的函数?
这是plugin.js结构:
(function() {
if (!supportsLocalStorage()) {
CKEDITOR.plugins.add("foobar", {}); //register a dummy plugin to pass CKEditor plugin initialization process
return;
}
CKEDITOR.plugins.add("foobar", {
lang: 'de,en,jp,pl,pt-br,sv,zh,zh-cn', // %REMOVE_LINE_CORE%
version: 0.10,
init: function(editor) {
CKEDITOR.document.appendStyleSheet(CKEDITOR.getUrl(CKEDITOR.plugins.getPath('foobar') + 'css/foobar.min.css'));
if (typeof (jQuery) === 'undefined') {
CKEDITOR.scriptLoader.load('//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js', function() {
jQuery.noConflict();
loadPlugin(editor);
});
} else {
CKEDITOR.scriptLoader.load(CKEDITOR.getUrl(CKEDITOR.plugins.getPath('foobar') + 'js/extensions.min.js'), function() {
loadPlugin(editor);
});
}
}
});
function loadPlugin(editorInstance) {
/*
load of random stuff that isn't important for this example..
*/
}
var hello = function() {
alert('hello!');
};
}
最佳答案
插件的正确定义应该如下:
( function() {
// Definition of the plugin.
CKEDITOR.plugins.add( 'foo', {
init: function( editor ) {
...
}
} );
// Methods and variables related to the plugin but exposed to the public.
CKEDITOR.plugins.foo = {
hello: function() {
...
}
};
} )();
然后只需CKEDITOR.plugins.foo.hello()
。这是 CKEditor 核心插件之间最常见的共享模式。
关于javascript - 如何在页面内调用CKEditor 4插件功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24432494/