var bbcode = ['[b]', '[/b]', '[i]', '[/i]', '[u]', '[/u]', '[s]', '[/s]', '[url]', '[/url]', '[center]', '[/center]', '[quote]', '[/quote]', '[code]', '[/code]'];
|
|
|
|
function insertTag(first, second)
|
|
{
|
|
postArea = document.getElementById('post');
|
|
if (document.selection) // IE
|
|
{
|
|
postArea.focus();
|
|
sel = document.selection.createRange();
|
|
sel.text = first + sel.text + second;
|
|
}
|
|
else if (postArea.selectionStart || postArea.selectionStart == '0')
|
|
{
|
|
var startPos = postArea.selectionStart;
|
|
var endPos = postArea.selectionEnd;
|
|
if (startPos == endPos)
|
|
{
|
|
if (first == bbcode[8])
|
|
{
|
|
var link = prompt('Type hyperlink address', 'http://');
|
|
if (startPos != 0)
|
|
{
|
|
postArea.value = postArea.value.substring(0, startPos) + '[url=' + link + '] ' + postArea.value.substring(startPos, endPos) + second + postArea.value.substring(endPos, postArea.value.length);
|
|
}
|
|
else
|
|
{
|
|
postArea.value += '[url=' + link + '][/url]';
|
|
}
|
|
}
|
|
else
|
|
{
|
|
postArea.value += ' ' + first + second;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
postArea.value = postArea.value.substring(0, startPos) + first + postArea.value.substring(startPos, endPos) + second + postArea.value.substring(endPos, postArea.value.length);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
postArea.value += ' ' + first + second;
|
|
}
|
|
}
|
|
|
|
function bbTag(item)
|
|
{
|
|
if(item < bbcode.length -1)
|
|
{
|
|
insertTag(bbcode[item], bbcode[item+1]);
|
|
}
|
|
else
|
|
{
|
|
switch(item)
|
|
{
|
|
case 16:
|
|
var firstItem = prompt('Type first item list');
|
|
document.getElementById('post').value += "[list]\n[*]"+firstItem+"\n[/list]";
|
|
break;
|
|
case 18:
|
|
var color = document.getElementById('text_color').value;//prompt('Type font color', 'black');
|
|
insertTag('[color='+color+']', '[/color]');
|
|
}
|
|
}
|
|
}
|
|
|
|
function insertSmile(smile)
|
|
{
|
|
document.getElementById('post').value += ' ' + smile;
|
|
}
|