Bachir Soussi Chiadmi 1bc61b12ad first import
2015-04-08 11:40:19 +02:00

59 lines
1.6 KiB
JavaScript

/*
Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.html or http://ckeditor.com/license
*/
/**
* @file Plugin for inserting images from Drupal media module
*/
( function() {
CKEDITOR.plugins.add( 'media',
{
// Wrap Drupal plugin in a proxy plugin.
init: function(editor)
{
var pluginCommand = {
exec: function (editor) {
var data = {
format: 'html',
node: null,
content: ''
};
var selection = editor.getSelection();
if (selection) {
data.node = selection.getSelectedElement();
if (data.node) {
data.node = data.node.$;
}
if (selection.getType() == CKEDITOR.SELECTION_TEXT) {
if (CKEDITOR.env.ie) {
data.content = selection.getNative().createRange().text;
}
else {
data.content = selection.getNative().toString();
}
}
else if (data.node) {
// content is supposed to contain the "outerHTML".
data.content = data.node.parentNode.innerHTML;
}
}
Drupal.settings.ckeditor.plugins['media'].invoke(data, Drupal.settings.ckeditor.plugins['media'], editor.name);
}
};
editor.addCommand( 'media', pluginCommand );
editor.ui.addButton( 'Media',
{
label: 'Add media',
command: 'media',
icon: this.path + 'images/icon.gif'
});
}
});
} )();