Yes I had an old post, nearly same question, yet when I took the time and wrote this myself instead of using @Tim Downs code I got closer than I even thought I would. Only problem now is that each time I click the button it adds another piece so best way to show you is by going to the bin yourself and trying it out
http://jsbin.com/ogiyed/1/edit
Code is here:
function getSelected() {
if(window.getSelection) { return window.getSelection(); }
else if(document.getSelection) { return document.getSelection(); }
else {
var selection = document.selection && document.selection.createRange();
if(selection.text) { return selection.text; }
return false;
}
return false;
}
$('.selections').not('.username').mouseup(function(e) {
var uid = $('.selections').find('.username').text();
var selection = getSelected();
if(selection) {
$('button').click(function() {
var text = $('#textarea_content');
text.val(text.val()+'[quote="'+ uid +'"]'+ selection +'[/quote]');
});
}
});
It nearly works like a charm ;)