[SPIP] +2.1.12
[velocampus/web/www.git] / www / extensions / porte_plume / barre_outils / edition.php
1 <?php
2 /*
3 * Plugin Porte Plume pour SPIP 2
4 * Licence GPL
5 * Auteur Matthieu Marcillaud
6 */
7 if (!defined("_ECRIRE_INC_VERSION")) return;
8
9
10 /**
11 * Definition de la barre 'edition' pour markitup
12 */
13 function barre_outils_edition(){
14 $set = new Barre_outils(array(
15 'nameSpace' => 'edition',
16 #'previewAutoRefresh'=> true,
17 #'previewParserPath' => url_absolue(generer_url_public('preview')),
18 'onShiftEnter' => array('keepDefault'=>false, 'replaceWith'=>"\n_ "),
19 'onCtrlEnter' => array('keepDefault'=>false, 'replaceWith'=>"\n\n"),
20 // garder les listes si on appuie sur entree
21 'onEnter' => array('keepDefault'=>false, 'selectionType'=>'return', 'replaceWith'=>"\n"),
22 // Utile quand on saisi du code, mais pas accessible !
23 #'onTab' => array('keepDefault'=>false, 'replaceWith'=>"\t"),
24 'markupSet' => array(
25 // H1 - {{{
26 array(
27 "id" => 'header1',
28 "name" => _T('barre_outils:barre_intertitre'),
29 "key" => "H",
30 "className" => "outil_header1",
31 "openWith" => "\n{{{",
32 "closeWith" => "}}}\n",
33 "display" => true,
34 "selectionType" => "line",
35 ),
36 // Bold - {{
37 array(
38 "id" => 'bold',
39 "name" => _T('barre_outils:barre_gras'),
40 "key" => "B",
41 "className" => "outil_bold",
42 "replaceWith" => "function(h){ return espace_si_accolade(h, '{{', '}}');}",
43 //"openWith" => "{{",
44 //"closeWith" => "}}",
45 "display" => true,
46 "selectionType" => "word",
47 ),
48 // Italic - {
49 array(
50 "id" => 'italic',
51 "name" => _T('barre_outils:barre_italic'),
52 "key" => "I",
53 "className" => "outil_italic",
54 "replaceWith" => "function(h){ return espace_si_accolade(h, '{', '}');}",
55 //"openWith" => "{",
56 //"closeWith" => "}",
57 "display" => true,
58 "selectionType" => "word",
59 ),
60
61 // montrer une suppression
62 array(
63 "id" => 'stroke_through',
64 "name" => _T('barre_outils:barre_barre'), // :-)
65 "className" => "outil_stroke_through",
66 "openWith" => "<del>",
67 "closeWith" => "</del>",
68 "display" => true,
69 "selectionType" => "word",
70 ),
71
72 // listes -*
73 array(
74 "id" => 'liste_ul',
75 "name" => _T('barre_outils:barre_liste_ul'),
76 "className" => "outil_liste_ul",
77 "replaceWith" => "function(h){ return outil_liste(h, '*');}",
78 "display" => true,
79 "selectionType" => "line",
80 "forceMultiline" => true,
81 "dropMenu" => array(
82 // liste -#
83 array(
84 "id" => 'liste_ol',
85 "name" => _T('barre_outils:barre_liste_ol'),
86 "className" => "outil_liste_ol",
87 "replaceWith" => "function(h){ return outil_liste(h, '#');}",
88 "display" => true,
89 "selectionType" => "line",
90 "forceMultiline" => true,
91 ),
92 // desindenter
93 array(
94 "id" => 'desindenter',
95 "name" => _T('barre_outils:barre_desindenter'),
96 "className" => "outil_desindenter",
97 "replaceWith" => "function(h){return outil_desindenter(h);}",
98 "display" => true,
99 "selectionType" => "line",
100 "forceMultiline" => true,
101 ),
102 // indenter
103 array(
104 "id" => 'indenter',
105 "name" => _T('barre_outils:barre_indenter'),
106 "className" => "outil_indenter",
107 "replaceWith" => "function(h){return outil_indenter(h);}",
108 "display" => true,
109 "selectionType" => "line",
110 "forceMultiline" => true,
111 ),
112 ),
113 ),
114
115
116
117 // separation
118 array(
119 "id" => "sepLink", // trouver un nom correct !
120 "separator" => "---------------",
121 "display" => true,
122 ),
123 // lien spip
124 array(
125 "id" => 'link',
126 "name" => _T('barre_outils:barre_lien'),
127 "key" => "L",
128 "className" => "outil_link",
129 "openWith" => "[",
130 "closeWith" => "->[!["._T('barre_outils:barre_lien_input')."]!]]",
131 "display" => true,
132 ),
133 // note en bas de page spip
134 array(
135 "id" => 'notes',
136 "name" => _T('barre_outils:barre_note'),
137 "className" => "outil_notes",
138 "openWith" => "[[",
139 "closeWith" => "]]",
140 "display" => true,
141 "selectionType" => "word",
142 ),
143
144
145 // separation
146 array(
147 "id" => "sepGuillemets",
148 "separator" => "---------------",
149 "display" => true,
150 ),
151
152 // quote spip
153 // (affichee dans forum)
154 array(
155 "id" => 'quote',
156 "name" => _T('barre_outils:barre_quote'),
157 "key" => "Q",
158 "className" => "outil_quote",
159 "openWith" => "\n<quote>",
160 "closeWith" => "</quote>\n",
161 "display" => true,
162 "selectionType" => "word",
163 ),
164 // guillemets
165 array(
166 "id" => 'guillemets',
167 "name" => _T('barre_outils:barre_guillemets'),
168 "className" => "outil_guillemets",
169 "openWith" => "&laquo;",
170 "closeWith" => "&raquo;",
171 "display" => true,
172 "lang" => array('fr','eo','cpf','ar','es'),
173 "selectionType" => "word",
174 ),
175 // guillemets internes
176 array(
177 "id" => 'guillemets_simples',
178 "name" => _T('barre_outils:barre_guillemets_simples'),
179 "className" => "outil_guillemets_simples",
180 "openWith" => "&ldquo;",
181 "closeWith" => "&rdquo;",
182 "display" => true,
183 "lang" => array('fr','eo','cpf','ar','es'),
184 "selectionType" => "word",
185 ),
186 // guillemets de
187 array(
188 "id" => 'guillemets_de',
189 "name" => _T('barre_outils:barre_guillemets'),
190 "className" => "outil_guillemets_de",
191 "openWith" => "&bdquo;",
192 "closeWith" => "&ldquo;",
193 "display" => true,
194 "lang" => array('bg','de','pl','hr','src'),
195 "selectionType" => "word",
196 ),
197 // guillemets de, simples
198 array(
199 "id" => 'guillemets_de_simples',
200 "name" => _T('barre_outils:barre_guillemets_simples'),
201 "className" => "outil_guillemets_de_simples",
202 "openWith" => "&sbquo;",
203 "closeWith" => "&lsquo;",
204 "display" => true,
205 "lang" => array('bg','de','pl','hr','src'),
206 "selectionType" => "word",
207 ),
208 // guillemets autres langues
209 array(
210 "id" => 'guillemets_autres',
211 "name" => _T('barre_outils:barre_guillemets'),
212 "className" => "outil_guillemets_simples",
213 "openWith" => "&ldquo;",
214 "closeWith" => "&rdquo;",
215 "display" => true,
216 "lang_not" => array('fr','eo','cpf','ar','es','bg','de','pl','hr','src'),
217 "selectionType" => "word",
218 ),
219 // guillemets simples, autres langues
220 array(
221 "id" => 'guillemets_autres_simples',
222 "name" => _T('barre_outils:barre_guillemets_simples'),
223 "className" => "outil_guillemets_uniques",
224 "openWith" => "&lsquo;",
225 "closeWith" => "&rsquo;",
226 "display" => true,
227 "lang_not" => array('fr','eo','cpf','ar','es','bg','de','pl','hr','src'),
228 "selectionType" => "word",
229 ),
230
231 // separation
232 array(
233 "id" => "sepCaracteres",
234 "separator" => "---------------",
235 "display" => true,
236 ),
237 // icones clavier
238 array(
239 "id" => 'grpCaracteres',
240 "name" => _T('barre_outils:barre_inserer_caracteres'),
241 "className" => 'outil_caracteres',
242 "display" => true,
243
244 "dropMenu" => array(
245 // A majuscule accent grave
246 array(
247 "id" => 'A_grave',
248 "name" => _T('barre_outils:barre_a_accent_grave'),
249 "className" => "outil_a_maj_grave",
250 "replaceWith" => "&Agrave;",
251 "display" => true,
252 "lang" => array('fr','eo','cpf'),
253 ),
254 // E majuscule accent aigu
255 array(
256 "id" => 'E_aigu',
257 "name" => _T('barre_outils:barre_e_accent_aigu'),
258 "className" => "outil_e_maj_aigu",
259 "replaceWith" => "&Eacute;",
260 "display" => true,
261 "lang" => array('fr','eo','cpf'),
262 ),
263 // E majuscule accent grave
264 array(
265 "id" => 'E_grave',
266 "name" => _T('barre_outils:barre_e_accent_grave'),
267 "className" => "outil_e_maj_grave",
268 "replaceWith" => "&Egrave;",
269 "display" => true,
270 "lang" => array('fr','eo','cpf'),
271 ),
272 // e dans le a
273 array(
274 "id" => 'aelig',
275 "name" => _T('barre_outils:barre_ea'),
276 "className" => "outil_aelig",
277 "replaceWith" => "&aelig;",
278 "display" => true,
279 "lang" => array('fr','eo','cpf'),
280 ),
281 // e dans le a majuscule
282 array(
283 "id" => 'AElig',
284 "name" => _T('barre_outils:barre_ea_maj'),
285 "className" => "outil_aelig_maj",
286 "replaceWith" => "&AElig;",
287 "display" => true,
288 "lang" => array('fr','eo','cpf'),
289 ),
290 // oe
291 array(
292 "id" => 'oe',
293 "name" => _T('barre_outils:barre_eo'),
294 "className" => "outil_oe",
295 "replaceWith" => "&oelig;",
296 "display" => true,
297 "lang" => array('fr'),
298 ),
299 // OE
300 array(
301 "id" => 'OE',
302 "name" => _T('barre_outils:barre_eo_maj'),
303 "className" => "outil_oe_maj",
304 "replaceWith" => "&OElig;",
305 "display" => true,
306 "lang" => array('fr'),
307 ),
308 // c cedille majuscule
309 array(
310 "id" => 'Ccedil',
311 "name" => _T('barre_outils:barre_c_cedille_maj'),
312 "className" => "outil_ccedil_maj",
313 "replaceWith" => "&Ccedil;",
314 "display" => true,
315 "lang" => array('fr','eo','cpf'),
316 ),
317 // Transformation en majuscule
318 array(
319 "id" => 'uppercase',
320 "name" => _T('barre_outils:barre_gestion_cr_changercassemajuscules'),
321 "className" => "outil_uppercase",
322 "replaceWith" => 'function(markitup) { return markitup.selection.toUpperCase() }',
323 "display" => true,
324 "lang" => array('fr','en'),
325 ),
326 // Transformation en minuscule
327 array(
328 "id" => 'lowercase',
329 "name" => _T('barre_outils:barre_gestion_cr_changercasseminuscules'),
330 "className" => "outil_lowercase",
331 "replaceWith" => 'function(markitup) { return markitup.selection.toLowerCase() }',
332 "display" => true,
333 "lang" => array('fr','en'),
334 ),
335 ),
336 ),
337
338 /* inutile (origine de markitup et non de spip)
339
340 // separation
341 array(
342 "id" => "sepPreview", // trouver un nom correct !
343 "separator" => "---------------",
344 "display" => true,
345 ),
346 // clean
347 array(
348 "id" => 'clean',
349 "name" => _T('barre_outils:barre_clean'),
350 "className" => "outil_clean",
351 "replaceWith" => 'function(markitup) { return markitup.selection.replace(/<(.*?)>/g, "") }',
352 "display" => true,
353 ),
354 // preview
355 array(
356 "id" => 'preview',
357 "name" => _T('barre_outils:barre_preview'),
358 "className" => "outil_preview",
359 "call" => "preview",
360 "display" => true,
361 ),
362 */
363
364 ),
365
366 'functions' => "
367 // remplace ou cree -* ou -** ou -# ou -##
368 function outil_liste(h, c) {
369 if ((s = h.selection) && (r = s.match(/^-([*#]+) (.*)\$/))) {
370 r[1] = r[1].replace(/[#*]/g, c);
371 s = '-'+r[1]+' '+r[2];
372 } else {
373 s = '-' + c + ' '+s;
374 }
375 return s;
376 }
377
378 // indente des -* ou -#
379 function outil_indenter(h) {
380 if (s = h.selection) {
381 if (s.substr(0,2)=='-*') {
382 s = '-**' + s.substr(2);
383 } else if (s.substr(0,2)=='-#') {
384 s = '-##' + s.substr(2);
385 } else {
386 s = '-* ' + s;
387 }
388 }
389 return s;
390 }
391
392 // desindente des -* ou -** ou -# ou -##
393 function outil_desindenter(h){
394 if (s = h.selection) {
395 if (s.substr(0,3)=='-**') {
396 s = '-*' + s.substr(3);
397 } else if (s.substr(0,3)=='-* ') {
398 s = s.substr(3);
399 } else if (s.substr(0,3)=='-##') {
400 s = '-#' + s.substr(3);
401 } else if (s.substr(0,3)=='-# ') {
402 s = s.substr(3);
403 }
404 }
405 return s;
406 }
407
408 // ajouter un espace avant, apres un {qqc} pour ne pas que
409 // gras {{}} suivi de italique {} donnent {{{}}}, mais { {{}} }
410 function espace_si_accolade(h, openWith, closeWith){
411 if (s = h.selection) {
412 // accolade dans la selection
413 if (s.charAt(0)=='{') {
414 return openWith + ' ' + s + ' ' + closeWith;
415 }
416 // accolade avant la selection
417 else if (c = h.textarea.selectionStart) {
418 if (h.textarea.value.charAt(c-1) == '{') {
419 return ' ' + openWith + s + closeWith + ' ';
420 }
421 }
422 }
423 return openWith + s + closeWith;
424 }
425 ",
426 ));
427
428 $set->cacher(array(
429 'stroke_through',
430 'clean', 'preview',
431 ));
432
433 return $set;
434 }
435
436
437
438 /**
439 * Definitions des liens entre css et icones
440 */
441 function barre_outils_edition_icones(){
442 return array(
443 //'outil_header1' => 'text_heading_1.png',
444 'outil_header1' => array('spt-v1.png','-10px -226px'), //'intertitre.png'
445 'outil_bold' => array('spt-v1.png','-10px -478px'), //'text_bold.png'
446 'outil_italic' => array('spt-v1.png','-10px -586px'), //'text_italic.png'
447
448 'outil_stroke_through' => array('spt-v1.png','-10px -946px'), //'text_strikethrough.png'
449
450 'outil_liste_ul' => array('spt-v1.png','-10px -622px'), //'text_list_bullets.png'
451 'outil_liste_ol' => array('spt-v1.png','-10px -658px'), //'text_list_numbers.png'
452 'outil_indenter' => array('spt-v1.png','-10px -514px'), //'text_indent.png'
453 'outil_desindenter' => array('spt-v1.png','-10px -550px'), //'text_indent_remove.png'
454
455 //'outil_quote' => 'text_indent.png',
456 'outil_quote' => array('spt-v1.png','-10px -442px'), //'quote.png'
457
458 //'outil_link' => 'world_link.png',
459 'outil_link' => array('spt-v1.png','-10px -298px'), //'lien.png'
460 'outil_notes' => array('spt-v1.png','-10px -334px'), //'notes.png'
461
462
463 'outil_guillemets' => array('spt-v1.png','-10px -910px'), //'guillemets.png'
464 'outil_guillemets_simples' => array('spt-v1.png','-10px -802px'), //'guillemets-simples.png'
465 'outil_guillemets_de' => array('spt-v1.png','-10px -766px'), //'guillemets-de.png'
466 'outil_guillemets_de_simples' => array('spt-v1.png','-10px -838px'), //'guillemets-uniques-de.png'
467 'outil_guillemets_uniques' => array('spt-v1.png','-10px -874px'), //'guillemets-uniques.png'
468
469 'outil_caracteres' => array('spt-v1.png','-10px -262px'), //'keyboard.png'
470 'outil_a_maj_grave' => array('spt-v1.png','-10px -82px'), //'agrave-maj.png'
471 'outil_e_maj_aigu' => array('spt-v1.png','-10px -154px'), //'eacute-maj.png'
472 'outil_e_maj_grave' => array('spt-v1.png','-10px -190px'), //'eagrave-maj.png'
473 'outil_aelig' => array('spt-v1.png','-10px -46px'), //'aelig.png'
474 'outil_aelig_maj' => array('spt-v1.png','-10px -10px'), //'aelig-maj.png'
475 'outil_oe' => array('spt-v1.png','-10px -406px'), //'oelig.png'
476 'outil_oe_maj' => array('spt-v1.png','-10px -370px'), //'oelig-maj.png'
477 'outil_ccedil_maj' => array('spt-v1.png','-10px -118px'), //'ccedil-maj.png'
478 'outil_uppercase' => array('spt-v1.png','-10px -730px'), //'text_uppercase.png'
479 'outil_lowercase' => array('spt-v1.png','-10px -694px'), //'text_lowercase.png'
480
481 'outil_clean' => array('spt-v1.png','-10px -982px'), //'clean.png'
482 'outil_preview' => array('spt-v1.png','-10px -1018px'), //'eye.png'
483 );
484 }
485 ?>