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