使用 CKEditor 4.5 的 FileBrowser 回调而不是弹出窗口
FileBrowser callback instead of popup with CKEditor 4.5
我在我的 ASP.NET MVC 5 应用程序中使用 CKEditor,但我仍在使用 4.0.2 版,因为我使用 fileBrowserCallback
配置,使用 AlexW (see also here 的补丁) .但是这个补丁不兼容任何更新的版本。
现在随着 CKEditor 4.5 的新发布,我终于想升级了,因为它们有一些很棒的新功能(比如拖动&drop/copy&粘贴上传),但我不想回到 "pop-up file-browser".
我搜索了所有新文件浏览器的文档和 API plugins/options,但我仍然找不到这样的选项。
我是否错过了启用此功能的配置选项,还是仍然无法启用?
如果没有,是否有一个 "updated patch" 可以再次添加它,或者有人可以指出我可以自己添加的位置吗?
您无需修补 CKEditor 即可在按下“浏览服务器”按钮时调用您的自定义回调。检查以下更改图像对话框的示例代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Browse server - custom callback</title>
<script src="http://cdn.ckeditor.com/4.5.1/standard/ckeditor.js"></script>
</head>
<body>
<form action="sample_posteddata.php" method="post">
<textarea cols="80" id="editor1" name="editor1" rows="10">
</textarea>
<script>
CKEDITOR.on( 'dialogDefinition', function( ev ) {
// Take the dialog name and its definition from the event data.
var dialogName = ev.data.name;
var dialogDefinition = ev.data.definition;
// Check if the definition is from the dialog we're
// interested on (the "Image" dialog).
if ( dialogName == 'image' ) {
// Get a reference to the "Image Properties" tab.
var infoTab = dialogDefinition.getContents( 'info' );
// Get a reference to the "Browse Server" button.
var browse = infoTab.get( 'browse' );
// Instruct filebrowser plugin to skip hooking into this button.
browse[ 'filebrowser' ] = false;
// The "Browse Server" button is hidden by default.
browse[ 'hidden' ] = false;
// Add our own callback.
browse[ 'onClick' ] = function() {
var url = prompt( 'Type some URL' );
this.getDialog().getContentElement( 'info', 'txtUrl' ).setValue( url );
};
}
} );
CKEDITOR.replace( 'editor1' );
</script>
</form>
</body>
</html>
我在我的 ASP.NET MVC 5 应用程序中使用 CKEditor,但我仍在使用 4.0.2 版,因为我使用 fileBrowserCallback
配置,使用 AlexW (see also here 的补丁) .但是这个补丁不兼容任何更新的版本。
现在随着 CKEditor 4.5 的新发布,我终于想升级了,因为它们有一些很棒的新功能(比如拖动&drop/copy&粘贴上传),但我不想回到 "pop-up file-browser".
我搜索了所有新文件浏览器的文档和 API plugins/options,但我仍然找不到这样的选项。
我是否错过了启用此功能的配置选项,还是仍然无法启用?
如果没有,是否有一个 "updated patch" 可以再次添加它,或者有人可以指出我可以自己添加的位置吗?
您无需修补 CKEditor 即可在按下“浏览服务器”按钮时调用您的自定义回调。检查以下更改图像对话框的示例代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Browse server - custom callback</title>
<script src="http://cdn.ckeditor.com/4.5.1/standard/ckeditor.js"></script>
</head>
<body>
<form action="sample_posteddata.php" method="post">
<textarea cols="80" id="editor1" name="editor1" rows="10">
</textarea>
<script>
CKEDITOR.on( 'dialogDefinition', function( ev ) {
// Take the dialog name and its definition from the event data.
var dialogName = ev.data.name;
var dialogDefinition = ev.data.definition;
// Check if the definition is from the dialog we're
// interested on (the "Image" dialog).
if ( dialogName == 'image' ) {
// Get a reference to the "Image Properties" tab.
var infoTab = dialogDefinition.getContents( 'info' );
// Get a reference to the "Browse Server" button.
var browse = infoTab.get( 'browse' );
// Instruct filebrowser plugin to skip hooking into this button.
browse[ 'filebrowser' ] = false;
// The "Browse Server" button is hidden by default.
browse[ 'hidden' ] = false;
// Add our own callback.
browse[ 'onClick' ] = function() {
var url = prompt( 'Type some URL' );
this.getDialog().getContentElement( 'info', 'txtUrl' ).setValue( url );
};
}
} );
CKEDITOR.replace( 'editor1' );
</script>
</form>
</body>
</html>