jauninjais Posted July 16, 2006 Report Share Posted July 16, 2006 (edited) man ir shaads kods (kods iespeejams ir videeji garsh, bet nav sarezgjiits - vairaakas daljas atkaartojas) : <script type="text/javascript"> function getSelection(ta) { var bits = [ta.value,'','','']; if(document.selection) { var vs = '#$%^%$#'; var tr=document.selection.createRange() if(tr.parentElement()!=ta) return null; bits[2] = tr.text; tr.text = vs; fb = ta.value.split(vs); tr.moveStart('character',-vs.length); tr.text = bits[2]; bits[1] = fb[0]; bits[3] = fb[1]; } else { if(ta.selectionStart == ta.selectionEnd) return null; bits=(new RegExp('([\x00-\xff]{'+ta.selectionStart+'})([\x00-\xff]{'+(ta.selectionEnd - ta.selectionStart)+'})([\x00-\xff]*)')).exec(ta.value); } return bits; } function matchPTags(str) { str = ' ' + str + ' '; ot = str.split(/\[[B|U|I].*?\]/i); ct = str.split(/\[\/[B|U|I].*?\]/i); return ot.length==ct.length; } function addPTag(ta,pTag) { bits = getSelection(ta); if(bits) { if(!matchPTags(bits[2])) { alert('\t\tNav aizvērta kāda iekava.'); return; } ta.value = bits[1] + '<' + pTag + '>' + bits[2] + '</' + pTag + '>' + bits[3]; } } function addZTag(ta,pTag) { bits = getSelection(ta); if(bits) { if(!matchPTags(bits[2])) { alert('\t\tNav aizvērta kāda iekava.'); return; } ta.value = bits[1] + bits[2] + '</' + pTag + '>' + bits[3]; } } function addATag(ta,pTag) { bits = getSelection(ta); if(bits) { if(!matchPTags(bits[2])) { alert('\t\tNav aizvērta kāda iekava.'); return; } ta.value = bits[1] + '<' + pTag + ' HREF="uploads/___FAILA NOSAUKUMS___"' + '>' + bits[2] + '</' + pTag + '>' + bits[3]; } } </script> </head> <body> <button onClick="addPTag(document.getElementById('text'),'B')"><b>Bold</b></button> <button onClick="addPTag(document.getElementById('text'),'I')"><i>Italic</i></button> <button onClick="addPTag(document.getElementById('text'),'U')"><u>Underline</u></button> <button onClick="addZTag(document.getElementById('text'),'BR')">Rindkopa</button> <button onClick="addATag(document.getElementById('text'),'A')">Links</button> es tik nesaprotu, ja es piemeeram raxtu parastu tekstu be garum&miikstinaajum ziimeem, tad visi tagi liekas, a kad man tekstaa kaut viena neangliskaa ziime, tad es varu spaidiit cik gribu taas pogas, nekas nemainiisies. man skjiet, ka pie vainas ir shii rinda bits=(new RegExp('([\x00-\xff]{'+ta.selectionStart+'})([\x00-\xff]{'+(ta.selectionEnd - ta.selectionStart)+'})([\x00-\xff]*)')).exec(ta.value); es tik nesaprotu, kaa vinjam uzlikt, lai vinsh saprastu LV burtus. neprasu lai juus raxtiitu kodu, vnk kaadu padomu, varbuut linku... p.s Straadaa uz IE, bet ne uz FF... Edited July 16, 2006 by jauninjais Link to comment Share on other sites More sharing options...
Recommended Posts