From: Stefan Lage Date: Fri, 24 May 2013 00:17:41 +0000 (-0400) Subject: nitdoc: Adds function to create a new comment X-Git-Tag: v0.6~46^2~16 X-Git-Url: http://nitlanguage.org nitdoc: Adds function to create a new comment Adding function which allow to comment a function which is not yet. signed-off by: Stefan Lage --- diff --git a/share/nitdoc/scripts/js-facilities.js b/share/nitdoc/scripts/js-facilities.js index ccbfbb5..f46ac9c 100644 --- a/share/nitdoc/scripts/js-facilities.js +++ b/share/nitdoc/scripts/js-facilities.js @@ -3,6 +3,7 @@ var userB64 = null; var sessionStarted = false; var editComment = 0; var currentfileContent = ''; +var addNewComment = false; // SHA GitHub var shaLastCommit = ""; @@ -593,6 +594,24 @@ $(document).ready(function() { } }); + $('a[class=newComment]').click(function(){ + addNewComment = true; + editComment += 1; + // hide comment + $(this).hide(); + // Show edit box + $(this).next().show(); + // Show cancel button + $(this).next().next().show(); + // Show commit button + $(this).next().next().next().show(); + // Resize edit box + $(this).next().height($(this).next().prop("scrollHeight")); + // Select it + $(this).next().select(); + preElement = $(this); + }); + }); /* Parse current URL and return anchor name */ @@ -647,6 +666,7 @@ function startCommitProcess() { var numL = preElement.attr("title"); commentLineStart = numL.split('-')[0] - 1; + if(addNewComment) { commentLineStart++; } commentLineEnd = (commentLineStart + preElement.text().split('\n').length) - 1; state = true; replaceComment(updateComment, currentfileContent); @@ -1027,6 +1047,13 @@ function replaceComment(newComment, fileContent){ var lines = fileContent.split("\n"); for (var i = 0; i < lines.length; i++) { if(i == commentLineStart){ + if(addNewComment){ + for(var indexLine=0; indexLine < lines[i+1].length; indexxLine++){ + if(lines[i+1].substr(indexLine,1) == "\t" || lines[i+1].substr(indexLine,1) == "#"){ text += lines[i+1].substr(indexLine,1); } + else{ break;} + } + text += lines[i] + "\n"; + } // We change the comment for(var j = 0; j < lNew; j++){ if(commentType == 1){ text += "\t# " + arrayNew[j] + "\n"; } @@ -1041,6 +1068,9 @@ function replaceComment(newComment, fileContent){ else{ text += lines[i] + "\n"; } } } + if(addNewComment){ + addNewComment = false; + } } function getCommentLastCommit(path){