Please login or register. Welcome to the Studio, guest!


Quick Links:


newBookmarkLockedFalling

peter
Guest
This code might look familiar to some coders, that's because it is the ProBoards UBBC wrapper, which I wrote for ProBoards.

What it does is wraps tags around the selected text in the textarea, and can also be used for smileys. Could be useful for comment systems, forums (like ProBoards) for example.

function ubbc(open, end){
    var tArea = document.THE_FORM.TEXTAREA;
    var isIE = (document.all)? true : false;
    var open = (open)? open : "";
    var end = (end)? end : "";

    if(isIE){
        tArea.focus();
        var curSelect = document.selection.createRange();
        if(arguments[2]){
            curSelect.text = open + arguments[2] + "]" + curSelect.text + end;
        } else {
            curSelect.text = open + curSelect.text + end;
        }
    } else if(!isIE && typeof tArea.selectionStart != "undefined"){
        var selStart = tArea.value.substr(0, tArea.selectionStart);
        var selEnd = tArea.value.substr(tArea.selectionEnd, tArea.value.length);
        var curSelection = tArea.value.replace(selStart, '').replace(selEnd, '');
        if(arguments[2]){
            tArea.value = selStart + open + arguments[2] + "]" + curSelection + end + selEnd;
        } else {
            tArea.value = selStart + open + curSelection + end + selEnd;
        }
    } else {
        tArea.value += (arguments[2])? open + arguments[2] + "]" + end : open + end;
    }
}


Only line you need to change is this...

var tArea = document.THE_FORM.TEXTAREA;

...that needs to point to your form textarea.

Example: if I wanted to have bold tags, I would do this....

<a href="#" onclick="ubbc('[b]', '[/b]')">Bold</a>

You can also add tags that don't have a closing tag. Like so...

<a href="#" onclick="ubbc('[hr]')">HR Line</a>


Last Edit: Nov 7, 2005 9:26:05 GMT by peter

newBookmarkLockedFalling