Je suis à la recherche d'un plugin ou d'une fonction jQuery pour insérer du code bb dans une zone de texte sélectionnée - rien de plus. J'ai trouvé des plugins comme http://markitup.jaysalvat.com/downloads/ mais ils ajoutent sont surdimensionnés pour mon projet.Recherche d'un simple plugin jQuery BB-code
Tout ce que je veux est la fonction suivante réalisée en jQuery:
document.getElementById("bold_button").onclick = function() {
format("[b]", "[/b]");
}
function format(aTag, eTag) {
var input = document.getElementById('t_antwort');
input.focus();
if(typeof document.selection != 'undefined') {
var range = document.selection.createRange();
var insText = range.text;
range.text = aTag + insText + eTag;
/* Anpassen der Cursorposition */
range = document.selection.createRange();
if (insText.length == 0) {
range.move('character', -eTag.length);
} else {
range.moveStart('character', aTag.length + insText.length + eTag.length);
}
range.select();
}
/* für neuere auf Gecko basierende Browser */
else if(typeof input.selectionStart != 'undefined')
{
/* Einfügen des Formatierungscodes */
var start = input.selectionStart;
var end = input.selectionEnd;
var insText = input.value.substring(start, end);
input.value = input.value.substr(0, start) + aTag + insText + eTag + input.value.substr(end);
/* Anpassen der Cursorposition */
var pos;
if (insText.length == 0) {
pos = start + aTag.length;
} else {
pos = start + aTag.length + insText.length + eTag.length;
}
input.selectionStart = pos;
input.selectionEnd = pos;
}
/* für die übrigen Browser */
else
{
input.innerHTML += aTag;
}
}
Connaissez-vous un plugin ou une fonction comme ça?