0

我有两个 ASP.NET Web 窗体应用程序,首先针对 v4.0,其次针对 .NET 框架的 v4.5。我使用 ASP.NET CKeditor 插件 v3.6.4。一切都很好,除了我无法使用“ExtraPlugins”属性注册我的“短语”插件。Javascript 解决方案有效:

CKEDITOR.replace('<%=CKEditor1.ClientID%>',
        {
            extraPlugins: 'phrases',
            toolbar:
            [
                ['Bold', 'Italic', '-', 'NumberedList', 'BulletedList', '-', 'Link', 'Unlink'],
                ['phrases']
            ]
        });

但是“ExtraPlugins”属性解决方案不起作用:

<CKEditor:CKEditorControl ID="CKEditor1" BasePath="~/ckeditor" ExtraPlugins="phrases" Toolbar="Basic" runat="server" />

请寻求帮助。

最好的问候, WP

4

1 回答 1

3

我做了一些实验,最后我知道它是如何工作的。

以下 ASP.NET CKEditor Web Control 标记放置在 *.aspx 页面中:

<CKEditor:CKEditorControl ID="CKEditor1" BasePath="~/ckeditor" ExtraPlugins="phrases" Toolbar="Basic" runat="server" />

然后,这个标签在输出的 HTML 文档中呈现,并以这种方式传送到用户浏览器:

第一部分:

<script type="text/javascript">
//<![CDATA[
function WebForm_OnSubmit() {
CKEditor_TextBoxEncode('CKEditor1', 0); 
return true;
}
//]]>
</script>

第二部分:

<textarea name="CKEditor1" rows="2" cols="20" id="CKEditor1">
</textarea>

第三方:

<script type="text/javascript">
//<![CDATA[
var CKEditor_Controls=[],CKEditor_Init=[];function CKEditor_TextBoxEncode(d,e){var f;if(typeof CKEDITOR=='undefined'||typeof CKEDITOR.instances[d]=='undefined'){f=document.getElementById(d);if(f)f.value=f.value.replace(/</g,'&lt;').replace(/>/g,'&gt;');}else{var g=CKEDITOR.instances[d];if(e&&(typeof Page_BlockSubmit=='undefined'||!Page_BlockSubmit)){g.destroy();f=document.getElementById(d);if(f)f.style.visibility='hidden';}else g.updateElement();}};(function(){if(typeof CKEDITOR!='undefined'){var d=document.getElementById('CKEditor1');if(d)d.style.visibility='hidden';}var e=function(){var f=CKEditor_Controls,g=CKEditor_Init,h=window.pageLoad,i=function(){for(var j=f.length;j--;){var k=document.getElementById(f[j]);if(k&&k.value&&(k.value.indexOf('<')==-1||k.value.indexOf('>')==-1))k.value=k.value.replace(/&lt;/g,'<').replace(/&gt;/g,'>').replace(/&amp;/g,'&');}if(typeof CKEDITOR!='undefined')for(var j=0;j<g.length;j++)g[j].call(this);};window.pageLoad=function(j,k){if(k.get_isPartialLoad())setTimeout(i,0);if(h&&typeof h=='function')h.call(this,j,k);};if(typeof Page_ClientValidate=='function'&&typeof CKEDITOR!='undefined')Page_ClientValidate=CKEDITOR.tools.override(Page_ClientValidate,function(j){return function(){for(var k in CKEDITOR.instances){if(document.getElementById(k))CKEDITOR.instances[k].updateElement();}return j.apply(this,arguments);};});setTimeout(i,0);};if(typeof Sys!='undefined'&&typeof Sys.Application!='undefined')Sys.Application.add_load(e);if(window.addEventListener)window.addEventListener('load',e,false);else if(window.attachEvent)window.attachEvent('onload',e);})();CKEditor_Controls.push('CKEditor1');
CKEditor_Init.push(function(){if(typeof CKEDITOR.instances['CKEditor1']!='undefined' || !document.getElementById('CKEditor1')) return;CKEDITOR.replace('CKEditor1',{"extraPlugins" : "phrases", "htmlEncodeOutput" : true, "toolbar" : "Basic"}); });
//]]>
</script>

在源代码的第三部分,有一个最重要的语句,它被渲染为等效于 ASP.NET CKEditor 标记:

CKEDITOR.replace('CKEditor1',{"extraPlugins" : "phrases", "htmlEncodeOutput" : true, "toolbar" : "Basic"}); });

正如我们所见,ASP.NET WebControl 的属性ExtraPlugingsextraPluginsCKEditor 实例的 Javascript 配置中的属性相关联。

经过一些认识,事实证明,JS 配置extraPlugins选项实际上并没有附加插件以在 CKEditor 工具栏中可见并准备好使用,而实际上只是注册插件以允许使用它。插件可以通过这种方式注册,也可以在config.jsCKEditor 的配置文件中注册:

CKEDITOR.editorConfig = function( config )
{
    config.extraPlugins = 'phrases';

    // Define changes to default configuration here. For example:
    // config.language = 'fr';
    // config.uiColor = '#AADC6E';
};

注册后,必须以某种方式将插件添加到工具栏以供使用,例如以这种方式:

<CKEditor:CKEditorControl ID="CKEditor1" BasePath="~/ckeditor" ExtraPlugins="phrases" Toolbar="[{ name: 'plugins', items: ['phrases'] }]" runat="server" />

或通过使用 Javascript 代码。

因此,总而言之:ExtraPlugins属性只会导致插件注册。如果我们想在 CKEditor Toolbar 上拥有它,我们必须编写适当的语句来配置 CKEEditor 工具栏。

于 2013-04-10T09:57:02.797 回答