nitdoc: Fix bugs: Forgot variable definition
[nit.git] / share / nitdoc / scripts / js-facilities.js
index 58cbddf..84aab54 100644 (file)
@@ -3,6 +3,9 @@ var userB64 = null;
 var sessionStarted = false;\r
 var editComment = 0;\r
 var currentfileContent = '';\r
+var addNewComment = false;\r
+var commentLineStart;\r
+var commentLineEnd;\r
 \r
 // SHA GitHub\r
 var shaLastCommit = "";\r
@@ -53,6 +56,12 @@ var currentTable = null;
 //Hightlighted index in search result preview table\r
 var currentIndex = -1;\r
 \r
+// Check if a comment is editing\r
+window.onbeforeunload = function() {\r
+       if(editComment > 0){\r
+       return 'Are you sure you want to leave this page?';\r
+       }\r
+};\r
 \r
 /*\r
 * Add folding and filtering facilities to class description page.\r
@@ -65,11 +74,9 @@ $(document).ready(function() {
        $('a[id=cancelBtn]').hide();\r
        // Hide Authenfication form\r
        $(".popover").hide();\r
+       githubRepo = $('#repoName').attr('name');\r
        // Update display\r
        updateDisplaying();\r
-       githubRepo = $('#repoName').attr('name');\r
-       // Load comment from the original repo\r
-       reloadComment();\r
        /*\r
        * Highlight the spoted element\r
        */\r
@@ -587,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
@@ -641,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
@@ -658,6 +684,7 @@ function displayLogginModal(){
 function updateDisplaying(){\r
        if (checkCookie())\r
        {\r
+               userB64 = "Basic " + getUserPass("logginNitdoc"); \r
                $('#loginGit').hide();\r
                $('#passwordGit').hide();\r
                $('#lbpasswordGit').hide();             \r
@@ -675,6 +702,7 @@ function updateDisplaying(){
                $('.popover').css({'height' : '80px'}); \r
                $('#signIn').text("Sign out");  \r
                sessionStarted = true;\r
+               reloadComment();\r
        }\r
        else\r
        {\r
@@ -1021,6 +1049,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
@@ -1035,6 +1070,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