mam taki skrypt na bbcode pożyczony ze skryptu usebb i leciutko zmodyfikowany pod moje wymagania.

oto on
  1. function bbcode(tagOpen, tagClose, id) {
  2. [*] alert('aaaaaaa');
  3. [*] var txtarea = document.getElementById(id);
  4. [*] var sampleText = '';
  5. [*] // IE
  6. [*] if(document.selection && !is_gecko) {
  7. [*] var theSelection = document.selection.createRange().text;
  8. [*] var replaced = true;
  9. [*] if(!theSelection){
  10. [*] replaced = false;
  11. [*] theSelection=sampleText;
  12. [*] }
  13. [*] txtarea.focus();
  14. [*]
  15. [*] // This has change
  16. [*] text = theSelection;
  17. [*] if(theSelection.charAt(theSelection.length - 1) == " "){// exclude ending space char, if any
  18. [*] theSelection = theSelection.substring(0, theSelection.length - 1);
  19. [*] r = document.selection.createRange();
  20. [*] r.text = tagOpen + theSelection + tagClose + " ";
  21. [*] } else {
  22. [*] r = document.selection.createRange();
  23. [*] r.text = tagOpen + theSelection + tagClose;
  24. [*] }
  25. [*] if(!replaced){
  26. [*] r.moveStart('character',-text.length-tagClose.length);
  27. [*] r.moveEnd('character',-tagClose.length);
  28. [*] }
  29. [*] r.select();
  30. [*] // Mozilla
  31. [*] } else if(txtarea.selectionStart || txtarea.selectionStart == '0') {
  32. [*] var replaced = false;
  33. [*] var startPos = txtarea.selectionStart;
  34. [*] var endPos = txtarea.selectionEnd;
  35. [*] if(endPos - startPos) replaced = true;
  36. [*] var scrollTop=txtarea.scrollTop;
  37. [*] var myText = (txtarea.value).substring(startPos, endPos);
  38. [*] if(!myText) { myText=sampleText;}
  39. [*] if(myText.charAt(myText.length - 1) == " "){ // exclude ending space char, if any
  40. [*] subst = tagOpen + myText.substring(0, (myText.length - 1)) + tagClose + " ";
  41. [*] } else {
  42. [*] subst = tagOpen + myText + tagClose;
  43. [*] }
  44. [*] txtarea.value = txtarea.value.substring(0, startPos) + subst + txtarea.value.substring(endPos, txtarea.value.length);
  45. [*] txtarea.focus();
  46. [*]
  47. [*] //set new selection
  48. [*] if(replaced){
  49. [*] var cPos=startPos+(tagOpen.length+myText.length+tagClose.length);
  50. [*] txtarea.selectionStart=cPos;
  51. [*] txtarea.selectionEnd=cPos;
  52. [*] }else{
  53. [*] txtarea.selectionStart=startPos+tagOpen.length;
  54. [*] txtarea.selectionEnd=startPos+tagOpen.length+myText.length;
  55. [*] }
  56. [*] txtarea.scrollTop=scrollTop;
  57. [*] // All others
  58. [*] } else {
  59. [*] var copy_alertText=alertText;
  60. [*] var re1=new RegExp("\\$1","g");
  61. [*] var re2=new RegExp("\\$2","g");
  62. [*] copy_alertText=copy_alertText.replace(re1,sampleText);
  63. [*] copy_alertText=copy_alertText.replace(re2,tagOpen+sampleText+tagClose);
  64. [*] var text;
  65. [*] if (sampleText) {
  66. [*] text=prompt(copy_alertText);
  67. [*] } else {
  68. [*] text="";
  69. [*] }
  70. [*] if(!text) { text=sampleText;}
  71. [*] text=tagOpen+text+tagClose;
  72. [*] //append to the end
  73. [*] txtarea.value += "\n"+text;
  74. [*]
  75. [*] // in Safari this causes scrolling
  76. [*] if(!is_safari) {
  77. [*] txtarea.focus();
  78. [*] }
  79. [*]
  80. [*] }
  81. [*] // reposition cursor if possible
  82. [*] if (txtarea.createTextRange) txtarea.caretPos = document.selection.createRange().duplicate();
  83. [*]}


problem jest taki że skrypt nie działa mi pod operą


demo macie tutaj : http://ph.xaa.pl/forum/
dane do testowego konta to moderator / zzzzzz

pomoże ktoś ?

podbijam