3 * Plugin Porte Plume pour SPIP 2
5 * Auteur Matthieu Marcillaud
7 if (!defined("_ECRIRE_INC_VERSION")) return;
11 * Definition de la barre 'edition' pour markitup
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"),
28 "name" => _T('barre_outils:barre_intertitre'),
30 "className" => "outil_header1",
31 "openWith" => "\n{{{",
32 "closeWith" => "}}}\n",
34 "selectionType" => "line",
39 "name" => _T('barre_outils:barre_gras'),
41 "className" => "outil_bold",
42 "replaceWith" => "function(h){ return espace_si_accolade(h, '{{', '}}');}",
44 //"closeWith" => "}}",
46 "selectionType" => "word",
51 "name" => _T('barre_outils:barre_italic'),
53 "className" => "outil_italic",
54 "replaceWith" => "function(h){ return espace_si_accolade(h, '{', '}');}",
58 "selectionType" => "word",
61 // montrer une suppression
63 "id" => 'stroke_through',
64 "name" => _T('barre_outils:barre_barre'), // :-)
65 "className" => "outil_stroke_through",
66 "openWith" => "<del>",
67 "closeWith" => "</del>",
69 "selectionType" => "word",
75 "name" => _T('barre_outils:barre_liste_ul'),
76 "className" => "outil_liste_ul",
77 "replaceWith" => "function(h){ return outil_liste(h, '*');}",
79 "selectionType" => "line",
80 "forceMultiline" => true,
85 "name" => _T('barre_outils:barre_liste_ol'),
86 "className" => "outil_liste_ol",
87 "replaceWith" => "function(h){ return outil_liste(h, '#');}",
89 "selectionType" => "line",
90 "forceMultiline" => true,
94 "id" => 'desindenter',
95 "name" => _T('barre_outils:barre_desindenter'),
96 "className" => "outil_desindenter",
97 "replaceWith" => "function(h){return outil_desindenter(h);}",
99 "selectionType" => "line",
100 "forceMultiline" => true,
105 "name" => _T('barre_outils:barre_indenter'),
106 "className" => "outil_indenter",
107 "replaceWith" => "function(h){return outil_indenter(h);}",
109 "selectionType" => "line",
110 "forceMultiline" => true,
119 "id" => "sepLink", // trouver un nom correct !
120 "separator" => "---------------",
126 "name" => _T('barre_outils:barre_lien'),
128 "className" => "outil_link",
130 "closeWith" => "->[!["._T('barre_outils:barre_lien_input')."]!]]",
133 // note en bas de page spip
136 "name" => _T('barre_outils:barre_note'),
137 "className" => "outil_notes",
141 "selectionType" => "word",
147 "id" => "sepGuillemets",
148 "separator" => "---------------",
153 // (affichee dans forum)
156 "name" => _T('barre_outils:barre_quote'),
158 "className" => "outil_quote",
159 "openWith" => "\n<quote>",
160 "closeWith" => "</quote>\n",
162 "selectionType" => "word",
166 "id" => 'guillemets',
167 "name" => _T('barre_outils:barre_guillemets'),
168 "className" => "outil_guillemets",
169 "openWith" => "«",
170 "closeWith" => "»",
172 "lang" => array('fr','eo','cpf','ar','es'),
173 "selectionType" => "word",
175 // guillemets internes
177 "id" => 'guillemets_simples',
178 "name" => _T('barre_outils:barre_guillemets_simples'),
179 "className" => "outil_guillemets_simples",
180 "openWith" => "“",
181 "closeWith" => "”",
183 "lang" => array('fr','eo','cpf','ar','es'),
184 "selectionType" => "word",
188 "id" => 'guillemets_de',
189 "name" => _T('barre_outils:barre_guillemets'),
190 "className" => "outil_guillemets_de",
191 "openWith" => "„",
192 "closeWith" => "“",
194 "lang" => array('bg','de','pl','hr','src'),
195 "selectionType" => "word",
197 // guillemets de, simples
199 "id" => 'guillemets_de_simples',
200 "name" => _T('barre_outils:barre_guillemets_simples'),
201 "className" => "outil_guillemets_de_simples",
202 "openWith" => "‚",
203 "closeWith" => "‘",
205 "lang" => array('bg','de','pl','hr','src'),
206 "selectionType" => "word",
208 // guillemets autres langues
210 "id" => 'guillemets_autres',
211 "name" => _T('barre_outils:barre_guillemets'),
212 "className" => "outil_guillemets_simples",
213 "openWith" => "“",
214 "closeWith" => "”",
216 "lang_not" => array('fr','eo','cpf','ar','es','bg','de','pl','hr','src'),
217 "selectionType" => "word",
219 // guillemets simples, autres langues
221 "id" => 'guillemets_autres_simples',
222 "name" => _T('barre_outils:barre_guillemets_simples'),
223 "className" => "outil_guillemets_uniques",
224 "openWith" => "‘",
225 "closeWith" => "’",
227 "lang_not" => array('fr','eo','cpf','ar','es','bg','de','pl','hr','src'),
228 "selectionType" => "word",
233 "id" => "sepCaracteres",
234 "separator" => "---------------",
239 "id" => 'grpCaracteres',
240 "name" => _T('barre_outils:barre_inserer_caracteres'),
241 "className" => 'outil_caracteres',
245 // A majuscule accent grave
248 "name" => _T('barre_outils:barre_a_accent_grave'),
249 "className" => "outil_a_maj_grave",
250 "replaceWith" => "À",
252 "lang" => array('fr','eo','cpf'),
254 // E majuscule accent aigu
257 "name" => _T('barre_outils:barre_e_accent_aigu'),
258 "className" => "outil_e_maj_aigu",
259 "replaceWith" => "É",
261 "lang" => array('fr','eo','cpf'),
263 // E majuscule accent grave
266 "name" => _T('barre_outils:barre_e_accent_grave'),
267 "className" => "outil_e_maj_grave",
268 "replaceWith" => "È",
270 "lang" => array('fr','eo','cpf'),
275 "name" => _T('barre_outils:barre_ea'),
276 "className" => "outil_aelig",
277 "replaceWith" => "æ",
279 "lang" => array('fr','eo','cpf'),
281 // e dans le a majuscule
284 "name" => _T('barre_outils:barre_ea_maj'),
285 "className" => "outil_aelig_maj",
286 "replaceWith" => "Æ",
288 "lang" => array('fr','eo','cpf'),
293 "name" => _T('barre_outils:barre_eo'),
294 "className" => "outil_oe",
295 "replaceWith" => "œ",
297 "lang" => array('fr'),
302 "name" => _T('barre_outils:barre_eo_maj'),
303 "className" => "outil_oe_maj",
304 "replaceWith" => "Œ",
306 "lang" => array('fr'),
308 // c cedille majuscule
311 "name" => _T('barre_outils:barre_c_cedille_maj'),
312 "className" => "outil_ccedil_maj",
313 "replaceWith" => "Ç",
315 "lang" => array('fr','eo','cpf'),
317 // Transformation en majuscule
320 "name" => _T('barre_outils:barre_gestion_cr_changercassemajuscules'),
321 "className" => "outil_uppercase",
322 "replaceWith" => 'function(markitup) { return markitup.selection.toUpperCase() }',
324 "lang" => array('fr','en'),
326 // Transformation en minuscule
329 "name" => _T('barre_outils:barre_gestion_cr_changercasseminuscules'),
330 "className" => "outil_lowercase",
331 "replaceWith" => 'function(markitup) { return markitup.selection.toLowerCase() }',
333 "lang" => array('fr','en'),
338 /* inutile (origine de markitup et non de spip)
342 "id" => "sepPreview", // trouver un nom correct !
343 "separator" => "---------------",
349 "name" => _T('barre_outils:barre_clean'),
350 "className" => "outil_clean",
351 "replaceWith" => 'function(markitup) { return markitup.selection.replace(/<(.*?)>/g, "") }',
357 "name" => _T('barre_outils:barre_preview'),
358 "className" => "outil_preview",
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];
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);
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)=='-* ') {
399 } else if (s.substr(0,3)=='-##') {
400 s = '-#' + s.substr(3);
401 } else if (s.substr(0,3)=='-# ') {
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;
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 + ' ';
423 return openWith + s + closeWith;
439 * Definitions des liens entre css et icones
441 function barre_outils_edition_icones(){
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'
448 'outil_stroke_through' => array('spt-v1.png','-10px -946px'), //'text_strikethrough.png'
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'
455 //'outil_quote' => 'text_indent.png',
456 'outil_quote' => array('spt-v1.png','-10px -442px'), //'quote.png'
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'
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'
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'
481 'outil_clean' => array('spt-v1.png','-10px -982px'), //'clean.png'
482 'outil_preview' => array('spt-v1.png','-10px -1018px'), //'eye.png'