Login:    

useradd
more /root/Forums and Website/BBCode Buttons?.thread
2008-10-01 16:53:03cheeseboy
Can you add buttons to wrap text in bbcode?
2008-11-16 07:26:22IsmAvatar
Code
<script>
 function tag(t1,t2) {
  var o = document.getElementById('ted');
  if (o.setSelectionRange) {
   o.value = o.value.substring(0,o.selectionStart)
    + t1 + o.value.substring(o.selectionStart,o.selectionEnd)
    + t2 + o.value.substring(o.selectionEnd,o.value.length);
  } else {
   var range = document.selection.createRange();
   range.text = t1 + range.text + t2;
  }
  o.focus();
 }
</script>

<input type="button" value="B" onclick="tag('[b]','[/b]');" />
<input type="button" value="I" onclick="tag('[i]','[/i]');" />
<input type="button" value="U" onclick="tag('[u]','[/u]');" />
<br /><textarea id="ted" cols="30" rows="5"></textarea>
2008-11-16 07:29:32IsmAvatar
Notice, the above code doesn't work the best in IE. Actually, it does work in IE, but it doesn't restrict itself to the textarea. That is, if you were to select some text outside of the textarea, such as someone's post, and then click the button, it would actually put [b] and [/b] tags around the selected text... Which is a really neat effect, but not desirable...
2008-12-17 04:56:05Authentic GameWarez
Code
<script>
 function tag(t1,t2) {
  var o = document.getElementById('ted');
  if (o.setSelectionRange) {
   o.value = o.value.substring(0,o.selectionStart)
    + t1 + o.value.substring(o.selectionStart,o.selectionEnd)
    + t2 + o.value.substring(o.selectionEnd,o.value.length);
  } else {
   var range = document.selection.createRange();
   range.text = t1 + range.text + t2;
  }
  o.focus();
 }
</script>

<input type="button" value="B" onclick="tag('[b]','[/b]');" />
<input type="button" value="I" onclick="tag('[i]','[/i]');" />
<input type="button" value="U" onclick="tag('[u]','[/u]');" />
<br /><textarea id="ted" cols="30" rows="5">


Eeer.... What was that supposed to do?
2008-12-17 06:04:03IsmAvatar
He asked if I can. I showed him that I partially can. Nobody asked to implement it :-p
besides, as mentioned above, that code is buggy, so anybody with workarounds is encouraged to post their revision or suggested revision to it.
2009-03-25 17:43:44lieuwe
please implement that, that would be really usefull, you could also add smilies(you can host them at flickr, direct linking is posible)
2009-03-27 01:59:01IsmAvatar
I don't think it's a good idea to implement it because it does funky things in IE. If someone can make a revised version that doesn't have the problems, then I'll implement it.