I'm currently developing a image browser in PHP and jQuery. I've managed to create a custom button plugin that opens my image browser 开发者_运维百科in a new window (not a dialog box):
CKEDITOR.plugins.add('imgbrowser',
{
init: function(editor)
{
var pluginName = 'imgbrowser';
editor.ui.addButton('Imgbrowser',
{
label: 'Image browser',
command: pluginName,
click: function (editor) { window.open('/publish/browser/index.php','Image Browser','width=900,height=600'); }
});
}
});
Is there anyone here who knows how to enable the callback function and how this will be used so that I can add the selected pictures into the editor?
Ok. Here is the answer:
In the parent window I have this function:
function InsertHTML(file_path)
{
// Get the editor instance that we want to interact with.
var oEditor = CKEDITOR.instances.page_content;
var value = file_path;
// Check the active editing mode.
if ( oEditor.mode == 'wysiwyg' )
{
// Insert the desired HTML.
oEditor.insertHtml( '<img src="' + value + '" />' );
}
else
alert( 'You must be on WYSIWYG mode!' );
}
page_content is the id of my textarea.
In the popup window I have this function:
function sendToParent(file_path) {
window.opener.InsertHTML(file_path);
}
echo "<input type='button' value='Insert image' onclick='sendToParent(\"".$img_element."\")' />"
精彩评论