私は CkEditor を使用しており、AJAX 関数を使用して HTML 文字列をロードするカスタム テンプレートを定義したいと考えています。カスタム テンプレートを定義できましたが、テンプレート オブジェクトの html プロパティに関数を使用すると、関数が実行されません。デフォルトのテンプレート プラグインで AJAX を使用してテンプレートをロードすることは可能ですか、それとも独自に作成する必要がありますか?
config.js
CKEDITOR.editorConfig = function (config) {
config.templates_files = ['/pathtomyfile/custom.js'];
};
custom.js (カスタム テンプレートの定義)
CKEDITOR.addTemplates('default', {
imagesPath: CKEDITOR.getUrl(CKEDITOR.plugins.getPath('templates') + 'templates/images/'),
templates: [
{
title: 'Template 1',
image: 'template1.gif',
description: 'A custom template that does not work',
html: function () {
alert('This alert is never called');
var html = '';
$.ajax({
url: 'MyGetURL',
type: "GET",
async: false,
success: function (result) {
html = result;
},
error: function (jqXhr, textStatus, errorThrown) {
alert("Error '" + jqXhr.status + "' (textStatus: '" + textStatus + "', errorThrown: '" + errorThrown + "')");
}
});
return html;
}
},
{
title: 'Template 2',
image: 'template2.gif',
description: 'A working custom template',
html: '<h1>I Work!</h1>'
}
]
});