nitdoc: Adds function to create a new comment
authorStefan Lage <lagestfan@gmail.com>
Fri, 24 May 2013 00:17:41 +0000 (20:17 -0400)
committerStefan Lage <lagestfan@gmail.com>
Fri, 24 May 2013 02:26:50 +0000 (22:26 -0400)
Adding function which allow to comment a function which is not yet.

signed-off by: Stefan Lage <lagestfan@gmail.com>

share/nitdoc/scripts/js-facilities.js

index ccbfbb5..f46ac9c 100644 (file)
@@ -3,6 +3,7 @@ var userB64 = null;
 var sessionStarted = false;\r
 var editComment = 0;\r
 var currentfileContent = '';\r
+var addNewComment = false;\r
 \r
 // SHA GitHub\r
 var shaLastCommit = "";\r
@@ -593,6 +594,24 @@ $(document).ready(function() {
                }\r
        });\r
 \r
+       $('a[class=newComment]').click(function(){\r
+               addNewComment = true;                   \r
+               editComment += 1;\r
+               // hide comment\r
+               $(this).hide();\r
+               // Show edit box \r
+               $(this).next().show();\r
+               // Show cancel button\r
+               $(this).next().next().show();\r
+               // Show commit button\r
+               $(this).next().next().next().show();\r
+               // Resize edit box \r
+               $(this).next().height($(this).next().prop("scrollHeight"));\r
+               // Select it\r
+               $(this).next().select();\r
+               preElement = $(this);  \r
+        });\r
+\r
 });\r
 \r
 /* Parse current URL and return anchor name */\r
@@ -647,6 +666,7 @@ function startCommitProcess()
 {\r
        var numL = preElement.attr("title");\r
        commentLineStart = numL.split('-')[0] - 1;      \r
+       if(addNewComment) { commentLineStart++; }\r
        commentLineEnd = (commentLineStart + preElement.text().split('\n').length) - 1;\r
        state = true;   \r
        replaceComment(updateComment, currentfileContent);\r
@@ -1027,6 +1047,13 @@ function replaceComment(newComment, fileContent){
        var lines = fileContent.split("\n");\r
        for (var i = 0; i < lines.length; i++) {\r
                if(i == commentLineStart){\r
+                       if(addNewComment){\r
+                               for(var indexLine=0; indexLine < lines[i+1].length; indexxLine++){\r
+                                       if(lines[i+1].substr(indexLine,1) == "\t" || lines[i+1].substr(indexLine,1) == "#"){ text += lines[i+1].substr(indexLine,1); }\r
+                                       else{ break;}\r
+                               }\r
+                               text += lines[i] + "\n"; \r
+                       }\r
                        // We change the comment\r
                        for(var j = 0; j < lNew; j++){\r
                                if(commentType == 1){ text += "\t# " + arrayNew[j] + "\n"; }\r
@@ -1041,6 +1068,9 @@ function replaceComment(newComment, fileContent){
                        else{ text += lines[i] + "\n"; }\r
                }\r
        }\r
+       if(addNewComment){\r
+               addNewComment = false;\r
+       }\r
 }\r
 \r
 function getCommentLastCommit(path){\r