A new, object-oriented, better vesion of μForum
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.8 KiB

  1. var bbcode = ['[b]', '[/b]', '[i]', '[/i]', '[u]', '[/u]', '[s]', '[/s]', '[url]', '[/url]', '[center]', '[/center]', '[quote]', '[/quote]', '[code]', '[/code]'];
  2. function insertTag(first, second)
  3. {
  4. postArea = document.getElementById('post');
  5. if (document.selection) // IE
  6. {
  7. postArea.focus();
  8. sel = document.selection.createRange();
  9. sel.text = first + sel.text + second;
  10. }
  11. else if (postArea.selectionStart || postArea.selectionStart == '0')
  12. {
  13. var startPos = postArea.selectionStart;
  14. var endPos = postArea.selectionEnd;
  15. if (startPos == endPos)
  16. {
  17. if (first == bbcode[8])
  18. {
  19. var link = prompt('Type hyperlink address', 'http://');
  20. if (startPos != 0)
  21. {
  22. postArea.value = postArea.value.substring(0, startPos) + '[url=' + link + '] ' + postArea.value.substring(startPos, endPos) + second + postArea.value.substring(endPos, postArea.value.length);
  23. }
  24. else
  25. {
  26. postArea.value += '[url=' + link + '][/url]';
  27. }
  28. }
  29. else
  30. {
  31. postArea.value += ' ' + first + second;
  32. }
  33. }
  34. else
  35. {
  36. postArea.value = postArea.value.substring(0, startPos) + first + postArea.value.substring(startPos, endPos) + second + postArea.value.substring(endPos, postArea.value.length);
  37. }
  38. }
  39. else
  40. {
  41. postArea.value += ' ' + first + second;
  42. }
  43. }
  44. function bbTag(item)
  45. {
  46. if(item < bbcode.length -1)
  47. {
  48. insertTag(bbcode[item], bbcode[item+1]);
  49. }
  50. else
  51. {
  52. switch(item)
  53. {
  54. case 16:
  55. var firstItem = prompt('Type first item list');
  56. document.getElementById('post').value += "[list]\n[*]"+firstItem+"\n[/list]";
  57. break;
  58. case 18:
  59. var color = document.getElementById('text_color').value;//prompt('Type font color', 'black');
  60. insertTag('[color='+color+']', '[/color]');
  61. }
  62. }
  63. }
  64. function insertSmile(smile)
  65. {
  66. document.getElementById('post').value += ' ' + smile;
  67. }