Просмотр файла www/includes/bbcod.php

Размер файла: 7.75Kb
<script>
var textarea = document.getElementById("textarea");
var button = document.getElementById("button");

a.onclick = function() {
var len = textarea.value.length,
    start = textarea.selectionStart,
    end = textarea.selectionEnd,
    sel = textarea.value.substring(start, end),
    replace = '[url]http://адрес_cсылки' + sel + '[/url]';
textarea.value = textarea.value.substring(0,start) + replace + textarea.value.substring(end,len);
}
b.onclick = function() {
var len = textarea.value.length,
    start = textarea.selectionStart,
    end = textarea.selectionEnd,
    sel = textarea.value.substring(start, end),
    replace = '[b]' + sel + '[/b]';
textarea.value = textarea.value.substring(0,start) + replace + textarea.value.substring(end,len);
}
i.onclick = function() {
var len = textarea.value.length,
    start = textarea.selectionStart,
    end = textarea.selectionEnd,
    sel = textarea.value.substring(start, end),
    replace = '[i]' + sel + '[/i]';
textarea.value = textarea.value.substring(0,start) + replace + textarea.value.substring(end,len);
}
u.onclick = function() {
var len = textarea.value.length,
    start = textarea.selectionStart,
    end = textarea.selectionEnd,
    sel = textarea.value.substring(start, end),
    replace = '[u]' + sel + '[/u]';
textarea.value = textarea.value.substring(0,start) + replace + textarea.value.substring(end,len);
}
br.onclick = function() {
var len = textarea.value.length,
    start = textarea.selectionStart,
    end = textarea.selectionEnd,
    sel = textarea.value.substring(start, end),
    replace =' ' + sel + '[br]';
textarea.value = textarea.value.substring(0,start) + replace + textarea.value.substring(end,len);
}
small.onclick = function() {
var len = textarea.value.length,
    start = textarea.selectionStart,
    end = textarea.selectionEnd,
    sel = textarea.value.substring(start, end),
    replace ='[small]' + sel + '[/small]';
textarea.value = textarea.value.substring(0,start) + replace + textarea.value.substring(end,len);
}
red.onclick = function() {
var len = textarea.value.length,
    start = textarea.selectionStart,
    end = textarea.selectionEnd,
    sel = textarea.value.substring(start, end),
    replace ='[red]' + sel + '[/red]';
textarea.value = textarea.value.substring(0,start) + replace + textarea.value.substring(end,len);
}
green.onclick = function() {
var len = textarea.value.length,
    start = textarea.selectionStart,
    end = textarea.selectionEnd,
    sel = textarea.value.substring(start, end),
    replace ='[green]' + sel + '[/green]';
textarea.value = textarea.value.substring(0,start) + replace + textarea.value.substring(end,len);
}
blue.onclick = function() {
var len = textarea.value.length,
    start = textarea.selectionStart,
    end = textarea.selectionEnd,
    sel = textarea.value.substring(start, end),
    replace ='[blue]' + sel + '[/blue]';
textarea.value = textarea.value.substring(0,start) + replace + textarea.value.substring(end,len);
}
yellow.onclick = function() {
var len = textarea.value.length,
    start = textarea.selectionStart,
    end = textarea.selectionEnd,
    sel = textarea.value.substring(start, end),
    replace ='[yellow]' + sel + '[/yellow]';
textarea.value = textarea.value.substring(0,start) + replace + textarea.value.substring(end,len);
}
q.onclick = function() {
var len = textarea.value.length,
    start = textarea.selectionStart,
    end = textarea.selectionEnd,
    sel = textarea.value.substring(start, end),
    replace ='[q]' + sel + '[/q]';
textarea.value = textarea.value.substring(0,start) + replace + textarea.value.substring(end,len);
}
del.onclick = function() {
var len = textarea.value.length,
    start = textarea.selectionStart,
    end = textarea.selectionEnd,
    sel = textarea.value.substring(start, end),
    replace ='[del]' + sel + '[/del]';
textarea.value = textarea.value.substring(0,start) + replace + textarea.value.substring(end,len);
}
code.onclick = function() {
var len = textarea.value.length,
    start = textarea.selectionStart,
    end = textarea.selectionEnd,
    sel = textarea.value.substring(start, end),
    replace ='[code]' + sel + '[/code]';
textarea.value = textarea.value.substring(0,start) + replace + textarea.value.substring(end,len);
}
img.onclick = function() {
var len = textarea.value.length,
    start = textarea.selectionStart,
    end = textarea.selectionEnd,
    sel = textarea.value.substring(start, end),
    replace ='[img]http://адрес_картинки' + sel + '[/img]';
textarea.value = textarea.value.substring(0,start) + replace + textarea.value.substring(end,len);
}
gr.onclick = function() {
var len = textarea.value.length,
    start = textarea.selectionStart,
    end = textarea.selectionEnd,
    sel = textarea.value.substring(start, end),
    replace ='' + sel + ':(';
textarea.value = textarea.value.substring(0,start) + replace + textarea.value.substring(end,len);
}
ul.onclick = function() {
var len = textarea.value.length,
    start = textarea.selectionStart,
    end = textarea.selectionEnd,
    sel = textarea.value.substring(start, end),
    replace ='' + sel + ':)';
textarea.value = textarea.value.substring(0,start) + replace + textarea.value.substring(end,len);
}
moks.onclick = function() {
var len = textarea.value.length,
    start = textarea.selectionStart,
    end = textarea.selectionEnd,
    sel = textarea.value.substring(start, end),
    replace ='' + sel + ':4moks:';
textarea.value = textarea.value.substring(0,start) + replace + textarea.value.substring(end,len);
}
aaa.onclick = function() {
var len = textarea.value.length,
    start = textarea.selectionStart,
    end = textarea.selectionEnd,
    sel = textarea.value.substring(start, end),
    replace ='' + sel + ':aaa:';
textarea.value = textarea.value.substring(0,start) + replace + textarea.value.substring(end,len);
}
agree.onclick = function() {
var len = textarea.value.length,
    start = textarea.selectionStart,
    end = textarea.selectionEnd,
    sel = textarea.value.substring(start, end),
    replace ='' + sel + ':agree:';
textarea.value = textarea.value.substring(0,start) + replace + textarea.value.substring(end,len);
}
airkiss.onclick = function() {
var len = textarea.value.length,
    start = textarea.selectionStart,
    end = textarea.selectionEnd,
    sel = textarea.value.substring(start, end),
    replace ='' + sel + ':airkiss:';
textarea.value = textarea.value.substring(0,start) + replace + textarea.value.substring(end,len);
}
atlet.onclick = function() {
var len = textarea.value.length,
    start = textarea.selectionStart,
    end = textarea.selectionEnd,
    sel = textarea.value.substring(start, end),
    replace ='' + sel + ':atlet:';
textarea.value = textarea.value.substring(0,start) + replace + textarea.value.substring(end,len);
}
baby.onclick = function() {
var len = textarea.value.length,
    start = textarea.selectionStart,
    end = textarea.selectionEnd,
    sel = textarea.value.substring(start, end),
    replace ='' + sel + ':baby:';
textarea.value = textarea.value.substring(0,start) + replace + textarea.value.substring(end,len);
}
bant.onclick = function() {
var len = textarea.value.length,
    start = textarea.selectionStart,
    end = textarea.selectionEnd,
    sel = textarea.value.substring(start, end),
    replace ='' + sel + ':bant:';
textarea.value = textarea.value.substring(0,start) + replace + textarea.value.substring(end,len);
}
be.onclick = function() {
var len = textarea.value.length,
    start = textarea.selectionStart,
    end = textarea.selectionEnd,
    sel = textarea.value.substring(start, end),
    replace ='' + sel + ':be:';
textarea.value = textarea.value.substring(0,start) + replace + textarea.value.substring(end,len);
}
</script>