Re: Blockquotes

  •  06-02-2004, 7:25 AM

    Re: Blockquotes

    Hi Adam

     
    Yes for some reason it seems not to work, it could be that the .execCommand('Indent') is meant to replace it, this inserts <blockquote>s however it includes some inline style attributes,  and also nests <p> tags, which is specifically what I'm trying to avoid ! ie like this
     
    <BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
    <P>Test</P></BLOCKQUOTE>
     
    as I'm trying to quickly get this up and running, I've gone for a bit of a dodgy workaround, on the basis that I don't need to use <ADDRESS> tags, I use .execCommand('FormatBlock', false, '<ADDRESS>') then use regex's to replace the <ADDRESS> tags with <BLOCKQUOTES>
     
    can you think of a better way ?
     
    my code below:-
     
     

    function doBlockQuotes(EditorID) {

    var editor = document.getElementById(EditorID);

    checkRange(EditorID);

    // ideally we want to use .execCommand('FormatBlock',false,'<BLOCKQUOTE>') but it does not work :-(

    // So since we are NEVER (famous last words) going to use the <ADDRESS> block functionality, but want our blockquote button to work like that

    // we first change the block into <ADDRESS> tags, using the FormatBlock functionality of the execCommand

    editor.document.execCommand('FormatBlock',false,'<ADDRESS>');

    // then sneakily we use regex's to replace <ADDRESS> tags with <BLOCKQUOTE> tags

    editor.innerHTML = editor.innerHTML.replace(/<(\/?)ADDRESS>/gi, "<$1BLOCKQUOTE>");

    // then we tidy any extra <BLOCKQUOTES> that have been unhelpfully added.

    editor.innerHTML = editor.innerHTML.replace(/<BLOCKQUOTE>\s*?<BLOCKQUOTE>/gi, "<BLOCKQUOTE>");

    editor.innerHTML = editor.innerHTML.replace(/<\/BLOCKQUOTE>\s*?<\/BLOCKQUOTE>/gi, "<\/BLOCKQUOTE>");

    editor.innerHTML = editor.innerHTML.replace(/<BLOCKQUOTE>\s*?<\/BLOCKQUOTE>/gi, "");

    }

    function unBlockQuotes(EditorID) {

    checkRange(EditorID);

    // well you'd think that selecting normal from the paragraph menu would revert the <blockquotes> back into <p>'s

    // it does if you try it twice (once to insert <p>'s inside the <blockquotes>, the 2nd time, removing the <blockquotes>)

    // that may be liveable with if not

    var editor = document.getElementById(EditorID);

    // change the formatBlock to be normal paragraphs

    editor.document.execCommand('FormatBlock',false,'<P>');

    // use regexs to tidy up nested <P> tags inside <blockquotes>

    editor.innerHTML = editor.innerHTML.replace(/<BLOCKQUOTE>\s*?<P>/gi,"<P>");

    editor.innerHTML = editor.innerHTML.replace(/<\/P>s*?<\/BLOCKQUOTE>/gi,"<\/P>");

    editor.innerHTML = editor.innerHTML.replace(/<BLOCKQUOTE>\s*?<\/BLOCKQUOTE>/gi, "");

    }
     
    and a couple of toolbar images
     
     
    regards
     
     
    marc
     
     
     
     
View Complete Thread