3 * Déclaration de la barre d'outil d'édition de SPIP
5 * @plugin Porte Plume pour SPIP
7 * @package SPIP\PortePlume\BarreOutils
9 if (!defined("_ECRIRE_INC_VERSION")) return;
13 * Définition de la barre 'edition' pour markitup
15 * @return Barre_outils La barre d'outil
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"),
32 "name" => _T('barreoutils:barre_intertitre'),
34 "className" => "outil_header1",
35 "openWith" => "\n{{{",
36 "closeWith" => "}}}\n",
38 "selectionType" => "line",
43 "name" => _T('barreoutils:barre_gras'),
45 "className" => "outil_bold",
46 "replaceWith" => "function(h){ return espace_si_accolade(h, '{{', '}}');}",
48 //"closeWith" => "}}",
50 "selectionType" => "word",
55 "name" => _T('barreoutils:barre_italic'),
57 "className" => "outil_italic",
58 "replaceWith" => "function(h){ return espace_si_accolade(h, '{', '}');}",
62 "selectionType" => "word",
65 // montrer une suppression
67 "id" => 'stroke_through',
68 "name" => _T('barreoutils:barre_barre'), // :-)
69 "className" => "outil_stroke_through",
70 "openWith" => "<del>",
71 "closeWith" => "</del>",
73 "selectionType" => "word",
79 "name" => _T('barreoutils:barre_liste_ul'),
80 "className" => "outil_liste_ul",
81 "replaceWith" => "function(h){ return outil_liste(h, '*');}",
83 "selectionType" => "line",
84 "forceMultiline" => true,
89 "name" => _T('barreoutils:barre_liste_ol'),
90 "className" => "outil_liste_ol",
91 "replaceWith" => "function(h){ return outil_liste(h, '#');}",
93 "selectionType" => "line",
94 "forceMultiline" => true,
98 "id" => 'desindenter',
99 "name" => _T('barreoutils:barre_desindenter'),
100 "className" => "outil_desindenter",
101 "replaceWith" => "function(h){return outil_desindenter(h);}",
103 "selectionType" => "line",
104 "forceMultiline" => true,
109 "name" => _T('barreoutils:barre_indenter'),
110 "className" => "outil_indenter",
111 "replaceWith" => "function(h){return outil_indenter(h);}",
113 "selectionType" => "line",
114 "forceMultiline" => true,
122 "id" => "sepLink", // trouver un nom correct !
123 "separator" => "---------------",
129 "name" => _T('barreoutils:barre_lien'),
131 "className" => "outil_link",
133 "closeWith" => "->[!["._T('barreoutils:barre_lien_input')."]!]]",
136 // note en bas de page spip
139 "name" => _T('barreoutils:barre_note'),
140 "className" => "outil_notes",
144 "selectionType" => "word",
150 "id" => "sepGuillemets",
151 "separator" => "---------------",
156 // (affichee dans forum)
159 "name" => _T('barreoutils:barre_quote'),
161 "className" => "outil_quote",
162 "openWith" => "\n<quote>",
163 "closeWith" => "</quote>\n",
165 "selectionType" => "word",
169 "id" => 'barre_poesie',
170 "name" => _T('barreoutils:barre_poesie'),
171 "className" => "outil_poesie",
172 "openWith" => "\n<poesie>",
173 "closeWith" => "</poesie>\n",
175 "selectionType" => "line",
181 "id" => 'guillemets',
182 "name" => _T('barreoutils:barre_guillemets'),
183 "className" => "outil_guillemets",
184 "openWith" => "«",
185 "closeWith" => "»",
187 "lang" => array('fr','eo','cpf','ar','es'),
188 "selectionType" => "word",
190 // guillemets internes
192 "id" => 'guillemets_simples',
193 "name" => _T('barreoutils:barre_guillemets_simples'),
194 "className" => "outil_guillemets_simples",
195 "openWith" => "“",
196 "closeWith" => "”",
198 "lang" => array('fr','eo','cpf','ar','es'),
199 "selectionType" => "word",
206 "id" => 'guillemets_de',
207 "name" => _T('barreoutils:barre_guillemets'),
208 "className" => "outil_guillemets_de",
209 "openWith" => "„",
210 "closeWith" => "“",
212 "lang" => array('bg','de','pl','hr','src'),
213 "selectionType" => "word",
215 // guillemets de, simples
217 "id" => 'guillemets_de_simples',
218 "name" => _T('barreoutils:barre_guillemets_simples'),
219 "className" => "outil_guillemets_de_simples",
220 "openWith" => "‚",
221 "closeWith" => "‘",
223 "lang" => array('bg','de','pl','hr','src'),
224 "selectionType" => "word",
229 // guillemets autres langues
231 "id" => 'guillemets_autres',
232 "name" => _T('barreoutils:barre_guillemets'),
233 "className" => "outil_guillemets_simples",
234 "openWith" => "“",
235 "closeWith" => "”",
237 "lang_not" => array('fr','eo','cpf','ar','es','bg','de','pl','hr','src'),
238 "selectionType" => "word",
240 // guillemets simples, autres langues
242 "id" => 'guillemets_autres_simples',
243 "name" => _T('barreoutils:barre_guillemets_simples'),
244 "className" => "outil_guillemets_uniques",
245 "openWith" => "‘",
246 "closeWith" => "’",
248 "lang_not" => array('fr','eo','cpf','ar','es','bg','de','pl','hr','src'),
249 "selectionType" => "word",
257 "id" => "sepCaracteres",
258 "separator" => "---------------",
263 "id" => 'grpCaracteres',
264 "name" => _T('barreoutils:barre_inserer_caracteres'),
265 "className" => 'outil_caracteres',
269 // A majuscule accent grave
272 "name" => _T('barreoutils:barre_a_accent_grave'),
273 "className" => "outil_a_maj_grave",
274 "replaceWith" => "À",
276 "lang" => array('fr','eo','cpf'),
278 // E majuscule accent aigu
281 "name" => _T('barreoutils:barre_e_accent_aigu'),
282 "className" => "outil_e_maj_aigu",
283 "replaceWith" => "É",
285 "lang" => array('fr','eo','cpf'),
287 // E majuscule accent grave
290 "name" => _T('barreoutils:barre_e_accent_grave'),
291 "className" => "outil_e_maj_grave",
292 "replaceWith" => "È",
294 "lang" => array('fr','eo','cpf'),
299 "name" => _T('barreoutils:barre_ea'),
300 "className" => "outil_aelig",
301 "replaceWith" => "æ",
303 "lang" => array('fr','eo','cpf'),
305 // e dans le a majuscule
308 "name" => _T('barreoutils:barre_ea_maj'),
309 "className" => "outil_aelig_maj",
310 "replaceWith" => "Æ",
312 "lang" => array('fr','eo','cpf'),
317 "name" => _T('barreoutils:barre_eo'),
318 "className" => "outil_oe",
319 "replaceWith" => "œ",
321 "lang" => array('fr'),
326 "name" => _T('barreoutils:barre_eo_maj'),
327 "className" => "outil_oe_maj",
328 "replaceWith" => "Œ",
330 "lang" => array('fr'),
332 // c cedille majuscule
335 "name" => _T('barreoutils:barre_c_cedille_maj'),
336 "className" => "outil_ccedil_maj",
337 "replaceWith" => "Ç",
339 "lang" => array('fr','eo','cpf'),
341 // Transformation en majuscule
344 "name" => _T('barreoutils:barre_gestion_cr_changercassemajuscules'),
345 "className" => "outil_uppercase",
346 "replaceWith" => 'function(markitup) { return markitup.selection.toUpperCase() }',
348 "lang" => array('fr','en'),
350 // Transformation en minuscule
353 "name" => _T('barreoutils:barre_gestion_cr_changercasseminuscules'),
354 "className" => "outil_lowercase",
355 "replaceWith" => 'function(markitup) { return markitup.selection.toLowerCase() }',
357 "lang" => array('fr','en'),
362 // Groupe de Codes informatiques.
365 "separator" => "---------------",
369 // groupe code et bouton <code>
371 "name" => _T('barreoutils:barre_inserer_code'),
372 "className" => 'outil_code',
373 "openWith" => "<code>",
374 "closeWith" => "</code>",
380 "name" => _T('barreoutils:barre_inserer_cadre'),
381 "className" => 'outil_cadre',
382 "openWith" => "<cadre>\n",
383 "closeWith" => "\n</cadre>",
389 /* inutile (origine de markitup et non de spip)
393 "id" => "sepPreview", // trouver un nom correct !
394 "separator" => "---------------",
400 "name" => _T('barreoutils:barre_clean'),
401 "className" => "outil_clean",
402 "replaceWith" => 'function(markitup) { return markitup.selection.replace(/<(.*?)>/g, "") }',
408 "name" => _T('barreoutils:barre_preview'),
409 "className" => "outil_preview",
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];
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);
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)=='-* ') {
450 } else if (s.substr(0,3)=='-##') {
451 s = '-#' + s.substr(3);
452 } else if (s.substr(0,3)=='-# ') {
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;
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 + ' ';
474 return openWith + s + closeWith;
490 * Définitions des liens entre css et icones
493 * Couples identifiant de bouton => nom de l'image (ou tableau nom, position haut, position bas)
495 function barre_outils_edition_icones(){
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'
502 'outil_stroke_through' => array('spt-v1.png','-10px -946px'), //'text_strikethrough.png'
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'
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'
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'
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'
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'
536 'outil_code' => array('spt-v1.png','-10px -1086px'),
537 'outil_cadre' => array('spt-v1.png','-10px -1122px'),
539 'outil_clean' => array('spt-v1.png','-10px -982px'), //'clean.png'
540 'outil_preview' => array('spt-v1.png','-10px -1018px'), //'eye.png'