nitdoc: fixed shared files with ni_nitdoc.
[nit.git] / share / ni_nitdoc / scripts / static / git-favicon.png
diff --git a/share/nitdoc/scripts/github.js b/share/nitdoc/scripts/github.js
deleted file mode 100644 (file)
index 54ed212..0000000
+++ /dev/null
@@ -1,1041 +0,0 @@
-// User\r
-var userB64 = null;\r
-var userName = "";\r
-var password = "";\r
-var sessionStarted = false;\r
-var editComment = 0;\r
-var currentfileContent = '';\r
-var originalFileContent = '';\r
-var addNewComment = false;\r
-var commentLineStart;\r
-var commentLineEnd;\r
-\r
-// SHA GitHub\r
-var shaLastCommit = "";\r
-var shaBaseTree;\r
-var shaNewTree;\r
-var shaNewCommit;\r
-var shaBlob;\r
-var shaMaster;\r
-var repoExist = false;\r
-var branchExist = false;\r
-var githubRepo;\r
-var loginProcess = false; \r
-var signedOff = '';\r
-var userEmail = '';\r
-var commitMessage = '';\r
-var numComment = '';\r
-var showcomment = false;\r
-\r
-// Spinner vars\r
-var opts = {\r
-         lines: 11, // The number of lines to draw\r
-         length: 7, // The length of each line\r
-         width: 4, // The line thickness\r
-         radius: 10, // The radius of the inner circle\r
-         corners: 1, // Corner roundness (0..1)\r
-         rotate: 0, // The rotation offset\r
-         color: '#FFF', // #rgb or #rrggbb\r
-         speed: 1, // Rounds per second\r
-         trail: 60, // Afterglow percentage\r
-         shadow: false, // Whether to render a shadow\r
-         hwaccel: false, // Whether to use hardware acceleration\r
-         className: 'spinner', // The CSS class to assign to the spinner\r
-         zIndex: 99999, // The z-index (defaults to 2000000000)\r
-         top: '300', // Top position relative to parent in px\r
-         left: 'auto' // Left position relative to parent in px\r
-       };\r
-var targetSpinner = document.getElementById('waitCommit');\r
-var spinner = new Spinner(opts).spin(targetSpinner);\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
-$(document).ready(function() {\r
-       createLoginBox();\r
-       // Hide edit tags\r
-       $('textarea').hide();\r
-       $('a[id=commitBtn]').hide();\r
-       $('a[id=cancelBtn]').hide();\r
-       // Display Login modal\r
-       $("#logGitHub").click(function(){ toggleLoginBox(); });\r
-       // Update display\r
-       updateDisplaying();\r
-       // If cookie existing the session is opened\r
-       if(sessionStarted){ userB64 = "Basic " + getUserPass("logginNitdoc"); }\r
-\r
-       // Sign In an github user or Log out him\r
-       $("#signIn").click(function(){\r
-               if(!sessionStarted){\r
-                       if($('#loginGit').val() == "" || $('#passwordGit').val() == ""){ displayMessage('Please informed login/password field!', 40, 45); }\r
-                       else\r
-                       {\r
-                               userName = $('#loginGit').val();\r
-                               password = $('#passwordGit').val();\r
-                               githubRepo = $('#repositoryGit').val();\r
-                               branchName = $('#branchGit').val();\r
-                               userB64 = "Basic " +  base64.encode(userName+':'+password);\r
-                               if(checkSignIn()){\r
-                                       // Check if repo exist\r
-                                       isRepoExisting();\r
-                                       if(repoExist){\r
-                                               $.when(isBranchExisting()).done(function(){\r
-                                                       loginProcess = true;\r
-                                                       if(branchExist){\r
-                                                               setCookie("logginNitdoc", base64.encode(userName+':'+password+':'+githubRepo+':'+branchName), 1);\r
-                                                               $('#loginGit').val("");\r
-                                                               $('#passwordGit').val("");\r
-                                                               reloadComment();\r
-                                                       }\r
-                                               });\r
-                                       }\r
-                               }\r
-                       }\r
-               }       \r
-               else\r
-               {\r
-                       // Delete cookie and reset settings\r
-                       del_cookie("logginNitdoc");\r
-                       closeAllCommentInEdtiting();\r
-               }       \r
-               toggleLoginBox();\r
-       });\r
-\r
-       // Activate edit mode\r
-       $('pre[class=text_label]').click(function(){\r
-               // the customer is loggued ?\r
-               if(!sessionStarted || userName == ""){\r
-                       // No => nothing happen\r
-                       return;\r
-               }\r
-               else{\r
-                       numComment = $(this).attr('title');\r
-                       var arrayNew = $(this).text().split('\n');\r
-                       var lNew = arrayNew.length - 1;\r
-                       var adapt = "";\r
-\r
-                       for (var i = 0; i < lNew; i++) {\r
-                               adapt += arrayNew[i];\r
-                               if(i < lNew-1){ adapt += "\n"; }\r
-                       }\r
-                       editComment += 1;\r
-                       getCommentOfFunction($(this));\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
-                       // Add text in edit box\r
-                       if($(this).next().val() == "" || $(this).next().val() != adapt){ $(this).next().val(adapt); }\r
-                       // Resize edit box \r
-                       $(this).next().height($(this).next().prop("scrollHeight"));\r
-                       resizeTextarea($(this).next());\r
-                       // Select it\r
-                       $(this).next().select();\r
-                       preElement = $(this);\r
-               }\r
-       });\r
-\r
-       // Disable the edit mode\r
-       $('a[id=cancelBtn]').click(function(){\r
-               $(this).parent().prev().children('#lblDiffCommit').text("");\r
-               showcomment = false;\r
-               closeEditing($(this));\r
-       });\r
-\r
-       // Display commit form\r
-       $('a[id=commitBtn]').click(function(){\r
-               updateComment = $(this).prev().prev().val();\r
-               commentType = $(this).prev().prev().prev().attr('type');\r
-\r
-               if(updateComment == ""){ displayMessage('The comment field is empty!', 40, 45); }\r
-               else{\r
-                       if(!sessionStarted){\r
-                               displayMessage("You need to be loggued before commit something", 45, 40);\r
-                               toggleLoginBox();\r
-                               return;\r
-                       }\r
-                       \r
-                       // Create the commit message\r
-                       commitMessage = 'Wikidoc: modified comment in ' + $(this).parent().prev().prev().html().split(' ')[1];\r
-                       $('#commitMessage').text(commitMessage);\r
-                       $('#commitMessage').css({'display': 'block'});\r
-                       pathFile = $(this).prev().prev().prev().attr('tag');\r
-                       $('#modal').show().prepend('<a class="close"><img src="resources/icons/close.png" class="btn_close" title="Close" alt="Close" /></a>');\r
-                       $('body').append('<div id="fade"></div>');\r
-                       $('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();\r
-               }\r
-        });\r
-\r
-       // Close commit form\r
-       $('.btn_close').click(function(){\r
-               $(this).hide();                 \r
-               $(this).next().hide();                  \r
-               if(editComment > 0){ editComment -= 1; }\r
-               $('#chkSignedOff').attr('checked', false);\r
-               removeSignedOff();\r
-        });\r
-\r
-       //Close Popups and Fade Layer\r
-       $('body').on('click', 'a.close, #fade', function() {\r
-               if(editComment > 0){ editComment -= 1; }\r
-               $('#fade , #modal').fadeOut(function() {\r
-                       $('#fade, a.close').remove();  \r
-               });             \r
-               $('#modalQuestion').hide();\r
-               $('#chkSignedOff').attr('checked', false);\r
-               removeSignedOff();\r
-       });\r
-\r
-       $('#loginAction').click(function(){\r
-               var text;\r
-               var url;\r
-               var line;\r
-               // Look if the customer is logged\r
-               if(!sessionStarted){\r
-                       displayMessage("You need to be loggued before commit something", 100, 40);\r
-                       $('.popover').show();\r
-                       return;\r
-               }\r
-               else{ userB64 = "Basic " + getUserPass("logginNitdoc"); }\r
-               // Check if repo exist\r
-               isRepoExisting();\r
-               if(repoExist){\r
-                       isBranchExisting();\r
-                       if(branchExist){\r
-                               editComment -= 1;\r
-                               commitMessage = $('#commitMessage').val().replace(/\r?\n/g, '\\n').replace(/\t/g, '\\t').replace(/\"/g,'\\"');\r
-                               if(commitMessage == ""){ commitMessage = "New commit";}\r
-                               if(sessionStarted){\r
-                                       if ($.trim(updateComment) == ''){ this.value = (this.defaultValue ? this.defaultValue : ''); }\r
-                                       else{ \r
-                                               displaySpinner();\r
-                                               startCommitProcess();\r
-                                       }\r
-                               }\r
-                               $('#modal, #modalQuestion').fadeOut(function() {\r
-                                       $('#login').val("");\r
-                                       $('#password').val("");\r
-                                       $('textarea').hide();\r
-                                       $('textarea').prev().show();\r
-                               });\r
-                               $('a[id=cancelBtn]').hide();\r
-                               $('a[id=commitBtn]').hide();\r
-                               $('a[id=lblDiffCommit]').text("");\r
-                               showcomment = false;\r
-                               // Re-load all comment\r
-                               reloadComment();\r
-                       }\r
-               }\r
-               else{ editComment -= 1; }\r
-               $('#chkSignedOff').attr('checked', false);\r
-       });\r
-       \r
-       // Cancel creating branch\r
-       $('#btnCancelBranch').click(function(){\r
-               editComment -= 1;\r
-               $('#modalQuestion').hide();\r
-               $('#fade , #modal').fadeOut(function() { $('#fade, a.close').remove(); });\r
-               return;\r
-       });\r
-\r
-       // Create new branch and continu\r
-       $('#btnCreateBranch').click(function(){\r
-               $('#modalQuestion').hide();\r
-               if($('#btnCreateBranch').text() != 'Ok'){\r
-                       // Create the branch\r
-                       createBranch();\r
-                       commitMessage = $('#commitMessage').val().replace(/\r?\n/g, '\\n').replace(/\t/g, '\\t').replace(/\"/g,'\\"');\r
-                       if(commitMessage == ""){ commitMessage = "New commit"; }\r
-                       if(userB64 != ""){                      \r
-                       if(loginProcess){\r
-                                       setCookie("logginNitdoc", base64.encode(userName+':'+password+':'+githubRepo+':'+branchName), 1);        \r
-                                       $('#loginGit').val("");\r
-                                       $('#passwordGit').val("");\r
-                                       loginProcess = false;          \r
-                                       toggleLoginBox();\r
-                       }\r
-                       else{\r
-                                       if ($.trim(updateComment) == ''){ this.value = (this.defaultValue ? this.defaultValue : ''); }\r
-                                       else{ startCommitProcess(); }\r
-                               } \r
-                   }\r
-               }\r
-               else\r
-               {\r
-                       $('#fade , #modalQuestion, #modal').fadeOut(function() { $('#fade, a.close').remove(); });\r
-               }\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
-               resizeTextarea($(this).next());\r
-               // Select it\r
-               $(this).next().select();\r
-               preElement = $(this);  \r
-        });\r
-\r
-       $("#dropBranches").change(function () {         \r
-               $("#dropBranches option:selected").each(function () {\r
-                       if(branchName != $(this).text()){\r
-                               branchName = $(this).text();\r
-                       }\r
-               });\r
-               $.when(updateCookie(userName, password, githubRepo, branchName)).done(function(){\r
-                       closeAllCommentInEdtiting();\r
-                       reloadComment();\r
-               });\r
-       });\r
-\r
-       $("pre").hover(\r
-               function () {\r
-                       if(sessionStarted == true){\r
-                               $(this).css({'cursor' : 'hand'});\r
-                       }\r
-                       else{\r
-                               $(this).css({'cursor' : ''});\r
-                       }\r
-               },\r
-               function () {\r
-                       if(sessionStarted == true){\r
-                               $(this).css({'cursor' : 'pointer'});\r
-                       }\r
-                       else{\r
-                               $(this).css({'cursor' : ''});   \r
-                       }\r
-               }\r
-       );\r
-\r
-       $('#chkSignedOff').click(function(){\r
-               if($(this).is(':checked')){ addSignedOff(); }\r
-               else{ removeSignedOff(); }\r
-       })\r
-\r
-       $('a[id=lblDiffCommit]').click(function(){\r
-               showComment($(this));\r
-       });\r
-});\r
-\r
-// Init process to commit the new comment\r
-function startCommitProcess()\r
-{      \r
-       if($('#chkSignedOff').is(':checked')){\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
-               getLastCommit();        \r
-               getBaseTree();  \r
-               editComment = false;\r
-       }\r
-       else{\r
-               displayMessage('Please sign this commit', 40, 40); \r
-       }\r
-}\r
-\r
-function updateDisplaying(){\r
-       if (checkCookie())\r
-       {\r
-               userB64 = "Basic " + getUserPass("logginNitdoc"); \r
-               $('#loginGit').hide();\r
-               $('#passwordGit').hide();\r
-               $('#lbpasswordGit').hide();             \r
-               $('#lbloginGit').hide();        \r
-               $('#repositoryGit').hide();\r
-               $('#lbrepositoryGit').hide();\r
-               $('#lbbranchGit').hide();  \r
-               $('#branchGit').hide();\r
-               $('#listBranches').show();\r
-               $('#divGitHubRepoDisplay').show();\r
-               $("#liGitHub").attr("class", "current");\r
-               $("#imgGitHub").attr("src", "resources/icons/github-icon-w.png");\r
-               $('#nickName').text(userName);\r
-               $('#githubAccount').attr("href", "https://github.com/"+userName);\r
-               $('#logginMessage').css({'display' : 'block'});\r
-               $('#logginMessage').css({'text-align' : 'center'});\r
-               $('.popover').css({'height' : '190px'});\r
-               $('#signIn').text("Sign out");\r
-               $('#githubRepoDisplay').text(githubRepo);\r
-               sessionStarted = true;\r
-               reloadComment();\r
-       }\r
-       else\r
-       {\r
-               sessionStarted = false;\r
-               $('#logginMessage').css({'display' : 'none'});\r
-               $("#liGitHub").attr("class", "");\r
-               $("#imgGitHub").attr("src", "resources/icons/github-icon.png");\r
-               $('#loginGit').val("");\r
-               $('#passwordGit').val("");\r
-               $('#nickName').text("");\r
-               $('.popover').css({'height' : '325px'});\r
-               $('#logginMessage').css({'display' : 'none'});\r
-               $('#repositoryGit').val($('#repoName').attr('name'));\r
-               $('#branchGit').val('wikidoc');  \r
-               $('#signIn').text("Sign In");\r
-               $('#loginGit').show();\r
-               $('#passwordGit').show();\r
-               $('#lbpasswordGit').show();\r
-               $('#lbloginGit').show();        \r
-               $('#repositoryGit').show();\r
-               $('#lbrepositoryGit').show();\r
-               $('#lbbranchGit').show();  \r
-               $('#branchGit').show();  \r
-               $('#listBranches').hide();\r
-               $('#divGitHubRepoDisplay').hide();\r
-       }\r
-}\r
-\r
-function setCookie(c_name, value, exdays)\r
-{\r
-       var exdate=new Date();\r
-       exdate.setDate(exdate.getDate() + exdays);\r
-       var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());\r
-       document.cookie=c_name + "=" + c_value;\r
-}\r
-\r
-function del_cookie(c_name)\r
-{\r
-    document.cookie = c_name + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';\r
-}\r
-\r
-function updateCookie(user, pwd, repo, branch){\r
-       if(checkCookie()){\r
-               branchName = branch;\r
-               setCookie("logginNitdoc", base64.encode(user+':'+pwd+':'+repo+':'+branch), 1);\r
-       }\r
-}\r
-\r
-function getCookie(c_name)\r
-{\r
-       var c_value = document.cookie;\r
-       var c_start = c_value.indexOf(" " + c_name + "=");\r
-       if (c_start == -1) { c_start = c_value.indexOf(c_name + "="); }\r
-       if (c_start == -1) { c_value = null; }\r
-       else\r
-       {\r
-               c_start = c_value.indexOf("=", c_start) + 1;\r
-               var c_end = c_value.indexOf(";", c_start);\r
-               if (c_end == -1) { c_end = c_value.length; }\r
-               c_value = unescape(c_value.substring(c_start,c_end));\r
-       }\r
-       return c_value;\r
-}\r
-\r
-function getUserPass(c_name){\r
-       var cookie = base64.decode(getCookie(c_name));\r
-       return base64.encode(cookie.split(':')[0] + ':' + cookie.split(':')[1]);\r
-}\r
-\r
-function checkCookie()\r
-{\r
-       var cookie=getCookie("logginNitdoc");\r
-       if (cookie!=null && cookie!="")\r
-       {\r
-               cookie = base64.decode(cookie);\r
-               userName = cookie.split(':')[0];\r
-               password = cookie.split(':')[1];\r
-               githubRepo = cookie.split(':')[2];              \r
-               branchName = cookie.split(':')[3];\r
-               return true;\r
-       }\r
-       else { return false; }\r
-}\r
-\r
-function getLastCommit() \r
-{   \r
-       var urlHead = '';\r
-       if(sessionStarted){ urlHead = "https://api.github.com/repos/"+userName+"/"+githubRepo+"/git/refs/heads/"+branchName;}\r
-       else{ \r
-               // TODO: get url of the original repo.\r
-               return;\r
-       }\r
-\r
-    $.ajax({\r
-        beforeSend: function (xhr) { \r
-            if (userB64 != ""){ xhr.setRequestHeader ("Authorization", userB64); }\r
-        },\r
-        type: "GET",\r
-        url: urlHead,\r
-        dataType:"json",\r
-        async: false,\r
-        success: function(success)\r
-        {              \r
-            shaLastCommit = success.object.sha;            \r
-        }\r
-    });\r
-}\r
-\r
-function getBaseTree()\r
-{      \r
-    $.ajax({ \r
-        beforeSend: function (xhr) { \r
-            if (userB64 != ""){ xhr.setRequestHeader ("Authorization", userB64); }\r
-        },\r
-        type: "GET",\r
-        url: "https://api.github.com/repos/"+userName+"/"+githubRepo+"/git/commits/" + shaLastCommit,\r
-        dataType:"json",\r
-        async: false,\r
-        success: function(success)\r
-        {   \r
-            shaBaseTree = success.tree.sha;\r
-            if (state){ setBlob(); }\r
-            else{ return; }            \r
-        },\r
-        error: function(){\r
-               return;\r
-        }\r
-    });    \r
-}\r
-\r
-function setNewTree()\r
-{\r
-    $.ajax({ \r
-        beforeSend: function (xhr) { xhr.setRequestHeader ("Authorization", userB64); },\r
-        type: "POST",\r
-        url: "https://api.github.com/repos/"+userName+"/"+githubRepo+"/git/trees", \r
-        async: false,\r
-        dataType:'json',\r
-        data:'{ "base_tree" : "'+shaBaseTree+'", '+\r
-                '"tree":[{ '+\r
-                    '"path":"'+ pathFile +'",'+\r
-                    '"mode":"100644",'+\r
-                    '"type":"blob",'+\r
-                    '"sha": "'+ shaBlob +'"'+\r
-                '}] '+\r
-            '}',        \r
-        success: function(success)\r
-        { // si l'appel a bien fonctionné\r
-            shaNewTree = success.sha;\r
-            setNewCommit();            \r
-        },\r
-        error: function(){\r
-               return;\r
-        }\r
-    });\r
-}\r
-\r
-function setNewCommit()\r
-{\r
-    addSignedOff();\r
-    $.ajax({ \r
-        beforeSend: function (xhr) { xhr.setRequestHeader ("Authorization", userB64); },\r
-        type: "POST",\r
-        url: "https://api.github.com/repos/"+userName+"/"+githubRepo+"/git/commits", \r
-        async: false,\r
-        dataType:'json',\r
-        data:'{ "message" : "'+ commitMessage +'", '+\r
-                '"parents" :"'+shaLastCommit+'",'+ \r
-                '"tree": "'+shaNewTree+'"'+\r
-             '}',        \r
-        success: function(success)\r
-        {\r
-            shaNewCommit = success.sha;\r
-            commit();          \r
-        },\r
-        error: function(){\r
-               return;\r
-        }\r
-    });\r
-}\r
-\r
-//Create a commit\r
-function commit()\r
-{\r
-    $.ajax({ \r
-        beforeSend: function (xhr) { xhr.setRequestHeader ("Authorization", userB64); },\r
-        type: "POST",\r
-        url: "https://api.github.com/repos/"+userName+"/"+githubRepo+"/git/refs/heads/"+branchName, \r
-        dataType:'json',\r
-        data:'{ "sha" : "'+shaNewCommit+'", '+\r
-                '"force" :"true"'+\r
-             '}',\r
-        success: function(success) { displayMessage('Commit created successfully', 40, 40); },\r
-        error:function(error){ displayMessage('Error ' + error.object.message, 40, 40); }\r
-    });\r
-}\r
-\r
-// Create a blob\r
-function setBlob()\r
-{\r
-    $.ajax({\r
-        beforeSend: function (xhr) { xhr.setRequestHeader ("Authorization",  userB64); },\r
-        type: "POST",         \r
-        url: "https://api.github.com/repos/"+userName+"/"+githubRepo+"/git/blobs",         \r
-        async: false,\r
-        dataType:'json',\r
-        data:'{ "content" : "'+text.replace(/\r?\n/g, '\\n').replace(/\t/g, '\\t').replace(/\"/g,'\\"')+'", '+\r
-                '"encoding" :"utf-8"'+\r
-            '}',\r
-        success: function(success)\r
-        {            \r
-            shaBlob = success.sha;\r
-            setNewTree();                  \r
-        },\r
-        error:function(error){ \r
-               displayMessage('Error : Problem parsing JSON', 40, 40); \r
-               return;\r
-       }\r
-    });\r
-}\r
-\r
-// Display file content\r
-function getFileContent(urlFile, newComment)\r
-{\r
-    $.ajax({\r
-        beforeSend: function (xhr) { \r
-            xhr.setRequestHeader ("Accept",  "application/vnd.github-blob.raw");\r
-            if (userB64 != ""){ xhr.setRequestHeader ("Authorization", userB64); }\r
-        },\r
-        type: "GET", \r
-        url: urlFile, \r
-        async:false,\r
-        success: function(success)\r
-        {\r
-            state = true;\r
-            replaceComment(newComment, success);            \r
-        }\r
-    });\r
-}\r
-\r
-function replaceComment(newComment, fileContent){\r
-       var arrayNew = newComment.split('\n');  \r
-       var lNew = arrayNew.length;\r
-       text = "";\r
-       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
-                               else{\r
-                                       if(arrayNew[j] == ""){ text += "#"+"\n"; }\r
-                                       else{ text += "# " + arrayNew[j] + "\n"; }\r
-                               }\r
-                       }\r
-               }\r
-               else if(i < commentLineStart || i >= commentLineEnd){\r
-                       if(i == lines.length-1){ text += lines[i]; }\r
-                       else{ text += lines[i] + "\n"; }\r
-               }\r
-       }\r
-       if(addNewComment){\r
-               addNewComment = false;\r
-       }\r
-}\r
-\r
-function getCommentLastCommit(path, origin){\r
-       var urlRaw;\r
-       var bkBranch = '';\r
-       if(origin){// We want to get the original file\r
-               bkBranch = branchName;\r
-               branchName = "master";\r
-       }\r
-       getLastCommit();\r
-       if(shaLastCommit != ""){\r
-               if (checkCookie()) {\r
-                       urlRaw="https://rawgithub.com/"+ userName +"/"+ githubRepo +"/" + shaLastCommit + "/" + path;\r
-                       $.ajax({  \r
-                           type: "GET",\r
-                           url: urlRaw,\r
-                           async: false,\r
-                           success: function(success)\r
-                           {\r
-                                   if(origin){ originalFileContent = success; }\r
-                                   else{ currentfileContent = success; }\r
-                           }\r
-                       });\r
-               }\r
-       }\r
-       if(origin){ branchName = bkBranch; }\r
-}\r
-\r
-function displayMessage(msg, widthDiv, margModal){\r
-       spinner.stop();\r
-       $('#modal').hide();\r
-       $('#btnCancelBranch').hide();   \r
-       $('#modalQuestion').show().prepend('<a class="close"><img src="resources/icons/close.png" class="btnCloseQuestion" title="Close" alt="Close" /></a>');\r
-       $('#txtQuestion').text(msg);\r
-       $('#btnCreateBranch').text("Ok");\r
-       var xModal = $('#modalQuestion').css('width').split('px')[0];\r
-       var yModal = $('#modalQuestion').css('height').split('px')[0];\r
-       var x = $(document).width/2 - xModal/2;\r
-       var y = $(document).height/2 - yModal/2;\r
-       var xBtnBranch = $('#btnCreateBranch').css('width').split('px')[0];\r
-       $('#modalQuestion').css({'left' : x, 'top' : y});\r
-       $('#modalQuestion').show();\r
-       $('#btnCreateBranch').css('margin-left', xModal/2 - xBtnBranch);\r
-       $('body').append('<div id="fade"></div>');\r
-       $('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();\r
-}\r
-\r
-function displaySpinner(){\r
-       spinner.spin(targetSpinner);\r
-       $("#waitCommit").show();\r
-}\r
-\r
-// Check if the repo already exist\r
-function isRepoExisting(){\r
-       $.ajax({\r
-        beforeSend: function (xhr) { \r
-            if (userB64 != "") { xhr.setRequestHeader ("Authorization", userB64); }\r
-        },\r
-        type: "GET", \r
-        url: "https://api.github.com/repos/"+userName+"/"+githubRepo, \r
-        async:false,\r
-        dataType:'json',\r
-        success: function(){ repoExist = true; },\r
-        error: function()\r
-        {\r
-               displayMessage('Repo not found !', 35, 45);\r
-               repoExist = false;\r
-        }\r
-    });\r
-}\r
-\r
-// Check if the branch already exist\r
-function isBranchExisting(){\r
-       $.ajax({\r
-               beforeSend: function (xhr) {\r
-                       if (userB64 != "") { xhr.setRequestHeader ("Authorization", userB64); }\r
-               },\r
-               type: "GET",\r
-               url: "https://api.github.com/repos/"+userName+"/"+githubRepo+"/git/refs/heads/"+branchName,\r
-               async:false,\r
-               dataType:'json',\r
-               success: function(){ branchExist = true; },\r
-               error: function()\r
-               {\r
-                       branchExist = false;\r
-                       editComment -= 1;\r
-                       $('#modal').hide();\r
-                       $('#txtQuestion').text("Are you sure you want to create that branch ?");\r
-                       $('#btnCancelBranch').show();\r
-                       $('#btnCreateBranch').text("Yes");\r
-                       $('#modalQuestion').show();\r
-                       $('#modalQuestion').show().prepend('<a class="close"><img src="resources/icons/close.png" class="btnCloseQuestion" title="Close" alt="Close" /></a>');\r
-                       $('body').append('<div id="fade"></div>');\r
-                       $('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();\r
-               }\r
-       });\r
-}\r
-\r
-function getMasterSha() \r
-{\r
-    $.ajax({\r
-        beforeSend: function (xhr) { \r
-            if (userB64 != ""){ xhr.setRequestHeader ("Authorization", userB64); }\r
-        },\r
-        type: "GET",\r
-        url: "https://api.github.com/repos/"+userName+"/"+githubRepo+"/git/refs/heads/master",\r
-        dataType:"json",\r
-        async: false,\r
-        success: function(success) { shaMaster = success.object.sha; }\r
-    });\r
-}\r
-\r
-function createBranch(){\r
-\r
-       getMasterSha();\r
-\r
-       $.ajax({ \r
-        beforeSend: function (xhr) { xhr.setRequestHeader ("Authorization", userB64); },\r
-        type: "POST",\r
-        url: "https://api.github.com/repos/"+userName+"/"+githubRepo+"/git/refs", \r
-        data:'{ "ref" : "refs/heads/'+branchName+'",'+\r
-                       '"sha" : "'+shaMaster+'"'+\r
-            '}',\r
-        success: function(){ return; },\r
-        error: function(){\r
-               editComment -= 1;\r
-               displayMessage('Impossible to create the new branch : ' + branchName, 40, 40);\r
-        }\r
-    });\r
-}\r
-\r
-$.fn.spin = function(opts) {\r
-  this.each(function() {\r
-    var $this = $(this),\r
-        data = $this.data();\r
-\r
-    if (data.spinner) {\r
-      data.spinner.stop();\r
-      delete data.spinner;\r
-    }\r
-    if (opts !== false) {\r
-      data.spinner = new Spinner($.extend({color: $this.css('color')}, opts)).spin(this);\r
-    }\r
-  });\r
-  return this;\r
-};\r
-\r
-function reloadComment(){\r
-       var path = $('pre[class=text_label]').attr('tag');\r
-       $.when(getCommentLastCommit(path, false)).done(function(){\r
-               if(sessionStarted){ getCommentLastCommit(path, true); }\r
-               $('pre[class=text_label]').each(function(){ getCommentOfFunction($(this)); });\r
-       });\r
-}\r
-\r
-function getCommentOfFunction(element){\r
-       var textC = ""; \r
-       var numL = element.attr("title");\r
-       if(numL != null){                                       \r
-               commentLineStart = numL-1;              \r
-               commentLineEnd = element.attr('name').split(numL)[1].split('-')[1]-1;           \r
-               var lines = currentfileContent.split("\n");\r
-               for (var i = 0; i < lines.length; i++) {\r
-                       if(i >= commentLineStart-1 && i <= commentLineEnd+1){\r
-                               if (lines[i].substr(1,1) == "#"){ textC += lines[i].substr(3,lines[i].length) + "\n";}\r
-                               else if(lines[i].substr(0,1) == '#'){ textC += lines[i].substr(2,lines[i].length) + "\n"; }\r
-               }\r
-           }\r
-           if(textC != element.text){element.text(textC);}\r
-           if (textC != "" && editComment > 0){\r
-               var originContent = originalFileContent.split("\n");\r
-               var origin = '';\r
-               var lblDiff = element.parent().prev().children('#lblDiffCommit');\r
-               var preSave = element.parent().children('#preSave');\r
-               for (var i = 0; i < originContent.length; i++) {\r
-                       if(i >= commentLineStart-1 && i <= commentLineEnd+1){\r
-                               if (originContent[i].substr(1,1) == "#"){ origin += originContent[i].substr(3,originContent[i].length) + "\n";}\r
-                               else if(originContent[i].substr(0,1) == '#'){ origin += originContent[i].substr(2,originContent[i].length) + "\n"; }\r
-                       }\r
-               }\r
-               if(textC != origin && numL == numComment){\r
-                       // The comment is different compare to the original\r
-                       if(showcomment == false){ lblDiff.text("Show original comment"); }\r
-                       preSave.text(origin);\r
-               }\r
-               else if (numL == numComment){ lblDiff.text(""); }\r
-           }\r
-       }\r
-}\r
-\r
-// Get list of branches\r
-function getListBranches()\r
-{\r
-       cleanListBranches();\r
-    $.ajax({\r
-        beforeSend: function (xhr) { \r
-            if ($("#login").val() != ""){ xhr.setRequestHeader ("Authorization", userB64); }\r
-        },\r
-        type: "GET", \r
-        url: "https://api.github.com/repos/"+userName+"/"+githubRepo+"/branches", \r
-        async:false,\r
-        dataType:'json',\r
-        success: function(success)\r
-        {   \r
-            for(var branch in success) { \r
-               var selected = '';\r
-               if(branchName == success[branch].name){\r
-                       selected = 'selected';\r
-               }\r
-               $('#dropBranches').append('<option value="" '+ selected +'>' + success[branch].name + '</option>');\r
-            }\r
-        }\r
-    });\r
-}\r
-\r
-// Delete all option in the list\r
-function cleanListBranches(){\r
-       $('#dropBranches').children("option").remove();\r
-}\r
-\r
-function closeAllCommentInEdtiting(){\r
-       $('a[id=cancelBtn]').each(function(){\r
-               closeEditing($(this));\r
-       });\r
-}\r
-\r
-function closeEditing(tag){\r
-       if(editComment > 0){ editComment -= 1; }\r
-       // Hide itself\r
-       tag.hide();\r
-       // Hide commitBtn\r
-       tag.next().hide();\r
-       // Hide Textarea\r
-       tag.prev().hide();\r
-       // Show comment\r
-       tag.prev().prev().show();\r
-}\r
-\r
-function checkSignIn(){\r
-       var response = false;\r
-       $.ajax({\r
-        beforeSend: function (xhr) {\r
-            if ($("#login").val() != ""){ xhr.setRequestHeader ("Authorization", userB64); }\r
-        },\r
-        type: "GET",\r
-        url: "https://api.github.com/repos/"+userName+"/"+githubRepo,\r
-        async:false,\r
-        dataType:'json',\r
-        success: function(success)\r
-        {\r
-               getUserInfo();\r
-               response = true;\r
-               displayMessage('You are now logged in');\r
-        },\r
-        error: function()\r
-        {\r
-               displayMessage('Error : Wrong username or password');\r
-               response = false;\r
-        }\r
-    });\r
-    return response;\r
-}\r
-\r
-function getUserInfo(){\r
-       $.ajax({\r
-        beforeSend: function (xhr) {\r
-            if ($("#login").val() != ""){ xhr.setRequestHeader ("Authorization", userB64); }\r
-        },\r
-        type: "GET",\r
-        url: "https://api.github.com/user/emails",\r
-        async:false,\r
-        dataType:'json',\r
-        success: function(success)\r
-        {        \r
-               userEmail = success;\r
-        }\r
-    });\r
-}\r
-\r
-function getSignedOff(){\r
-       $.ajax({\r
-        beforeSend: function (xhr) {\r
-            if ($("#login").val() != ""){ xhr.setRequestHeader ("Authorization", userB64); }\r
-        },\r
-        type: "GET",\r
-        url: "https://api.github.com/users/"+userName,\r
-        async:false,\r
-        dataType:'json',\r
-        success: function(success)\r
-        {\r
-               signedOff = success.name;\r
-        }\r
-    });\r
-}\r
-\r
-function addSignedOff(){\r
-       $.when(getUserInfo()).done(function(){\r
-               $.when(getSignedOff()).done(function(){\r
-                       $('#commitMessage').val($('#commitMessage').val() + "\n\nSigned-off-by: "+signedOff+" <"+userEmail+">");\r
-               });\r
-       });\r
-       resizeTextarea($('#commitMessage'));\r
-}\r
-\r
-function removeSignedOff(){\r
-       $('#commitMessage').val(commitMessage); \r
-       resizeTextarea($('#commitMessage'));\r
-}\r
-\r
-function resizeTextarea(element){\r
-       var nLines = element.val().split('\n').length + 1;\r
-       element.attr('rows', nLines);\r
-}\r
-\r
-function showComment(element){\r
-       // Display the original comment\r
-       if (showcomment == true){               \r
-               showcomment = false;\r
-               element.text("Show original comment");\r
-       }\r
-       else{\r
-               // Show the comment updated in user's repo\r
-               showcomment = true;\r
-               element.text("Comment changed in "+githubRepo+" / "+branchName);\r
-       }\r
-       var parent = element.parent().next(".description");             \r
-       var textarea = parent.children('#fileContent');\r
-       var text = textarea.val();      \r
-       var preSave = parent.children('#preSave');      \r
-       textarea.val(preSave.text());\r
-       preSave.text(text);\r
-       // Resize edit box\r
-       textarea.height(textarea.prop("scrollHeight"));\r
-       resizeTextarea(textarea);\r
-}\r
-\r
-/* GitHub login box management */\r
-\r
-function createLoginBox() {\r
-       $("nav.main ul").append(\r
-               "<li id='liGitHub'>" +\r
-               "  <a class='btn' id='logGitHub'>" +\r
-               "    <img id='imgGitHub' src='resources/icons/github-icon.png' alt='GitHub'/>" +\r
-               "  </a>" +\r
-               "  <div class='popover bottom' style='display: none;'>" +\r
-               "    <div class='arrow'>&nbsp;</div>" +\r
-               "      <div class='githubTitle'>" +\r
-               "        <h3>Github Sign In</h3>" +\r
-               "      </div>" +\r
-               "      <div>" +\r
-               "        <label id='lbloginGit'>Username</label>" +\r
-               "        <input id='loginGit' name='login' type='text'/>" +\r
-               "        <label id='logginMessage'>Hello " +\r
-               "          <a id='githubAccount'><strong id='nickName'></strong></a>" +\r
-               "        </label>" +\r
-               "      </div>" +\r
-               "      <div>" +\r
-               "        <label id='lbpasswordGit'>Password</label>" +\r
-               "        <input id='passwordGit' name='password' type='password'/>" +\r
-               "        <div id='listBranches'>" +\r
-               "          <label id='lbBranches'>Branch</label>" +\r
-               "          <select class='dropdown' id='dropBranches' name='dropBranches' tabindex='1'></select>" +\r
-               "        </div>" +\r
-               "      </div>" +\r
-               "      <div>" +\r
-               "        <label id='lbrepositoryGit'>Repository</label>" +\r
-               "        <input id='repositoryGit' name='repository' type='text'/>" +\r
-               "      </div>" +\r
-               "      <div>" +\r
-               "        <label id='lbbranchGit'>Branch</label>" +\r
-               "        <input id='branchGit' name='branch' type='text'/>" +\r
-               "      </div>" +\r
-               "      <div>" +\r
-               "        <a id='signIn'>Sign In</a>" +\r
-               "      </div>" +\r
-               "    </div>" +\r
-               "  </div>" +\r
-               "</li>"\r
-       );\r
-}\r
-\r
-function toggleLoginBox(){\r
-       if ($('.popover').is(':hidden')) {\r
-               if(sessionStarted){ getListBranches(); }\r
-               $('.popover').show();\r
-       } else {\r
-               $('.popover').hide();\r
-       }\r
-       updateDisplaying();\r
-}\r