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