SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Threaded View

  1. #1
    SitePoint Addict
    Join Date
    May 2006
    Posts
    236
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    adding tags problem

    HTML Code:
    <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/___FAIL NAME___"' + '>' + bits[2] + '</' + pTag + '>' + bits[3];
          }
      }
    
    </script>
    </head>
    
    
    <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')">Paragraph</button>
    <button onClick="addATag(document.getElementById('text'),'A')">Link</button>
    if I write zāle and press B button, it doesn't put any tags. I suppose it's something connected with this:

    bits=(new RegExp('([\x00-\xff]{'+ta.selectionStart+'})([\x00-\xff]{'+(ta.selectionEnd - ta.selectionStart)+'})([\x00-\xff]*)')).exec(ta.value);

    I think it doesn't like long letters like ā ē ī ū and this: ģ ķ ļ č ņ


    How can I repair that?

    P.S. It works in Ie but not in FF...
    Last edited by keissfootball; Jul 16, 2006 at 07:21.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •