From 941cfdfefec258fe4635247a4fff0ab8321e269a Mon Sep 17 00:00:00 2001 From: Stefan Lage Date: Thu, 23 May 2013 17:09:07 -0400 Subject: [PATCH] nitdoc: Added a function to display the edit mode of a comment This function load comment content in a "texterea" and display it with two buttons "commit" and "cancel". Actually cancel can hide/disable the edit mode. signed-off by: Stefan Lage --- share/nitdoc/scripts/js-facilities.js | 49 +++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/share/nitdoc/scripts/js-facilities.js b/share/nitdoc/scripts/js-facilities.js index 0041b54..b3e5d9d 100644 --- a/share/nitdoc/scripts/js-facilities.js +++ b/share/nitdoc/scripts/js-facilities.js @@ -1,6 +1,7 @@ // User var userB64 = null; var sessionStarted = false; +var editComment = 0; /* * JQuery Case Insensitive :icontains selector @@ -397,6 +398,54 @@ $(document).ready(function() { } displayLogginModal(); }); + + // Open edit file + $('pre[class=text_label]').click(function(){ + // the customer is loggued ? + if(!sessionStarted || userName == ""){ + // No => nothing happen + return; + } + else{ + var arrayNew = $(this).text().split('\n'); + var lNew = arrayNew.length - 1; + var adapt = ""; + + for (var i = 0; i < lNew; i++) { + adapt += arrayNew[i]; + if(i < lNew-1){ adapt += "\n"; } + } + 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(); + // Add text in edit box + if($(this).next().val() == ""){ $(this).next().val(adapt); } + // Resize edit box + $(this).next().height($(this).next().prop("scrollHeight")); + // Select it + $(this).next().select(); + preElement = $(this); + } + }); + + $('a[id=cancelBtn]').click(function(){ + if(editComment > 0){ editComment -= 1; } + // Hide itself + $(this).hide(); + // Hide commitBtn + $(this).next().hide(); + // Hide Textarea + $(this).prev().hide(); + // Show comment + $(this).prev().prev().show(); + }); + }); /* Parse current URL and return anchor name */ -- 1.7.9.5