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')) {
15 * Définition de la barre 'edition' pour markitup
17 * @return Barre_outils La barre d'outil
19 function barre_outils_edition() {
20 $set = new Barre_outils(array(
21 'nameSpace' => 'edition',
22 #'previewAutoRefresh'=> true,
23 #'previewParserPath' => url_absolue(generer_url_public('preview')),
24 'onShiftEnter' => array('keepDefault' => false, 'replaceWith' => "\n_ "),
25 'onCtrlEnter' => array('keepDefault' => false, 'replaceWith' => "\n\n"),
26 // garder les listes si on appuie sur entree
27 'onEnter' => array('keepDefault' => false, 'selectionType' => 'return', 'replaceWith' => "\n"),
28 // Utile quand on saisi du code, mais pas accessible !
29 #'onTab' => array('keepDefault'=>false, 'replaceWith'=>"\t"),
34 'name' => _T('barreoutils:barre_intertitre'),
36 'className' => 'outil_header1',
37 'openWith' => "\n{{{",
38 'closeWith' => "}}}\n",
40 'selectionType' => 'line',
45 'name' => _T('barreoutils:barre_gras'),
47 'className' => 'outil_bold',
48 'replaceWith' => "function(h){ return espace_si_accolade(h, '{{', '}}');}",
50 //"closeWith" => "}}",
52 'selectionType' => 'word',
57 'name' => _T('barreoutils:barre_italic'),
59 'className' => 'outil_italic',
60 'replaceWith' => "function(h){ return espace_si_accolade(h, '{', '}');}",
64 'selectionType' => 'word',
67 // montrer une suppression
69 'id' => 'stroke_through',
70 'name' => _T('barreoutils:barre_barre'), // :-)
71 'className' => 'outil_stroke_through',
72 'openWith' => '<del>',
73 'closeWith' => '</del>',
75 'selectionType' => 'word',
81 'name' => _T('barreoutils:barre_liste_ul'),
82 'className' => 'outil_liste_ul',
83 'replaceWith' => "function(h){ return outil_liste(h, '*');}",
85 'selectionType' => 'line',
86 'forceMultiline' => true,
91 'name' => _T('barreoutils:barre_liste_ol'),
92 'className' => 'outil_liste_ol',
93 'replaceWith' => "function(h){ return outil_liste(h, '#');}",
95 'selectionType' => 'line',
96 'forceMultiline' => true,
100 'id' => 'desindenter',
101 'name' => _T('barreoutils:barre_desindenter'),
102 'className' => 'outil_desindenter',
103 'replaceWith' => 'function(h){return outil_desindenter(h);}',
105 'selectionType' => 'line',
106 'forceMultiline' => true,
111 'name' => _T('barreoutils:barre_indenter'),
112 'className' => 'outil_indenter',
113 'replaceWith' => 'function(h){return outil_indenter(h);}',
115 'selectionType' => 'line',
116 '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',
148 'id' => 'sepGuillemets',
149 'separator' => '---------------',
153 // (affichee dans forum)
156 'name' => _T('barreoutils:barre_quote'),
158 'className' => 'outil_quote',
159 'openWith' => "\n<quote>",
160 'closeWith' => "</quote>\n",
162 'selectionType' => 'word',
166 'id' => 'barre_poesie',
167 'name' => _T('barreoutils:barre_poesie'),
168 'className' => 'outil_poesie',
169 'openWith' => "\n<poesie>",
170 'closeWith' => "</poesie>\n",
172 'selectionType' => 'line',
178 'id' => 'guillemets',
179 'name' => _T('barreoutils:barre_guillemets'),
180 'className' => 'outil_guillemets',
181 'openWith' => '«',
182 'closeWith' => '»',
184 'lang' => array('fr', 'eo', 'cpf', 'ar', 'es'),
185 'selectionType' => 'word',
187 // guillemets internes
189 'id' => 'guillemets_simples',
190 'name' => _T('barreoutils:barre_guillemets_simples'),
191 'className' => 'outil_guillemets_simples',
192 'openWith' => '“',
193 'closeWith' => '”',
195 'lang' => array('fr', 'eo', 'cpf', 'ar', 'es'),
196 'selectionType' => 'word',
202 'id' => 'guillemets_de',
203 'name' => _T('barreoutils:barre_guillemets'),
204 'className' => 'outil_guillemets_de',
205 'openWith' => '„',
206 'closeWith' => '“',
208 'lang' => array('bg', 'de', 'pl', 'hr', 'src'),
209 'selectionType' => 'word',
211 // guillemets de, simples
213 'id' => 'guillemets_de_simples',
214 'name' => _T('barreoutils:barre_guillemets_simples'),
215 'className' => 'outil_guillemets_de_simples',
216 'openWith' => '‚',
217 'closeWith' => '‘',
219 'lang' => array('bg', 'de', 'pl', 'hr', 'src'),
220 'selectionType' => 'word',
225 // guillemets autres langues
227 'id' => 'guillemets_autres',
228 'name' => _T('barreoutils:barre_guillemets'),
229 'className' => 'outil_guillemets_simples',
230 'openWith' => '“',
231 'closeWith' => '”',
233 'lang_not' => array('fr', 'eo', 'cpf', 'ar', 'es', 'bg', 'de', 'pl', 'hr', 'src'),
234 'selectionType' => 'word',
236 // guillemets simples, autres langues
238 'id' => 'guillemets_autres_simples',
239 'name' => _T('barreoutils:barre_guillemets_simples'),
240 'className' => 'outil_guillemets_uniques',
241 'openWith' => '‘',
242 'closeWith' => '’',
244 'lang_not' => array('fr', 'eo', 'cpf', 'ar', 'es', 'bg', 'de', 'pl', 'hr', 'src'),
245 'selectionType' => 'word',
251 'id' => 'sepCaracteres',
252 'separator' => '---------------',
257 'id' => 'grpCaracteres',
258 'name' => _T('barreoutils:barre_inserer_caracteres'),
259 'className' => 'outil_caracteres',
262 // A majuscule accent grave
265 'name' => _T('barreoutils:barre_a_accent_grave'),
266 'className' => 'outil_a_maj_grave',
267 'replaceWith' => 'À',
269 'lang' => array('fr', 'eo', 'cpf'),
271 // E majuscule accent aigu
274 'name' => _T('barreoutils:barre_e_accent_aigu'),
275 'className' => 'outil_e_maj_aigu',
276 'replaceWith' => 'É',
278 'lang' => array('fr', 'eo', 'cpf'),
280 // E majuscule accent grave
283 'name' => _T('barreoutils:barre_e_accent_grave'),
284 'className' => 'outil_e_maj_grave',
285 'replaceWith' => 'È',
287 'lang' => array('fr', 'eo', 'cpf'),
292 'name' => _T('barreoutils:barre_ea'),
293 'className' => 'outil_aelig',
294 'replaceWith' => 'æ',
296 'lang' => array('fr', 'eo', 'cpf'),
298 // e dans le a majuscule
301 'name' => _T('barreoutils:barre_ea_maj'),
302 'className' => 'outil_aelig_maj',
303 'replaceWith' => 'Æ',
305 'lang' => array('fr', 'eo', 'cpf'),
310 'name' => _T('barreoutils:barre_eo'),
311 'className' => 'outil_oe',
312 'replaceWith' => 'œ',
314 'lang' => array('fr'),
319 'name' => _T('barreoutils:barre_eo_maj'),
320 'className' => 'outil_oe_maj',
321 'replaceWith' => 'Œ',
323 'lang' => array('fr'),
325 // c cedille majuscule
328 'name' => _T('barreoutils:barre_c_cedille_maj'),
329 'className' => 'outil_ccedil_maj',
330 'replaceWith' => 'Ç',
332 'lang' => array('fr', 'eo', 'cpf'),
334 // Transformation en majuscule
337 'name' => _T('barreoutils:barre_gestion_cr_changercassemajuscules'),
338 'className' => 'outil_uppercase',
339 'replaceWith' => 'function(markitup) { return markitup.selection.toUpperCase() }',
341 'lang' => array('fr', 'en'),
343 // Transformation en minuscule
346 'name' => _T('barreoutils:barre_gestion_cr_changercasseminuscules'),
347 'className' => 'outil_lowercase',
348 'replaceWith' => 'function(markitup) { return markitup.selection.toLowerCase() }',
350 'lang' => array('fr', 'en'),
355 // Groupe de Codes informatiques.
358 'separator' => '---------------',
362 // groupe code et bouton <code>
364 'name' => _T('barreoutils:barre_inserer_code'),
365 'className' => 'outil_code',
366 'openWith' => '<code>',
367 'closeWith' => '</code>',
373 'name' => _T('barreoutils:barre_inserer_cadre'),
374 'className' => 'outil_cadre',
375 'openWith' => "<cadre>\n",
376 'closeWith' => "\n</cadre>",
382 /* inutile (origine de markitup et non de spip)
386 "id" => "sepPreview", // trouver un nom correct !
387 "separator" => "---------------",
393 "name" => _T('barreoutils:barre_clean'),
394 "className" => "outil_clean",
395 "replaceWith" => 'function(markitup) { return markitup.selection.replace(/<(.*?)>/g, "") }',
401 "name" => _T('barreoutils:barre_preview'),
402 "className" => "outil_preview",
411 // remplace ou cree -* ou -** ou -# ou -##
412 function outil_liste(h, c) {
413 if ((s = h.selection) && (r = s.match(/^-([*#]+) (.*)\$/))) {
414 r[1] = r[1].replace(/[#*]/g, c);
415 s = '-'+r[1]+' '+r[2];
422 // indente des -* ou -#
423 function outil_indenter(h) {
424 if (s = h.selection) {
425 if (s.substr(0,2)=='-*') {
426 s = '-**' + s.substr(2);
427 } else if (s.substr(0,2)=='-#') {
428 s = '-##' + s.substr(2);
436 // desindente des -* ou -** ou -# ou -##
437 function outil_desindenter(h){
438 if (s = h.selection) {
439 if (s.substr(0,3)=='-**') {
440 s = '-*' + s.substr(3);
441 } else if (s.substr(0,3)=='-* ') {
443 } else if (s.substr(0,3)=='-##') {
444 s = '-#' + s.substr(3);
445 } else if (s.substr(0,3)=='-# ') {
452 // ajouter un espace avant, apres un {qqc} pour ne pas que
453 // gras {{}} suivi de italique {} donnent {{{}}}, mais { {{}} }
454 function espace_si_accolade(h, openWith, closeWith){
455 if (s = h.selection) {
456 // accolade dans la selection
457 if (s.charAt(0)=='{') {
458 return openWith + ' ' + s + ' ' + closeWith;
460 // accolade avant la selection
461 else if (c = h.textarea.selectionStart) {
462 if (h.textarea.value.charAt(c-1) == '{') {
463 return ' ' + openWith + s + closeWith + ' ';
467 return openWith + s + closeWith;
483 * Définitions des liens entre css et icones
486 * Couples identifiant de bouton => nom de l'image (ou tableau nom, position haut, position bas)
488 function barre_outils_edition_icones() {
490 //'outil_header1' => 'text_heading_1.png',
491 'outil_header1' => array('spt-v1.png', '-10px -226px'), //'intertitre.png'
492 'outil_bold' => array('spt-v1.png', '-10px -478px'), //'text_bold.png'
493 'outil_italic' => array('spt-v1.png', '-10px -586px'), //'text_italic.png'
495 'outil_stroke_through' => array('spt-v1.png', '-10px -946px'), //'text_strikethrough.png'
497 'outil_liste_ul' => array('spt-v1.png', '-10px -622px'), //'text_list_bullets.png'
498 'outil_liste_ol' => array('spt-v1.png', '-10px -658px'), //'text_list_numbers.png'
499 'outil_indenter' => array('spt-v1.png', '-10px -514px'), //'text_indent.png'
500 'outil_desindenter' => array('spt-v1.png', '-10px -550px'), //'text_indent_remove.png'
502 //'outil_quote' => 'text_indent.png',
503 'outil_quote' => array('spt-v1.png', '-10px -442px'), //'quote.png'
504 'outil_poesie' => array('spt-v1.png', '-10px -1050px'), //'poesie.png'
506 //'outil_link' => 'world_link.png',
507 'outil_link' => array('spt-v1.png', '-10px -298px'), //'lien.png'
508 'outil_notes' => array('spt-v1.png', '-10px -334px'), //'notes.png'
511 'outil_guillemets' => array('spt-v1.png', '-10px -910px'), //'guillemets.png'
512 'outil_guillemets_simples' => array('spt-v1.png', '-10px -802px'), //'guillemets-simples.png'
513 'outil_guillemets_de' => array('spt-v1.png', '-10px -766px'), //'guillemets-de.png'
514 'outil_guillemets_de_simples' => array('spt-v1.png', '-10px -838px'), //'guillemets-uniques-de.png'
515 'outil_guillemets_uniques' => array('spt-v1.png', '-10px -874px'), //'guillemets-uniques.png'
517 'outil_caracteres' => array('spt-v1.png', '-10px -262px'), //'keyboard.png'
518 'outil_a_maj_grave' => array('spt-v1.png', '-10px -82px'), //'agrave-maj.png'
519 'outil_e_maj_aigu' => array('spt-v1.png', '-10px -154px'), //'eacute-maj.png'
520 'outil_e_maj_grave' => array('spt-v1.png', '-10px -190px'), //'eagrave-maj.png'
521 'outil_aelig' => array('spt-v1.png', '-10px -46px'), //'aelig.png'
522 'outil_aelig_maj' => array('spt-v1.png', '-10px -10px'), //'aelig-maj.png'
523 'outil_oe' => array('spt-v1.png', '-10px -406px'), //'oelig.png'
524 'outil_oe_maj' => array('spt-v1.png', '-10px -370px'), //'oelig-maj.png'
525 'outil_ccedil_maj' => array('spt-v1.png', '-10px -118px'), //'ccedil-maj.png'
526 'outil_uppercase' => array('spt-v1.png', '-10px -730px'), //'text_uppercase.png'
527 'outil_lowercase' => array('spt-v1.png', '-10px -694px'), //'text_lowercase.png'
529 'outil_code' => array('spt-v1.png', '-10px -1086px'),
530 'outil_cadre' => array('spt-v1.png', '-10px -1122px'),
532 'outil_clean' => array('spt-v1.png', '-10px -982px'), //'clean.png'
533 'outil_preview' => array('spt-v1.png', '-10px -1018px'), //'eye.png'