Fix bug 33: Polish "Expand/Hide all changesets" button behaviour
authorGraeme McCutcheon <graememcc_firefox@graeme-online.co.uk>
Sun, 13 Jan 2013 18:04:05 +0000
changeset 1198 97e1a705ae77dedba0a8eec0e4d8ad7b911e9f2f
parent 1197 f1e6133469b7d9184dfc450fcd809b1177014054
child 1199 ba1709bb98888a3c34fc0557ecfccdbaaeac0456
push id659
push useremorley@mozilla.com
push dateTue, 18 Jun 2013 13:49:17 +0000
bugs33
Fix bug 33: Polish "Expand/Hide all changesets" button behaviour
mcmerge/js/Viewer.js
--- a/mcmerge/js/Viewer.js
+++ b/mcmerge/js/Viewer.js
@@ -93,29 +93,43 @@ var Viewer = {
 
 
   onRemoveButtonClick: function viewer_onRemoveButtonClick(index, bug, target) {
     ViewerController.removeBug(index, bug);
   },
 
 
   onExpandButtonClick: function viewer_onExpandButtonClick(target) {
-    $('.commentDiv').toggle();
+    var shouldExpand = $('#expandButton').text() === 'Expand all comments';
+    $('.commentDiv').toggle(shouldExpand);
+    var expandText = shouldExpand ? 'Hide all comments' : 'Expand all comments';
+    $('#expandButton').text(expandText);
   },
 
 
   onSubmitButtonClick: function viewer_onSubmitButtonClick(target) {
     this.step.onSubmit();
   },
 
 
   // Spans
   onViewHideClick: function viewer_onViewHideClick(index, bug, target) {
     var cset = PushData.allPushes[index].cset;
     $('#' + this.getCommentID(cset, bug)).toggle();
+    var shouldExpand = false;
+
+    // Update 'expand all' button text
+    var divs = $('.commentDiv').get();
+    for (var i = 0, l = divs.length; i < l; i++) {
+      var style = divs[i].style.display.toLowerCase();
+      if (style === 'none' || style === '')
+        shouldExpand = true;
+    }
+    var expandText = shouldExpand ? 'Expand all comments' : 'Hide all comments';
+    $('#expandButton').text(expandText);
   },
 
 
   onFileViewHideClick: function viewer_onFileViewHideClick(cset, target) {
     $('#' + this.getFilesID(cset)).toggle();
   },
 
 
@@ -532,17 +546,17 @@ var Viewer = {
     html += '  <button type="button" class="nextButton">' + nextLabel + '</button>';
     html += '</div>'
     return html;
   },
 
 
   makeExpandHTML: function viewer_makeExpandHTML() {
     var html = '<div class="grid-12 divRight" id="expand">';
-    html += '  <button type="button" class="expandButton" id="expandButton">Expand/Hide all comments</button>';
+    html += '  <button type="button" class="expandButton" id="expandButton">Expand all comments</button>';
     html += '</div>';
     return html;
   },
 
 
   makeSubmitHTML: function viewer_makeSubmitHTML() {
     var html = '<div class="grid-12 divRight" id="submit">';
     html += '  <button type="button" class="submitButton" id="submitButton">Submit the changes above</button>';
@@ -628,15 +642,17 @@ var Viewer = {
     if (!onPrevious.fn)
       $('.prevButton').attr('disabled', true);
     this.onNextFn = onNext.fn;
     if (!onNext.fn)
       $('.nextButton').attr('disabled', true);
 
     this.updateSubmitButton();
 
-    if (Viewer.expand)
-      $('.commentDiv').toggle();
+    if (Viewer.expand) {
+      $('.commentDiv').toggle(true);
+      $('#expandButton').text('Hide all comments');
+    }
 
     UI.show('viewerOutput');
     $('html')[0].scrollIntoView();
   }
 }