/*
* @file Audio plugin for CKEditor - fork from the Video plugin for CKEditor
* Copyright (C) 2014 BeezNest Latino S.A.C
*
* == BEGIN LICENSE ==
*
* Licensed under the terms of any of the following licenses at your
* choice:
*
* - GNU General Public License Version 2 or later (the "GPL")
* http://www.gnu.org/licenses/gpl.html
*
* - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
* http://www.gnu.org/licenses/lgpl.html
*
* - Mozilla Public License Version 1.1 or later (the "MPL")
* http://www.mozilla.org/MPL/MPL-1.1.html
*
* == END LICENSE ==
*
*/
(function() {
CKEDITOR.plugins.add('audio', {
// Translations, available at the end of this file, without extra requests
lang: ['en', 'es'],
getPlaceholderCss: function() {
return 'img.cke_audio' +
'{' +
'background-image: url(' + CKEDITOR.getUrl(this.path + 'images/placeholder.png') + ');' +
'background-position: center center;' +
'background-repeat: no-repeat;' +
'background-color:gray;' +
'border: 1px solid #a9a9a9;' +
'width: 80px;' +
'height: 40px;' +
'}';
},
onLoad: function() {
// v4
if (CKEDITOR.addCss)
CKEDITOR.addCss(this.getPlaceholderCss());
},
init: function(editor) {
var lang = editor.lang.audio;
// Check for CKEditor 3.5
if (typeof editor.element.data == 'undefined') {
alert('The "audio" plugin requires CKEditor 3.5 or newer');
return;
}
CKEDITOR.dialog.add('audio', this.path + 'dialogs/audio.js');
editor.addCommand('Audio', new CKEDITOR.dialogCommand('audio'));
editor.ui.addButton('Audio', {
label: lang.toolbar,
command: 'Audio',
icon: this.path + 'images/icon.png'
});
// v3
if (editor.addCss) {
editor.addCss(this.getPlaceholderCss());
}
// If the "menu" plugin is loaded, register the menu items.
if (editor.addMenuItems) {
editor.addMenuItems({
audio: {
label: lang.properties,
command: 'Audio',
group: 'flash'
}
});
}
editor.on('doubleclick', function(evt) {
var element = evt.data.element;
if (element.is('img') && element.data('cke-real-element-type') == 'audio') {
evt.data.dialog = 'audio';
}
});
// If the "contextmenu" plugin is loaded, register the listeners.
if (editor.contextMenu) {
editor.contextMenu.addListener(function(element, selection) {
if (element && element.is('img') && !element.isReadOnly()
&& element.data('cke-real-element-type') == 'audio') {
return {audio: CKEDITOR.TRISTATE_OFF};
}
});
}
// Add special handling for these items
CKEDITOR.dtd.$empty['cke:source'] = 1;
CKEDITOR.dtd.$empty['source'] = 1;
editor.lang.fakeobjects.audio = lang.fakeObject;
}, //Init
afterInit: function(editor) {
var dataProcessor = editor.dataProcessor,
htmlFilter = dataProcessor && dataProcessor.htmlFilter,
dataFilter = dataProcessor && dataProcessor.dataFilter;
// dataFilter : conversion from html input to internal data
dataFilter.addRules({
elements: {
$: function(realElement) {
if (realElement.name == 'audio') {
realElement.name = 'cke:audio';
for (var i = 0; i < realElement.children.length; i++) {
if (realElement.children[ i ].name == 'source') {
realElement.children[ i ].name = 'cke:source';
}
}
var fakeElement = editor.createFakeParserElement(realElement, 'cke_audio', 'audio', false),
fakeStyle = fakeElement.attributes.style || '';
var width = realElement.attributes.width;
if (typeof width != 'undefined') {
fakeElement.attributes.style = fakeStyle + 'width:' + CKEDITOR.tools.cssLength(width) + ';';
}
return fakeElement;
}
}
}
});
} // afterInit
}); // plugins.add
var en = {
toolbar: 'Audio',
dialogTitle: 'Audio properties',
fakeObject: 'Audio',
properties: 'Edit audio',
widthRequired: 'Width field cannot be empty',
heightRequired: 'Height field cannot be empty',
sourceAudio: 'Source audio',
sourceType: 'Audio type',
linkTemplate: '%type% ',
fallbackTemplate: 'Your browser doesn\'t support audio.
Please download the file: %links%',
autoPlay: 'Auto play'
};
var es = {
toolbar: 'Audio',
dialogTitle: 'Propiedades de audio',
fakeObject: 'Audio',
properties: 'Editar el audio',
widthRequired: 'La anchura no se puede dejar en blanco',
heightRequired: 'La altura no se puede dejar en blanco',
sourceAudio: 'Archivo de audio',
sourceType: 'Tipo',
linkTemplate: '%type% ',
fallbackTemplate: 'Su navegador no soporta AUDIO.
Por favor, descargue el fichero: %links%',
autoPlay: 'Reproducir automáticamente'
};
var fr = {
toolbar: 'Audio',
dialogTitle: 'Propriétés de l\'audio',
fakeObject: 'Audio',
properties: 'Editer l\'audio',
widthRequired: 'La largeur ne peut être vide',
heightRequired: 'La hauteur ne peut être vide',
sourceAudio: 'Fichier audio',
sourceType: 'Type',
linkTemplate: '%type% ',
fallbackTemplate: 'Votre navigateur ne supporte pas l\'AUDIO.
Veuillez télécharger le fichier: %links%',
autoPlay: 'Lecture automatique'
};
// v3
if (CKEDITOR.skins) {
en = {audio: en};
es = {audio: es};
}
// Translations
CKEDITOR.plugins.setLang('audio', 'en', en);
CKEDITOR.plugins.setLang('audio', 'es', es);
})();