swapNode() under Mozilla issue...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • poofpoof

    swapNode() under Mozilla issue...

    hi all,

    if that can help somebody....

    feedback welcome

    <html>
    <head>

    <style type="text/css">
    blockquote{ border:1px solid red;margin:15px ;padding:2px;}
    div{border:1px solid blue; margin:2px; padding:2px;}

    </style>

    <script language="javas cript" >
    if(self.Node) {
    Node.prototype. swapNode = function(n){
    var p = n.parentNode;
    var s = n.nextSibling;
    this.parentNode .replaceChild(n ,this);
    p.insertBefore( this,s);
    return this;
    }
    }

    function is_all_ws( nod )
    {
    // Use ECMA-262 Edition 3 String and RegExp features
    return !(/[^\t\n\r ]/.test(nod.data) );
    }

    function is_ignorable( nod ){
    return ( nod.nodeType == 8) || // A comment node
    ( (nod.nodeType == 3) && is_all_ws(nod) ); // a text node, all ws
    }

    function node_before( sib ){
    while ((sib = sib.previousSib ling)) {
    if (!is_ignorable( sib))
    return sib;
    }
    return null;
    }

    function node_after( sib ){
    while ((sib = sib.nextSibling )) {
    if (!is_ignorable( sib))
    return sib;
    }
    return null;
    }

    function move( obj, direction ){
    while( obj.nodeName != "BLOCKQUOTE " )
    obj = obj.parentNode;

    if( direction == 1 && obj != obj.parentNode. lastChild ){
    var cur = obj;
    while (cur){
    if (cur.nodeName == "BLOCKQUOTE "){
    obj.swapNode( cur )
    }
    cur = node_after(cur) ;
    }
    }

    if( direction == -1 && obj != obj.parentNode. firstChild ){
    var cur = obj;
    while (cur){
    if (cur.nodeName == "BLOCKQUOTE "){
    obj.swapNode( cur )
    }
    cur = node_before(cur );
    }
    }
    }
    </script>
    </head>
    <body>


    <div id="root">
    <blockquote>
    <a href="javascrip t:void(0)" onclick="move(t his, -1)">up</a>
    <a href="javascrip t:void(0)" onclick="move(t his, 1)">down</a>
    <input type="text" name="field" value="1">
    </blockquote>
    <blockquote>
    <a href="javascrip t:void(0)" onclick="move(t his, -1)">up</a>
    <a href="javascrip t:void(0)" onclick="move(t his, 1)">down</a>
    <input type="text" name="field" value="2">
    </blockquote>

    </div>


    </body>

    </html>
  • Michael Winter

    #2
    Re: swapNode() under Mozilla issue...

    On 29 Jul 2004 03:56:31 -0700, poofpoof <poofpoof@free. fr> wrote:
    [color=blue]
    > hi all,
    >
    > if that can help somebody....[/color]

    Help with what? You've presented code and implied that there is an "issue"
    with Mozilla, but failed to describe it. As far as I can tell, there's
    nothing wrong, other than some undesirable padding due to the whitespace
    between block elements. You could get rid of that either by formatting the
    HTML to include no whitespace between the DIV and BLOCKQUOTE elements.
    Alternatively, you could use the DOM to delete the corresponding text
    nodes.

    Is this a request for help, or a solution?

    Mike

    [snipped code]

    Comment

    Working...