Может у кого имеется подобная функция, буду благодарен.. суть функции: передается 3 параметра 1 - ид элемента textarea (где будет производиться поиск) 2 и 3 - по краям найденного текста добавляем значения этих параметров, например, Код (Text): myfunc('id_txarea','[b]','[/b]') текст для поиска - текущий выделенный текст в теге textarea с ид id_txarea
Kreker спасибо Mr.M.I.T. слишком много лишнего.. В общем сделал так, вроде работает как надо по условию задачи (ie,ff,opera): Код (Text): function paste_str(id,bb1,bb2) { var str; var id=document.getElementById(id); if (id) if (document.selection) { id.focus(); sel = document.selection.createRange(); sel.text = bb1 + sel.text + bb2; sel.select(); return; } else { var startPos = id.selectionStart; var endPos = id.selectionEnd; str = id.value.substring(startPos, endPos); id.value = id.value.substring(0, startPos) + bb1 + str + bb2 + id.value.substring(endPos, id.value.length); return; } }
[js]function bbstyle(bbnumber) { var txtarea = document.post.message; txtarea.focus(); donotinsert = false; theSelection = false; bblast = 0; if (bbnumber == -1) { // Close all open tags & default button names while (bbcode[0]) { butnumber = arraypop(bbcode) - 1; txtarea.value += bbtags[butnumber + 1]; buttext = eval('document.post.addbbcode' + butnumber + '.value'); eval('document.post.addbbcode' + butnumber + '.value ="' + buttext.substr(0,(buttext.length - 1)) + '"'); } imageTag = false; // All tags are closed including image tags txtarea.focus(); return; } if ((clientVer >= 4) && is_ie && is_win) { theSelection = document.selection.createRange().text; // Get text selection if (theSelection) { // Add tags around selection document.selection.createRange().text = bbtags[bbnumber] + theSelection + bbtags[bbnumber+1]; txtarea.focus(); theSelection = ''; return; } } else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0)) { mozWrap(txtarea, bbtags[bbnumber], bbtags[bbnumber+1]); return; } // Find last occurance of an open tag the same as the one just clicked for (i = 0; i < bbcode.length; i++) { if (bbcode == bbnumber+1) { bblast = i; donotinsert = true; } } if (donotinsert) { // Close all open tags up to the one just clicked & default button names while (bbcode[bblast]) { butnumber = arraypop(bbcode) - 1; txtarea.value += bbtags[butnumber + 1]; buttext = eval('document.post.addbbcode' + butnumber + '.value'); eval('document.post.addbbcode' + butnumber + '.value ="' + buttext.substr(0,(buttext.length - 1)) + '"'); imageTag = false; } txtarea.focus(); return; } else { // Open tags if (imageTag && (bbnumber != 14)) { // Close image tag before adding another txtarea.value += bbtags[15]; lastValue = arraypop(bbcode) - 1; // Remove the close image tag from the list document.post.addbbcode14.value = "Img"; // Return button back to normal state imageTag = false; } // Open tag txtarea.value += bbtags[bbnumber]; if ((bbnumber == 14) && (imageTag == false)) imageTag = 1; // Check to stop additional tags after an unclosed image tag arraypush(bbcode,bbnumber+1); eval('document.post.addbbcode'+bbnumber+'.value += "*"'); txtarea.focus(); return; } storeCaret(txtarea); }[/js]