[gitg/wip/techlivezh/diff-view-clean-up: 8/12] Reduce duplicate stage button code



commit 673d2aee4065ae30873fb6715a2b30582790b3de
Author: Techlive Zheng <techlivezheng gmail com>
Date:   Thu Dec 19 09:35:32 2013 +0800

    Reduce duplicate stage button code

 libgitg/resources/diff-view-html-builder.js |   56 ++++++++++----------------
 1 files changed, 22 insertions(+), 34 deletions(-)
---
diff --git a/libgitg/resources/diff-view-html-builder.js b/libgitg/resources/diff-view-html-builder.js
index 04a845b..2405801 100644
--- a/libgitg/resources/diff-view-html-builder.js
+++ b/libgitg/resources/diff-view-html-builder.js
@@ -27,23 +27,7 @@ function diff_file(file, lnstate, data)
 
                var hunk_stats = '<span class="hunk_stats">@@ -' + h.range.old.start + ',' + 
h.range.old.lines + ' +' + h.range.new.start + ',' + h.range.new.lines + ' @@</span>';
 
-               if (data.settings.staged || data.settings.unstaged)
-               {
-                       var cls;
-
-                       if (data.settings.staged)
-                       {
-                               cls = 'unstage';
-                               nm = data.settings.strings.unstage;
-                       }
-                       else
-                       {
-                               cls = 'stage';
-                               nm = data.settings.strings.stage;
-                       }
-
-                       hunk_stats = '<span class="' + cls + '">' + nm + '</span>' + hunk_stats;
-               }
+               hunk_stats = lnstate.stagebutton + hunk_stats;
 
                file_body += '<tr class="hunk_header">\
                        <td class="gutter old">' + lnstate.gutterdots + '</td> \
@@ -143,23 +127,7 @@ function diff_file(file, lnstate, data)
 
        var file_stats = '<span class="file_stats"><span class="number">' + (added + removed)  + 
'</span><span class="bar"><span class="added" style="width: ' + addedp + '%;"></span><span class="removed" 
style="width: ' + removedp + '%;"></span></span></span>';
 
-       if (data.settings.staged || data.settings.unstaged)
-       {
-               var cls;
-
-               if (data.settings.staged)
-               {
-                       cls = 'unstage';
-                       nm = data.settings.strings.unstage;
-               }
-               else
-               {
-                       cls = 'stage';
-                       nm = data.settings.strings.stage;
-               }
-
-               file_stats += '<span class="' + cls + '">' + nm + '</span>';
-       }
+       file_stats = lnstate.stagebutton + file_stats;
 
        /**
         * run template
@@ -207,9 +175,29 @@ function diff_files(files, lines, maxlines, data)
                nexttick: 0,
                tickfreq: 0.01,
                gutterdots: new Array(maxlines.toString().length + 1).join('.'),
+               stagebutton: '',
                replacements: replacements,
        };
 
+       if (data.settings.staged || data.settings.unstaged)
+       {
+               var cls;
+               var nm;
+
+               if (data.settings.staged)
+               {
+                       cls = 'unstage';
+                       nm = data.settings.strings.unstage;
+               }
+               else
+               {
+                       cls = 'stage';
+                       nm = data.settings.strings.stage;
+               }
+
+               lnstate.stagebutton = '<span class="' + cls + '">' + nm + '</span>';
+       }
+
        var f = '';
 
        for (var i = 0; i < files.length; ++i)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]