1 // ----------------------------------------------------------------------------
2 // markItUp! Universal MarkUp Engine, JQuery plugin
3 // v 1.1.15 ( e147ca3 - 16/08/2018 )
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.15
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 var 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(){
260 setTimeout(function(){
263 }).on('mouseup', function(e
) {
265 eval(button
.call
)(e
); // Pass the mouseup event to custom delegate
267 setTimeout(function() { markup(button
) },1);
269 }).on('mouseenter.markItUp', function() {
270 $('> ul', this).show();
271 $(document
).one('click', function() { // close dropmenu if click outside
272 $('ul ul', header
).hide();
275 }).on('mouseleave.markItUp', function() {
276 $('> ul', this).hide();
278 if (button
.dropMenu
) {
280 $(li
).addClass('markItUpDropMenu').append(dropMenus(button
.dropMenu
));
290 function magicMarkups(string
) {
292 string
= string
.toString();
293 string
= string
.replace(/\(\!\(([\s\S]*?)\)\!\)/g,
295 var b
= a
.split('|!|');
296 if (altKey
=== true) {
297 return (b
[1] !== undefined) ? b
[1] : b
[0];
299 return (b
[1] === undefined) ? "" : b
[0];
303 // [![prompt]!], [![prompt:!:value]!]
304 string
= string
.replace(/\[\!\[([\s\S]*?)\]\!\]/g,
306 var b
= a
.split(':!:');
307 if (abort
=== true) {
311 // On prévient qu'un prompt s'ouvre
312 markitup_prompt
= true;
314 value
= prompt(b
[0], (b
[1]) ? b
[1] : '');
315 if (value
=== null) {
319 // On attend un peu avant de dire que le prompt est fermé
320 // pour ne pas que ça soit pris en compte en même temps que la fermeture du prompt
321 setTimeout(function(){markitup_prompt
= false;}, 500);
332 function prepare(action
) {
333 if ($.isFunction(action
)) {
334 action
= action(hash
);
336 return magicMarkups(action
);
339 // build block to insert
340 function build(string
) {
341 var openWith
= prepare(clicked
.openWith
);
342 var placeHolder
= prepare(clicked
.placeHolder
);
343 var replaceWith
= prepare(clicked
.replaceWith
);
344 var closeWith
= prepare(clicked
.closeWith
);
345 var openBlockWith
= prepare(clicked
.openBlockWith
);
346 var closeBlockWith
= prepare(clicked
.closeBlockWith
);
347 var multiline
= clicked
.multiline
;
349 if (replaceWith
!== "") {
350 block
= openWith
+ replaceWith
+ closeWith
;
351 } else if (selection
=== '' && placeHolder
!== '') {
352 block
= openWith
+ placeHolder
+ closeWith
;
353 } else if (multiline
=== true) {
354 string
= string
|| selection
;
356 var lines
= [string
], blocks
= [];
358 if (multiline
=== true) {
359 lines
= string
.split(/\r?\n/);
362 for (var l
= 0; l
< lines
.length
; l
++) {
365 if (trailingSpaces
= line
.match(/ *$/)) {
366 blocks
.push(openWith
+ line
.replace(/ *$/g
, '') + closeWith
+ trailingSpaces
);
368 blocks
.push(openWith
+ line
+ closeWith
);
372 block
= blocks
.join("\n");
374 block
= openWith
+ (string
|| selection
) + closeWith
;
377 block
= openBlockWith
+ block
+ closeBlockWith
;
379 return { block
:block
,
380 openBlockWith
:openBlockWith
,
382 replaceWith
:replaceWith
,
383 placeHolder
:placeHolder
,
385 closeBlockWith
:closeBlockWith
390 function selectWord(){
391 selectionBeforeAfter(/\s|[.,;:!¡?¿()]/);
394 function selectLine(){
395 selectionBeforeAfter(/\r?\n/);
399 function selectionRemoveLast(pattern
){
400 // Remove space by default
401 if (!pattern
) pattern
= /\s/;
402 last
= selection
[selection
.length
-1];
403 if (last
&& last
.match(pattern
)) {
404 set(caretPosition
, selection
.length
-1);
406 $.extend(hash
, { caretPosition
:caretPosition
, scrollPosition
:scrollPosition
} );
410 function selectionBeforeAfter(pattern
) {
411 if (!pattern
) pattern
= /\s/;
413 sautAvantIE
= sautApresIE
= 0;
415 // calcul du nombre reel de caracteres pour le substr()
416 // IE ne compte pas les sauts de lignes pour definir les selections
417 // mais les compte dans la fonction length()
418 lenSelection
= selection
.length
- fixIeBug(selection
);
419 // si le caractere avant mon debut est un saut le ligne,
420 // ie ne le prendra pas en compte dans la selection.
421 // il faut pouvoir le connaitre.
423 set(caretPosition
- 1, 2);
424 sautAvantIE
= fixIeBug(document
.selection
.createRange().text
);
426 // idem pour le caractere apres la ligne !
427 set(caretPosition
, 2);
428 sautApresIE
= fixIeBug(document
.selection
.createRange().text
);
430 set(0,caretPosition
);
431 before
= document
.selection
.createRange().text
;
433 set(caretPosition
+ lenSelection
, textarea
.value
.length
);
434 after
= document
.selection
.createRange().text
;
435 // remettre la veritable selection
436 set(caretPosition
, lenSelection
);
437 selection
= document
.selection
.createRange().text
;
439 before
= textarea
.value
.substring(0, caretPosition
);
440 after
= textarea
.value
.substring(caretPosition
+ selection
.length
- fixIeBug(selection
));
443 before
= before
.split(pattern
);
444 after
= after
.split(pattern
);
445 // ajouter ce fichu saut de ligne pour IE
446 if (sautAvantIE
) before
.push("");
447 if (sautApresIE
) after
.unshift("");
451 function selectionSave(){
452 nb_before
= before
? before
[before
.length
-1].length
: 0;
453 nb_after
= after
? after
[0].length
: 0;
455 nb
= nb_before
+ selection
.length
+ nb_after
- fixIeBug(selection
);
456 caretPosition
= caretPosition
- nb_before
;
458 set(caretPosition
, nb
);
460 $.extend(hash
, { selection
:selection
, caretPosition
:caretPosition
, scrollPosition
:scrollPosition
} );
463 // define markup to insert
464 function markup(button
) {
466 hash
= clicked
= button
;
469 $.extend(hash
, { line
:"",
472 selection
:(selection
||''),
473 caretPosition
:caretPosition
,
480 // corrections des selections pour que
481 // - soit le curseur ne change pas
482 // - soit on prend le mot complet (si pas de selection)
483 // - soit on prend la ligne (avant, apres la selection)
484 if (button
.selectionType
) {
486 if (button
.selectionType
== "word") {
490 // win/ff add space on double click ? (hum, seems strange)
491 selectionRemoveLast(/\s/);
494 if (button
.selectionType
== "line") {
497 // horrible chose, mais tellement plus pratique
498 // car on ne peut pas de l'exerieur (json) utiliser
499 // les fonctions internes de markitup
500 if (button
.selectionType
== "return"){
501 // le calcul de before et after sous IE
502 // necessitant de creer des selections
503 // c'est extremement vilain a chaque saut de ligne
504 // des qu'il y a un texte volumineux.
505 // on dit tant pis pour lui.
507 selectionBeforeAfter(/\r?\n/);
508 before_last
= before
[before
.length
-1];
510 // gestion des listes -# et -*
511 if (r
= before_last
.match(/^-([*#]+) ?(.*)$/)) {
513 button
.replaceWith
= "\n-"+r
[1]+' ';
516 // supprime le -* present
518 button
.replaceWith
= "\n";
522 button
.replaceWith
= "\n";
524 before
[before
.length
-1] = before_last
;
531 // callbacks before insertion
532 prepare(options
.beforeInsert
);
533 prepare(clicked
.beforeInsert
);
534 if ((ctrlKey
=== true && shiftKey
=== true) || button
.multiline
=== true) {
535 prepare(clicked
.beforeMultiInsert
);
537 $.extend(hash
, { line
:1 });
539 if ((ctrlKey
=== true && shiftKey
=== true) || button
.forceMultiline
=== true) {
540 lines
= selection
.split(/\r?\n/);
541 for (j
= 0, n
= lines
.length
, i
= 0; i
< n
; i
++) {
542 // si une seule ligne, on se fiche de savoir qu'elle est vide,
543 // c'est volontaire si on clique le bouton
544 if (n
== 1 || $.trim(lines
[i
]) !== '') {
545 $.extend(hash
, { line
:++j
, selection
:lines
[i
] } );
546 lines
[i
] = build(lines
[i
]).block
;
552 string
= { block
:lines
.join('\n')};
553 start
= caretPosition
;
554 len
= string
.block
.length
+ ((browser
.opera
) ? n
-1 : 0);
555 } else if (ctrlKey
=== true) {
556 string
= build(selection
);
557 start
= caretPosition
+ string
.openWith
.length
;
558 len
= string
.block
.length
- string
.openWith
.length
- string
.closeWith
.length
;
559 len
= len
- (string
.block
.match(/ $/) ? 1 : 0);
560 len
-= fixIeBug(string
.block
);
561 } else if (shiftKey
=== true) {
562 string
= build(selection
);
563 start
= caretPosition
;
564 len
= string
.block
.length
;
565 len
-= fixIeBug(string
.block
);
567 string
= build(selection
);
568 start
= caretPosition
+ string
.block
.length
;
570 start
-= fixIeBug(string
.block
);
573 if ((selection
=== '' && string
.replaceWith
=== '')) {
574 caretOffset
+= fixOperaBug(string
.block
);
576 start
= caretPosition
+ string
.openBlockWith
.length
+ string
.openWith
.length
;
577 len
= string
.block
.length
- string
.openBlockWith
.length
- string
.openWith
.length
- string
.closeWith
.length
- string
.closeBlockWith
.length
;
579 caretOffset
= $$.val().substring(caretPosition
, $$.val().length
).length
;
580 caretOffset
-= fixOperaBug($$.val().substring(0, caretPosition
));
582 $.extend(hash
, { caretPosition
:caretPosition
, scrollPosition
:scrollPosition
} );
584 if (string
.block
!== selection
&& abort
=== false) {
585 insert(string
.block
);
592 $.extend(hash
, { line
:'', selection
:selection
});
594 // callbacks after insertion
595 if ((ctrlKey
=== true && shiftKey
=== true) || button
.multiline
=== true) {
596 prepare(clicked
.afterMultiInsert
);
599 prepare(clicked
.afterInsert
);
600 prepare(options
.afterInsert
);
602 // refresh preview if opened
603 if (previewWindow
&& options
.previewAutoRefresh
) {
608 shiftKey
= altKey
= ctrlKey
= abort
= false;
611 // Substract linefeed in Opera
612 function fixOperaBug(string
) {
614 return string
.length
- string
.replace(/\n*/g, '').length
;
618 // Substract linefeed in IE
619 function fixIeBug(string
) {
621 return string
.length
- string
.replace(/\r*/g, '').length
;
627 function insert(block
) {
628 if (document
.selection
) {
629 var newSelection
= document
.selection
.createRange();
630 newSelection
.text
= block
;
632 textarea
.value
= textarea
.value
.substring(0, caretPosition
) + block
+ textarea
.value
.substring(caretPosition
+ selection
.length
, textarea
.value
.length
);
637 function set(start
, len
) {
638 if (textarea
.createTextRange
){
639 // quick fix to make it work on Opera 9.5
640 if (browser
.opera
&& browser
.version
>= 9.5 && len
== 0) {
643 range
= textarea
.createTextRange();
644 range
.collapse(true);
645 range
.moveStart('character', start
);
646 range
.moveEnd('character', len
);
648 } else if (textarea
.setSelectionRange
){
649 textarea
.setSelectionRange(start
, start
+ len
);
651 textarea
.scrollTop
= scrollPosition
;
659 scrollPosition
= textarea
.scrollTop
;
660 if (document
.selection
) {
661 selection
= document
.selection
.createRange().text
;
662 if (browser
.msie
) { // ie
663 var range
= document
.selection
.createRange(), rangeCopy
= range
.duplicate();
664 rangeCopy
.moveToElementText(textarea
);
666 while(rangeCopy
.inRange(range
)) {
667 rangeCopy
.moveStart('character');
671 caretPosition
= textarea
.selectionStart
;
673 } else { // gecko & webkit
674 caretPosition
= textarea
.selectionStart
;
676 selection
= textarea
.value
.substring(caretPosition
, textarea
.selectionEnd
);
681 // open preview window
683 if (typeof options
.previewHandler
=== 'function') {
684 previewWindow
= true;
685 } else if (options
.previewInElement
) {
686 previewWindow
= $(options
.previewInElement
);
687 } else if (!previewWindow
|| previewWindow
.closed
) {
688 if (options
.previewInWindow
) {
689 previewWindow
= window
.open('', 'preview', options
.previewInWindow
);
690 $(window
).unload(function() {
691 previewWindow
.close();
694 iFrame
= $('<iframe class="markItUpPreviewFrame"></iframe>');
695 if (options
.previewPosition
== 'after') {
696 iFrame
.insertAfter(footer
);
698 iFrame
.insertBefore(header
);
700 previewWindow
= iFrame
[iFrame
.length
- 1].contentWindow
|| frame
[iFrame
.length
- 1];
702 } else if (altKey
=== true) {
706 previewWindow
.close();
708 previewWindow
= iFrame
= false;
710 if (!options
.previewAutoRefresh
) {
713 if (options
.previewInWindow
) {
714 previewWindow
.focus();
718 // refresh Preview window
719 function refreshPreview() {
723 function renderPreview() {
725 var parsedData
= $$.val();
726 if (options
.previewParser
&& typeof options
.previewParser
=== 'function') {
727 parsedData
= options
.previewParser(parsedData
);
729 if (options
.previewHandler
&& typeof options
.previewHandler
=== 'function') {
730 options
.previewHandler(parsedData
);
731 } else if (options
.previewParserPath
!== '') {
733 type
: options
.previewParserAjaxType
,
736 url
: options
.previewParserPath
,
737 data
: options
.previewParserVar
+'='+encodeURIComponent(parsedData
),
738 success: function(data
) {
739 writeInPreview( localize(data
, 1) );
745 url
: options
.previewTemplatePath
,
748 success: function(data
) {
749 writeInPreview( localize(data
, 1).replace(/<!-- content -->/g, $$.val()) );
757 function writeInPreview(data
) {
758 if (options
.previewInElement
) {
759 $(options
.previewInElement
).html(data
);
760 } else if (previewWindow
&& previewWindow
.document
) {
762 sp
= previewWindow
.document
.documentElement
.scrollTop
766 previewWindow
.document
.open();
767 previewWindow
.document
.write(data
);
768 previewWindow
.document
.close();
769 previewWindow
.document
.documentElement
.scrollTop
= sp
;
774 function keyPressed(e
) {
775 shiftKey
= e
.shiftKey
;
777 ctrlKey
= (!(e
.altKey
&& e
.ctrlKey
)) ? (e
.ctrlKey
|| e
.metaKey
) : false;
779 if (e
.type
=== 'keydown') {
780 if (ctrlKey
=== true) {
781 li
= $('a[accesskey="'+((e
.keyCode
== 13) ? '\\n' : String
.fromCharCode(e
.keyCode
))+'"]', header
).parent('li');
782 if (li
.length
!== 0) {
784 setTimeout(function() {
785 li
.triggerHandler('mouseup');
791 // si opera, on s'embete pas, il cree plus de problemes qu'autre chose
792 // car il ne prend pas en compte l'arret de ces evenements
793 if (!browser
.opera
) {
794 if (e
.keyCode
=== 13 || e
.keyCode
=== 10) { // Enter key
795 if (ctrlKey
=== true) { // Enter + Ctrl
797 markup(options
.onCtrlEnter
);
798 return options
.onCtrlEnter
.keepDefault
;
799 } else if (shiftKey
=== true) { // Enter + Shift
801 markup(options
.onShiftEnter
);
802 return options
.onShiftEnter
.keepDefault
;
803 } else { // only Enter
804 markup(options
.onEnter
);
805 return options
.onEnter
.keepDefault
;
809 if (e
.keyCode
=== 9) { // Tab key
810 if (shiftKey
== true || ctrlKey
== true || altKey
== true) {
811 // permettre un retour a l'action naturelle
812 // du navigateur via shift+tab
815 if (caretOffset
!== -1) {
817 caretOffset
= $$.val().length
- caretOffset
;
822 markup(options
.onTab
);
823 return options
.onTab
.keepDefault
;
831 $$.off(".markItUp").removeClass('markItUpEditor');
832 $$.parent('div').parent('div.markItUp').parent('div').replaceWith($$);
834 var relativeRef
= $$.parent('div').parent('div.markItUp').parent('div');
835 if (relativeRef
.length
) {
836 relativeRef
.replaceWith($$);
839 $$.data('markItUp', null);
846 $.fn
.markItUpRemove = function() {
847 return this.each(function() {
848 $(this).markItUp('remove');
853 $.markItUp = function(settings
) {
854 var options
= { target
:false };
855 $.extend(options
, settings
);
856 if (options
.target
) {
857 return $(options
.target
).each(function() {
859 $(this).trigger('insertion', [options
]);
862 $('textarea').trigger('insertion', [options
]);