1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| function add(cod) {
var bal = document.getElementById(cod).value;
var v2 = '</'+cod+'>';
if (cod == "code") { var val = '<code language="'+bal+'" title="">'; }
else if (cod == "colo") { var val = '<color="'+bal+'">'; }
var text = document.getElementById("textarea");
if (text.curseur) {
text.curseur.text = val + text.curseur.text + v2;
}
else if (text.selectionStart >= 0 && text.selectionEnd >= 0) {
var debu = text.value.substring(0, text.selectionStart);
var enter = text.value.substring(text.selectionStart, text.selectionEnd);
var fin = text.value.substring(text.selectionEnd);
text.value = debu + val + enter + v2 + fin;
text.focus();
text.setSelectionRange(debu.length + val.length, text.value.length - fin.length - v2.length);
}
else {
text.value += val + v2;
text.focus();
}
document.getElementById(cod).options[0].selected = true;
} |