0a4ab6332f6de1cbe709709bcd056df9c05652c7
1 // ----------------------------------------------------------------------------
2 // markItUp! Universal MarkUp Engine, JQuery plugin
3 // v 1.1.14 ( c014800b - 02/06/2014 )
4 // Dual licensed under the MIT and GPL licenses.
5 // ----------------------------------------------------------------------------
6 // Copyright (C) 2007-2012 Jay Salvat
7 // http://markitup.jaysalvat.com/
8 // ----------------------------------------------------------------------------
9 // Permission is hereby granted, free of charge, to any person obtaining a copy
10 // of this software and associated documentation files (the "Software"), to deal
11 // in the Software without restriction, including without limitation the rights
12 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 // copies of the Software, and to permit persons to whom the Software is
14 // furnished to do so, subject to the following conditions:
16 // The above copyright notice and this permission notice shall be included in
17 // all copies or substantial portions of the Software.
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 // ----------------------------------------------------------------------------
29 * Le code original de markitup 1.1.14
30 * a ete modifie pour prendre en compte
32 * 1) la langue utilisee dans les textarea :
33 * - si un textarea possede un attribut lang='xx' alors
34 * markitup n'affichera que les icones qui correspondent a cette langue
35 * - on peut passer une valeur de langue par defaut a markitup (le textarea peut ne pas en definir)
36 * .markitup(set_spip,{lang:'fr'});
37 * - une option supplementaire optionnelle 'lang' est introduite dans les parametres
38 * des boutons (markupset), par exemple : lang:['fr','es','en']
39 * - si un bouton n'a pas ce parametre, l'icone s'affiche
40 * quelque soit la langue designee dans le textarea ou les parametres de markitup ;
41 * sinon, il faut que la langue soit contenue dedans pour que l'icone s'affiche.
43 * 2) gerer des types de selections differentes :
44 * - normales comme dans markitup (rien a faire)
45 * - 'selectionType':'word' : aux mots le plus proche si pas de selection (sinon la selection)
46 * - 'selectionType':'line' : aux lignes les plus proches
47 * - and 'return' : ugly hack to generate list (and so on) on key 'return' press
49 * 3) eviter a Opera de gerer les evenements apres tabulation ou entree...
50 * il ne sait pas gerer (v11.51)
52 * 4) ajout d'un <em> supplémentaire sur le html des boutons de la barre d'outil, pour des histoires de sprites
55 $.fn
.markItUp = function(settings
, extraSettings
) {
56 var method
, params
, options
, ctrlKey
, shiftKey
, altKey
; ctrlKey
= shiftKey
= altKey
= false;
57 markitup_prompt
= false; // variable volontairement globale
59 if (typeof settings
== 'string') {
61 params
= extraSettings
;
68 previewHandler
: false,
69 previewInWindow
: '', // 'width=800, height=600, resizable=yes, scrollbars=yes'
71 previewAutoRefresh
: true,
72 previewPosition
: 'after',
73 previewTemplatePath
: '~/templates/preview.html',
75 previewParserPath
: '',
76 previewParserVar
: 'data',
77 previewParserAjaxType
: 'POST',
85 markupSet
: [ { /* set */ } ]
87 $.extend(options
, settings
, extraSettings
);
89 // compute markItUp! path
91 $('script').each(function(a
, tag
) {
92 miuScript
= $(tag
).get(0).src
.match(/(.*)jquery\.markitup(\.pack)?\.js$/);
93 if (miuScript
!== null) {
94 options
.root
= miuScript
[1];
99 // Quick patch to keep compatibility with jQuery 1.9
100 var uaMatch = function(ua
) {
101 ua
= ua
.toLowerCase();
103 var match
= /(chrome)[ \/]([\w.]+)/.exec(ua
) ||
104 /(webkit)[ \/]([\w.]+)/.exec(ua
) ||
105 /(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua
) ||
106 /(msie) ([\w.]+)/.exec(ua
) ||
107 ua
.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua
) ||
111 browser
: match
[ 1 ] || "",
112 version
: match
[ 2 ] || "0"
115 var matched
= uaMatch( navigator
.userAgent
);
118 if (matched
.browser
) {
119 browser
[matched
.browser
] = true;
120 browser
.version
= matched
.version
;
122 if (browser
.chrome
) {
123 browser
.webkit
= true;
124 } else if (browser
.webkit
) {
125 browser
.safari
= true;
128 return this.each(function() {
129 var $$, textarea
, levels
, scrollPosition
, caretPosition
,
130 clicked
, hash
, header
, footer
, previewWindow
, template
, iFrame
, abort
,
136 scrollPosition
= caretPosition
= 0;
139 options
.previewParserPath
= localize(options
.previewParserPath
);
140 options
.previewTemplatePath
= localize(options
.previewTemplatePath
);
151 $.error('Method ' + method
+ ' does not exist on jQuery.markItUp');
156 // apply the computed path to ~/
157 function localize(data
, inText
) {
159 return data
.replace(/("|')~\//g, "$1"+options
.root
);
161 return data
.replace(/^~\//, options
.root
);
164 // init and build editor
166 id
= ''; nameSpace
= '';
168 id
= 'id="'+options
.id
+'"';
169 } else if ($$.attr("id")) {
170 id
= 'id="markItUp'+($$.attr("id").substr(0, 1).toUpperCase())+($$.attr("id").substr(1))+'"';
173 if (options
.nameSpace
) {
174 nameSpace
= 'class="'+options
.nameSpace
+'"';
176 currentScrollPosition
= $$.scrollTop();
177 $$.wrap('<div '+nameSpace
+'></div>');
178 $$.wrap('<div '+id
+' class="markItUp"></div>');
179 $$.wrap('<div class="markItUpContainer"></div>');
180 $$.addClass("markItUpEditor");
181 $$.scrollTop(currentScrollPosition
);
183 // add the header before the textarea
184 header
= $('<div class="markItUpHeader"></div>').insertBefore($$);
185 $(dropMenus(options
.markupSet
)).appendTo(header
);
186 // remove empty dropMenu
187 $(header
).find("li.markItUpDropMenu ul:empty").parent().remove();
189 // add the footer after the textarea
190 footer
= $('<div class="markItUpFooter"></div>').insertAfter($$);
192 // add the resize handle after textarea
193 if (options
.resizeHandle
=== true && browser
.safari
!== true) {
194 resizeHandle
= $('<div class="markItUpResizeHandle"></div>')
196 .on("mousedown.markItUp", function(e
) {
197 var h
= $$.height(), y
= e
.clientY
, mouseMove
, mouseUp
;
198 mouseMove = function(e
) {
199 $$.css("height", Math
.max(20, e
.clientY
+h
-y
)+"px");
202 mouseUp = function(e
) {
203 $("html").off("mousemove.markItUp", mouseMove
).off("mouseup.markItUp", mouseUp
);
206 $("html").on("mousemove.markItUp", mouseMove
).on("mouseup.markItUp", mouseUp
);
208 footer
.append(resizeHandle
);
212 $$.on('keydown.markItUp', keyPressed
).on('keyup', keyPressed
);
214 // bind an event to catch external calls
215 $$.on("insertion.markItUp", function(e
, settings
) {
216 if (settings
.target
!== false) {
219 if (textarea
=== $.markItUp
.focused
) {
224 // remember the last focus
225 $$.on('focus.markItUp', function() {
226 $.markItUp
.focused
= this;
229 if (options
.previewInElement
) {
234 // recursively build header with dropMenus from markupset
235 function dropMenus(markupSet
) {
236 var ul
= $('<ul></ul>'), i
= 0;
237 var lang
= ($$.attr('lang')||options
.lang
);
239 $('li:hover > ul', ul
).css('display', 'block');
240 $.each(markupSet
, function() {
241 var button
= this, t
= '', title
, li
, j
;
242 // pas de langue ou dans la langue ; et uniquement si langue autorisee
243 if ((!lang
|| !button
.lang
|| ($.inArray(lang
, button
.lang
) != -1))
244 && (!button
.lang_not
|| ($.inArray(lang
, button
.lang_not
) == -1))) {
245 button
.title
? title
= (button
.key
) ? (button
.title
||'')+' [Ctrl+'+button
.key
+']' : (button
.title
||'') : title
= (button
.key
) ? (button
.name
||'')+' [Ctrl+'+button
.key
+']' : (button
.name
||'');
246 key
= (button
.key
) ? 'accesskey="'+button
.key
+'"' : '';
247 if (button
.separator
) {
248 li
= $('<li class="markItUpSeparator">'+(button
.separator
||'')+'</li>').appendTo(ul
);
251 for (j
= levels
.length
-1; j
>= 0; j
--) {
254 li
= $('<li class="markItUpButton markItUpButton'+t
+(i
)+' '+(button
.className
||'')+'"><a href="#" '+key
+' title="'+title
+'"><em>'+(button
.name
||'')+'</em></a></li>')
255 .on("contextmenu.markItUp", function() { // prevent contextmenu on mac and allow ctrl+click
257 }).on('click.markItUp', function(e
) {
259 }).on("focusin.markItUp", function(){
261 }).on('mouseup', function(e
) {
263 eval(button
.call
)(e
); // Pass the mouseup event to custom delegate
265 setTimeout(function() { markup(button
) },1);
267 }).on('mouseenter.markItUp', function() {
268 $('> ul', this).show();
269 $(document
).one('click', function() { // close dropmenu if click outside
270 $('ul ul', header
).hide();
273 }).on('mouseleave.markItUp', function() {
274 $('> ul', this).hide();
276 if (button
.dropMenu
) {
278 $(li
).addClass('markItUpDropMenu').append(dropMenus(button
.dropMenu
));
288 function magicMarkups(string
) {
290 string
= string
.toString();
291 string
= string
.replace(/\(\!\(([\s\S]*?)\)\!\)/g,
293 var b
= a
.split('|!|');
294 if (altKey
=== true) {
295 return (b
[1] !== undefined) ? b
[1] : b
[0];
297 return (b
[1] === undefined) ? "" : b
[0];
301 // [![prompt]!], [![prompt:!:value]!]
302 string
= string
.replace(/\[\!\[([\s\S]*?)\]\!\]/g,
304 var b
= a
.split(':!:');
305 if (abort
=== true) {
309 // On prévient qu'un prompt s'ouvre
310 markitup_prompt
= true;
312 value
= prompt(b
[0], (b
[1]) ? b
[1] : '');
313 if (value
=== null) {
317 // On attend un peu avant de dire que le prompt est fermé
318 // pour ne pas que ça soit pris en compte en même temps que la fermeture du prompt
319 setTimeout(function(){markitup_prompt
= false;}, 500);
330 function prepare(action
) {
331 if ($.isFunction(action
)) {
332 action
= action(hash
);
334 return magicMarkups(action
);
337 // build block to insert
338 function build(string
) {
339 var openWith
= prepare(clicked
.openWith
);
340 var placeHolder
= prepare(clicked
.placeHolder
);
341 var replaceWith
= prepare(clicked
.replaceWith
);
342 var closeWith
= prepare(clicked
.closeWith
);
343 var openBlockWith
= prepare(clicked
.openBlockWith
);
344 var closeBlockWith
= prepare(clicked
.closeBlockWith
);
345 var multiline
= clicked
.multiline
;
347 if (replaceWith
!== "") {
348 block
= openWith
+ replaceWith
+ closeWith
;
349 } else if (selection
=== '' && placeHolder
!== '') {
350 block
= openWith
+ placeHolder
+ closeWith
;
351 } else if (multiline
=== true) {
352 string
= string
|| selection
;
354 var lines
= [string
], blocks
= [];
356 if (multiline
=== true) {
357 lines
= string
.split(/\r?\n/);
360 for (var l
= 0; l
< lines
.length
; l
++) {
363 if (trailingSpaces
= line
.match(/ *$/)) {
364 blocks
.push(openWith
+ line
.replace(/ *$/g
, '') + closeWith
+ trailingSpaces
);
366 blocks
.push(openWith
+ line
+ closeWith
);
370 block
= blocks
.join("\n");
372 block
= openWith
+ (string
|| selection
) + closeWith
;
375 block
= openBlockWith
+ block
+ closeBlockWith
;
377 return { block
:block
,
378 openBlockWith
:openBlockWith
,
380 replaceWith
:replaceWith
,
381 placeHolder
:placeHolder
,
383 closeBlockWith
:closeBlockWith
388 function selectWord(){
389 selectionBeforeAfter(/\s|[.,;:!¡?¿()]/);
392 function selectLine(){
393 selectionBeforeAfter(/\r?\n/);
397 function selectionRemoveLast(pattern
){
398 // Remove space by default
399 if (!pattern
) pattern
= /\s/;
400 last
= selection
[selection
.length
-1];
401 if (last
&& last
.match(pattern
)) {
402 set(caretPosition
, selection
.length
-1);
404 $.extend(hash
, { caretPosition
:caretPosition
, scrollPosition
:scrollPosition
} );
408 function selectionBeforeAfter(pattern
) {
409 if (!pattern
) pattern
= /\s/;
411 sautAvantIE
= sautApresIE
= 0;
413 // calcul du nombre reel de caracteres pour le substr()
414 // IE ne compte pas les sauts de lignes pour definir les selections
415 // mais les compte dans la fonction length()
416 lenSelection
= selection
.length
- fixIeBug(selection
);
417 // si le caractere avant mon debut est un saut le ligne,
418 // ie ne le prendra pas en compte dans la selection.
419 // il faut pouvoir le connaitre.
421 set(caretPosition
- 1, 2);
422 sautAvantIE
= fixIeBug(document
.selection
.createRange().text
);
424 // idem pour le caractere apres la ligne !
425 set(caretPosition
, 2);
426 sautApresIE
= fixIeBug(document
.selection
.createRange().text
);
428 set(0,caretPosition
);
429 before
= document
.selection
.createRange().text
;
431 set(caretPosition
+ lenSelection
, textarea
.value
.length
);
432 after
= document
.selection
.createRange().text
;
433 // remettre la veritable selection
434 set(caretPosition
, lenSelection
);
435 selection
= document
.selection
.createRange().text
;
437 before
= textarea
.value
.substring(0, caretPosition
);
438 after
= textarea
.value
.substring(caretPosition
+ selection
.length
- fixIeBug(selection
));
441 before
= before
.split(pattern
);
442 after
= after
.split(pattern
);
443 // ajouter ce fichu saut de ligne pour IE
444 if (sautAvantIE
) before
.push("");
445 if (sautApresIE
) after
.unshift("");
449 function selectionSave(){
450 nb_before
= before
? before
[before
.length
-1].length
: 0;
451 nb_after
= after
? after
[0].length
: 0;
453 nb
= nb_before
+ selection
.length
+ nb_after
- fixIeBug(selection
);
454 caretPosition
= caretPosition
- nb_before
;
456 set(caretPosition
, nb
);
458 $.extend(hash
, { selection
:selection
, caretPosition
:caretPosition
, scrollPosition
:scrollPosition
} );
461 // define markup to insert
462 function markup(button
) {
464 hash
= clicked
= button
;
467 $.extend(hash
, { line
:"",
470 selection
:(selection
||''),
471 caretPosition
:caretPosition
,
478 // corrections des selections pour que
479 // - soit le curseur ne change pas
480 // - soit on prend le mot complet (si pas de selection)
481 // - soit on prend la ligne (avant, apres la selection)
482 if (button
.selectionType
) {
484 if (button
.selectionType
== "word") {
488 // win/ff add space on double click ? (hum, seems strange)
489 selectionRemoveLast(/\s/);
492 if (button
.selectionType
== "line") {
495 // horrible chose, mais tellement plus pratique
496 // car on ne peut pas de l'exerieur (json) utiliser
497 // les fonctions internes de markitup
498 if (button
.selectionType
== "return"){
499 // le calcul de before et after sous IE
500 // necessitant de creer des selections
501 // c'est extremement vilain a chaque saut de ligne
502 // des qu'il y a un texte volumineux.
503 // on dit tant pis pour lui.
505 selectionBeforeAfter(/\r?\n/);
506 before_last
= before
[before
.length
-1];
508 // gestion des listes -# et -*
509 if (r
= before_last
.match(/^-([*#]+) ?(.*)$/)) {
511 button
.replaceWith
= "\n-"+r
[1]+' ';
514 // supprime le -* present
516 button
.replaceWith
= "\n";
520 button
.replaceWith
= "\n";
522 before
[before
.length
-1] = before_last
;
529 // callbacks before insertion
530 prepare(options
.beforeInsert
);
531 prepare(clicked
.beforeInsert
);
532 if ((ctrlKey
=== true && shiftKey
=== true) || button
.multiline
=== true) {
533 prepare(clicked
.beforeMultiInsert
);
535 $.extend(hash
, { line
:1 });
537 if ((ctrlKey
=== true && shiftKey
=== true) || button
.forceMultiline
=== true) {
538 lines
= selection
.split(/\r?\n/);
539 for (j
= 0, n
= lines
.length
, i
= 0; i
< n
; i
++) {
540 // si une seule ligne, on se fiche de savoir qu'elle est vide,
541 // c'est volontaire si on clique le bouton
542 if (n
== 1 || $.trim(lines
[i
]) !== '') {
543 $.extend(hash
, { line
:++j
, selection
:lines
[i
] } );
544 lines
[i
] = build(lines
[i
]).block
;
550 string
= { block
:lines
.join('\n')};
551 start
= caretPosition
;
552 len
= string
.block
.length
+ ((browser
.opera
) ? n
-1 : 0);
553 } else if (ctrlKey
=== true) {
554 string
= build(selection
);
555 start
= caretPosition
+ string
.openWith
.length
;
556 len
= string
.block
.length
- string
.openWith
.length
- string
.closeWith
.length
;
557 len
= len
- (string
.block
.match(/ $/) ? 1 : 0);
558 len
-= fixIeBug(string
.block
);
559 } else if (shiftKey
=== true) {
560 string
= build(selection
);
561 start
= caretPosition
;
562 len
= string
.block
.length
;
563 len
-= fixIeBug(string
.block
);
565 string
= build(selection
);
566 start
= caretPosition
+ string
.block
.length
;
568 start
-= fixIeBug(string
.block
);
571 if ((selection
=== '' && string
.replaceWith
=== '')) {
572 caretOffset
+= fixOperaBug(string
.block
);
574 start
= caretPosition
+ string
.openBlockWith
.length
+ string
.openWith
.length
;
575 len
= string
.block
.length
- string
.openBlockWith
.length
- string
.openWith
.length
- string
.closeWith
.length
- string
.closeBlockWith
.length
;
577 caretOffset
= $$.val().substring(caretPosition
, $$.val().length
).length
;
578 caretOffset
-= fixOperaBug($$.val().substring(0, caretPosition
));
580 $.extend(hash
, { caretPosition
:caretPosition
, scrollPosition
:scrollPosition
} );
582 if (string
.block
!== selection
&& abort
=== false) {
583 insert(string
.block
);
590 $.extend(hash
, { line
:'', selection
:selection
});
592 // callbacks after insertion
593 if ((ctrlKey
=== true && shiftKey
=== true) || button
.multiline
=== true) {
594 prepare(clicked
.afterMultiInsert
);
597 prepare(clicked
.afterInsert
);
598 prepare(options
.afterInsert
);
600 // refresh preview if opened
601 if (previewWindow
&& options
.previewAutoRefresh
) {
606 shiftKey
= altKey
= ctrlKey
= abort
= false;
609 // Substract linefeed in Opera
610 function fixOperaBug(string
) {
612 return string
.length
- string
.replace(/\n*/g, '').length
;
616 // Substract linefeed in IE
617 function fixIeBug(string
) {
619 return string
.length
- string
.replace(/\r*/g, '').length
;
625 function insert(block
) {
626 if (document
.selection
) {
627 var newSelection
= document
.selection
.createRange();
628 newSelection
.text
= block
;
630 textarea
.value
= textarea
.value
.substring(0, caretPosition
) + block
+ textarea
.value
.substring(caretPosition
+ selection
.length
, textarea
.value
.length
);
635 function set(start
, len
) {
636 if (textarea
.createTextRange
){
637 // quick fix to make it work on Opera 9.5
638 if (browser
.opera
&& browser
.version
>= 9.5 && len
== 0) {
641 range
= textarea
.createTextRange();
642 range
.collapse(true);
643 range
.moveStart('character', start
);
644 range
.moveEnd('character', len
);
646 } else if (textarea
.setSelectionRange
){
647 textarea
.setSelectionRange(start
, start
+ len
);
649 textarea
.scrollTop
= scrollPosition
;
657 scrollPosition
= textarea
.scrollTop
;
658 if (document
.selection
) {
659 selection
= document
.selection
.createRange().text
;
660 if (browser
.msie
) { // ie
661 var range
= document
.selection
.createRange(), rangeCopy
= range
.duplicate();
662 rangeCopy
.moveToElementText(textarea
);
664 while(rangeCopy
.inRange(range
)) {
665 rangeCopy
.moveStart('character');
669 caretPosition
= textarea
.selectionStart
;
671 } else { // gecko & webkit
672 caretPosition
= textarea
.selectionStart
;
674 selection
= textarea
.value
.substring(caretPosition
, textarea
.selectionEnd
);
679 // open preview window
681 if (typeof options
.previewHandler
=== 'function') {
682 previewWindow
= true;
683 } else if (options
.previewInElement
) {
684 previewWindow
= $(options
.previewInElement
);
685 } else if (!previewWindow
|| previewWindow
.closed
) {
686 if (options
.previewInWindow
) {
687 previewWindow
= window
.open('', 'preview', options
.previewInWindow
);
688 $(window
).unload(function() {
689 previewWindow
.close();
692 iFrame
= $('<iframe class="markItUpPreviewFrame"></iframe>');
693 if (options
.previewPosition
== 'after') {
694 iFrame
.insertAfter(footer
);
696 iFrame
.insertBefore(header
);
698 previewWindow
= iFrame
[iFrame
.length
- 1].contentWindow
|| frame
[iFrame
.length
- 1];
700 } else if (altKey
=== true) {
704 previewWindow
.close();
706 previewWindow
= iFrame
= false;
708 if (!options
.previewAutoRefresh
) {
711 if (options
.previewInWindow
) {
712 previewWindow
.focus();
716 // refresh Preview window
717 function refreshPreview() {
721 function renderPreview() {
723 if (options
.previewHandler
&& typeof options
.previewHandler
=== 'function') {
724 options
.previewHandler( $$.val() );
725 } else if (options
.previewParser
&& typeof options
.previewParser
=== 'function') {
726 var data
= options
.previewParser( $$.val() );
727 writeInPreview(localize(data
, 1) );
728 } else if (options
.previewParserPath
!== '') {
730 type
: options
.previewParserAjaxType
,
733 url
: options
.previewParserPath
,
734 data
: options
.previewParserVar
+'='+encodeURIComponent($$.val()),
735 success: function(data
) {
736 writeInPreview( localize(data
, 1) );
742 url
: options
.previewTemplatePath
,
745 success: function(data
) {
746 writeInPreview( localize(data
, 1).replace(/<!-- content -->/g, $$.val()) );
754 function writeInPreview(data
) {
755 if (options
.previewInElement
) {
756 $(options
.previewInElement
).html(data
);
757 } else if (previewWindow
&& previewWindow
.document
) {
759 sp
= previewWindow
.document
.documentElement
.scrollTop
763 previewWindow
.document
.open();
764 previewWindow
.document
.write(data
);
765 previewWindow
.document
.close();
766 previewWindow
.document
.documentElement
.scrollTop
= sp
;
771 function keyPressed(e
) {
772 shiftKey
= e
.shiftKey
;
774 ctrlKey
= (!(e
.altKey
&& e
.ctrlKey
)) ? (e
.ctrlKey
|| e
.metaKey
) : false;
776 if (e
.type
=== 'keydown') {
777 if (ctrlKey
=== true) {
778 li
= $('a[accesskey="'+((e
.keyCode
== 13) ? '\\n' : String
.fromCharCode(e
.keyCode
))+'"]', header
).parent('li');
779 if (li
.length
!== 0) {
781 setTimeout(function() {
782 li
.triggerHandler('mouseup');
788 // si opera, on s'embete pas, il cree plus de problemes qu'autre chose
789 // car il ne prend pas en compte l'arret de ces evenements
790 if (!browser
.opera
) {
791 if (e
.keyCode
=== 13 || e
.keyCode
=== 10) { // Enter key
792 if (ctrlKey
=== true) { // Enter + Ctrl
794 markup(options
.onCtrlEnter
);
795 return options
.onCtrlEnter
.keepDefault
;
796 } else if (shiftKey
=== true) { // Enter + Shift
798 markup(options
.onShiftEnter
);
799 return options
.onShiftEnter
.keepDefault
;
800 } else { // only Enter
801 markup(options
.onEnter
);
802 return options
.onEnter
.keepDefault
;
806 if (e
.keyCode
=== 9) { // Tab key
807 if (shiftKey
== true || ctrlKey
== true || altKey
== true) {
808 // permettre un retour a l'action naturelle
809 // du navigateur via shift+tab
812 if (caretOffset
!== -1) {
814 caretOffset
= $$.val().length
- caretOffset
;
819 markup(options
.onTab
);
820 return options
.onTab
.keepDefault
;
828 $$.off(".markItUp").removeClass('markItUpEditor');
829 $$.parent('div').parent('div.markItUp').parent('div').replaceWith($$);
831 var relativeRef
= $$.parent('div').parent('div.markItUp').parent('div');
832 if (relativeRef
.length
) {
833 relativeRef
.replaceWith($$);
836 $$.data('markItUp', null);
843 $.fn
.markItUpRemove = function() {
844 return this.each(function() {
845 $(this).markItUp('remove');
850 $.markItUp = function(settings
) {
851 var options
= { target
:false };
852 $.extend(options
, settings
);
853 if (options
.target
) {
854 return $(options
.target
).each(function() {
856 $(this).trigger('insertion', [options
]);
859 $('textarea').trigger('insertion', [options
]);