tools-yak
[Top] [All Lists]

[tools-yak@collab] Initial javascript comment code

To: tools-yak@xxxxxxxxxxxxxxxxxxx
From: "Peter P. Jones" <ppj@xxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 04 Feb 2004 19:47:36 -0000
Message-id: <40214C58.7409.85EA49@localhost>
Just thought I'd post up the first iteration of the javascript 
commenting code I've been playing with.
This version isn't anything special really - it just puts in a row of 
comments as children of a paragraph, and the way it does it isn't 
perhaps as clean as it could be.
I'm currently in the process of rewriting and debugging a version 
that does nested recursing commenting, and I hope to post that soon.
(After that, getting some version of a hidden form POST to work with 
a server.)    (01)

-----code starts here---------------------------------------
<script language="javascript1.2">
<!--
Nodes in the HTML doc that you want to be commentable should take the 
form
<p><a id="YOUR_NODE_ID" name="YOUR_NODE_ID">...your text here...
<a href="javascript:onEdit('YOUR_NODE_ID')">Add Comment</a></p>
so all existing purple numbering systems need to do is add the 
comment link.    (02)

This version does not produce recursion of comments - all comments 
are in a single line.    (03)

This script only updates the client copy, so if you want to preserve
your work you'll need to have some way to save from the browser now 
and again.    (04)

License: Free for use, distribution, and modification.
Author: Peter P. Jones at Concept67
-->
// <!--    (05)



function onEdit(nodeId){
    var myCount = 1;    (06)

    var rgxp1 = new RegExp("nid[0-9]+_[0-9]*$");
    var rgxp2 = new RegExp("_[0-9]*$");
    var rgxp3 = new RegExp("[0-9]*$");
    //myCount++;   //crude fix for prototype only
    var tbody = document.getElementById(nodeId).parentNode;
    var lastCom = tbody.lastChild.getAttribute('id');
    if(lastCom != null && rgxp1.exec(lastCom) != null){
       var tempStr = rgxp2.exec(lastCom);
    //alert("tempStr" + tempStr);
       var countStr = rgxp3.exec(tempStr); 
    //alert("countStr" + countStr);
    //alert(lastCom + ":" + countStr + ":" + rgxp2.exec(lastCom));
       myCount = ++countStr;
    }    (07)

    var addEl = document.createElement("textarea");
    addEl.setAttribute('id', nodeId + "_" + myCount );
    addEl.appendChild(document.createTextNode("Comment in here"));
    var aaa = document.createElement("a");
    aaa.setAttribute('href', "javascript:onSubmit('" + nodeId + "_" + 
myCount + "')" );
    aaa.setAttribute('id', "a" + nodeId + "_" + myCount );    (08)

    aaa.appendChild(document.createTextNode("Submit"));    (09)

    //alert(tbody);
    tbody.appendChild(addEl);
    tbody.appendChild(aaa);    (010)

}    (011)

function onSubmit(nodeId) {
    //alert("Submitting stuff" + nodeId);
    var inNode = document.getElementById(nodeId);
    var textNode;
    if(inNode.hasChildNodes()){
       textNode = document.getElementById(nodeId).lastChild;    (012)

    } 
    var rbody = document.getElementById(nodeId).parentNode;
    var nuEl = document.createElement("p");
    nuEl.setAttribute('class', "comment");
    nuEl.appendChild(textNode);
    try {
       rbody.removeChild(document.getElementById('a' + nodeId));
       inNode.setAttribute('id', "blah");
       nuEl.setAttribute('id', nodeId);
       var tmpNode = rbody.replaceChild(nuEl, inNode);    (013)

    } catch (DOMException){
      alert("Replace failed" + e);
    }    (014)

}    (015)



// -->
</script>
------------end code---------------------------    (016)


-- 
This message is archived at:    (017)

http://collab.blueoxen.net/forums/cgi-bin/mesg.cgi?a=tools-yak&i=40214C58.7409.85EA49@localhost    (018)
<Prev in Thread] Current Thread [Next in Thread>