• 'Quote selected text' javascript funtion

    By Craig Vertigan 2 decades ago

    The code in the common.js javascript library for the function 'quote(mode)' only works in IE since FireFox doesn't use document.selection.



    So I changed it to this so that it works in both IE and FireFox:



    //quote parent

    function quote(mode) {

    if (mode!='')<br/>
    {<br/>
        var selectedText;<br/>
        if(document.selection)<br/>
        {<br/>
            selectedText = document.selection ;//IE<br/>
            if (selectedText.type=='Text')<br/>
            {<br/>
                var newRange = selectedText.createRange(); <br/>
                tmp_text=newRange.text<br/>
            }<br/>
            else<br/>
            {<br/>
                return true<br/>
            }<br/>
        }<br/>
        else<br/>
        {<br/>
            selectedText = window.getSelection() ;//FireFox<br/>
            tmp_text = selectedText.toString();<br/>
        }<br/>
    }<br/>
    else {var tmp_text=onimod_parenttext}<br/>
    tmp_text=tmp_text.replace(new RegExp(&quot;(&lt;BR&gt;)&quot;, &quot;g&quot;),'\n')<br/>
    document.forms[0].Content.focus();<br/>
    document.forms[0].Content.value = document.forms[0].Content.value+'[QUOTE]'+tmp_text+'[/QUOTE]';<br/>
    _UpdateContentPreview ()<br/>
    

    }