]> git.immae.eu Git - perso/Immae/Projets/packagist/piedsjaloux-ckeditor-component.git/blob - sources/plugins/Audio/plugin.js
ee618f6dd74805360549a7628dd44baa4e052726
[perso/Immae/Projets/packagist/piedsjaloux-ckeditor-component.git] / sources / plugins / Audio / plugin.js
1 /*
2 * @file audio plugin for CKEditor
3 * Copyright (C) 2011 Alfonso Martínez de Lizarrondo
4 *
5 * == BEGIN LICENSE ==
6 *
7 * Licensed under the terms of any of the following licenses at your
8 * choice:
9 *
10 * - GNU General Public License Version 2 or later (the "GPL")
11 * http://www.gnu.org/licenses/gpl.html
12 *
13 * - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
14 * http://www.gnu.org/licenses/lgpl.html
15 *
16 * - Mozilla Public License Version 1.1 or later (the "MPL")
17 * http://www.mozilla.org/MPL/MPL-1.1.html
18 *
19 * == END LICENSE ==
20 *
21 */
22
23 ( function() {
24
25 CKEDITOR.plugins.add( 'Audio',
26 {
27 // Translations, available at the end of this file, without extra requests
28 lang : [ 'en', 'es' ],
29
30 getPlaceholderCss : function()
31 {
32 return 'img.cke_audio' +
33 '{' +
34 'background-image: url(' + CKEDITOR.getUrl( this.path + 'images/placeholder.png' ) + ');' +
35 'background-position: center center;' +
36 'background-repeat: no-repeat;' +
37 'background-color:gray;'+
38 'border: 1px solid #a9a9a9;' +
39 'width: 80px;' +
40 'height: 80px;' +
41 '}';
42 },
43
44 onLoad : function()
45 {
46 // v4
47 if (CKEDITOR.addCss)
48 CKEDITOR.addCss( this.getPlaceholderCss() );
49
50 },
51
52 init : function( editor )
53 {
54 var lang = editor.lang.audio;
55
56 // Check for CKEditor 3.5
57 if (typeof editor.element.data == 'undefined')
58 {
59 alert('The "audio" plugin requires CKEditor 3.5 or newer');
60 return;
61 }
62
63 CKEDITOR.dialog.add( 'audio', this.path + 'dialogs/audio.js' );
64
65 editor.addCommand( 'Audio', new CKEDITOR.dialogCommand( 'audio' ) );
66 editor.ui.addButton( 'Audio',
67 {
68 label : lang.toolbar,
69 command : 'Audio',
70 icon : this.path + 'images/icon.png'
71 } );
72
73 // v3
74 if (editor.addCss)
75 editor.addCss( this.getPlaceholderCss() );
76
77
78 // If the "menu" plugin is loaded, register the menu items.
79 if ( editor.addMenuItems )
80 {
81 editor.addMenuItems(
82 {
83 audio :
84 {
85 label : lang.properties,
86 command : 'Audio',
87 group : 'flash'
88 }
89 });
90 }
91
92 editor.on( 'doubleclick', function( evt )
93 {
94 var element = evt.data.element;
95
96 if ( element.is( 'img' ) && element.data( 'cke-real-element-type' ) == 'audio' )
97 evt.data.dialog = 'audio';
98 });
99
100 // If the "contextmenu" plugin is loaded, register the listeners.
101 if ( editor.contextMenu )
102 {
103 editor.contextMenu.addListener( function( element, selection )
104 {
105 if ( element && element.is( 'img' ) && !element.isReadOnly()
106 && element.data( 'cke-real-element-type' ) == 'audio' )
107 return { audio : CKEDITOR.TRISTATE_OFF };
108 });
109 }
110
111 // Add special handling for these items
112 CKEDITOR.dtd.$empty['cke:source']=1;
113 CKEDITOR.dtd.$empty['source']=1;
114
115 editor.lang.fakeobjects.audio = lang.fakeObject;
116
117
118 }, //Init
119
120 afterInit: function( editor )
121 {
122 var dataProcessor = editor.dataProcessor,
123 htmlFilter = dataProcessor && dataProcessor.htmlFilter,
124 dataFilter = dataProcessor && dataProcessor.dataFilter;
125
126 // dataFilter : conversion from html input to internal data
127 dataFilter.addRules(
128 {
129
130 elements : {
131 $ : function( realElement )
132 {
133 if ( realElement.name == 'audio' )
134 {
135 realElement.name = 'cke:audio';
136 for( var i=0; i < realElement.children.length; i++)
137 {
138 if ( realElement.children[ i ].name == 'source' )
139 realElement.children[ i ].name = 'cke:source'
140 }
141
142 var fakeElement = editor.createFakeParserElement( realElement, 'cke_audio', 'audio', false ),
143 fakeStyle = fakeElement.attributes.style || '';
144
145 var width = realElement.attributes.width,
146 height = realElement.attributes.height,
147 poster = realElement.attributes.poster;
148
149 if ( typeof width != 'undefined' )
150 fakeStyle = fakeElement.attributes.style = fakeStyle + 'width:' + CKEDITOR.tools.cssLength( width ) + ';';
151
152 if ( typeof height != 'undefined' )
153 fakeStyle = fakeElement.attributes.style = fakeStyle + 'height:' + CKEDITOR.tools.cssLength( height ) + ';';
154
155 if ( poster )
156 fakeStyle = fakeElement.attributes.style = fakeStyle + 'background-image:url(' + poster + ');';
157
158 return fakeElement;
159 }
160 }
161 }
162
163 }
164 );
165
166 } // afterInit
167
168 } ); // plugins.add
169
170
171 var en = {
172 toolbar : 'Audio',
173 dialogTitle : 'Audio properties',
174 fakeObject : 'Audio',
175 properties : 'Edit audio',
176 widthRequired : 'Width field cannot be empty',
177 heightRequired : 'Height field cannot be empty',
178 poster: 'Poster image',
179 sourceaudio: 'Source audio',
180 sourceType : 'Audio type',
181 linkTemplate : '<a href="%src%">%type%</a> ',
182 fallbackTemplate : 'Your browser doesn\'t support audio.<br>Please download the file: %links%'
183 };
184
185 var es = {
186 toolbar : 'Audio',
187 dialogTitle : 'Propiedades de audio',
188 fakeObject : 'Audio',
189 properties : 'Editar el audio',
190 widthRequired : 'La anchura no se puede dejar en blanco',
191 heightRequired : 'La altura no se puede dejar en blanco',
192 poster: 'Imagen de presentación',
193 sourceaudio: 'Archivo de audio',
194 sourceType : 'Tipo',
195 linkTemplate : '<a href="%src%">%type%</a> ',
196 fallbackTemplate : 'Su navegador no soporta audio.<br>Por favor, descargue el fichero: %links%'
197 };
198
199 // v3
200 if (CKEDITOR.skins)
201 {
202 en = { audio : en} ;
203 es = { audio : es} ;
204 }
205
206 // Translations
207 CKEDITOR.plugins.setLang( 'audio', 'en', en );
208
209 CKEDITOR.plugins.setLang( 'audio', 'es', es );
210
211 })();