[gitg/wip/techlivezh/diff-view-clean-up: 1/21] Clean up code a bit
- From: Techlive Zheng <techlivezh src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gitg/wip/techlivezh/diff-view-clean-up: 1/21] Clean up code a bit
- Date: Sat, 21 Dec 2013 16:40:02 +0000 (UTC)
commit 3058160ca8ff3bf9643cdf9040e78dc4292e60a6
Author: Techlive Zheng <techlivezheng gmail com>
Date: Sat Dec 7 23:15:55 2013 +0800
Clean up code a bit
https://bugzilla.gnome.org/show_bug.cgi?id=720886
libgitg/resources/diff-view-html-builder.js | 40 +++++++++++++-------------
libgitg/resources/diff-view.html | 2 +-
libgitg/resources/diff-view.js | 18 +++---------
3 files changed, 25 insertions(+), 35 deletions(-)
---
diff --git a/libgitg/resources/diff-view-html-builder.js b/libgitg/resources/diff-view-html-builder.js
index b58e6c9..c8fe0e6 100644
--- a/libgitg/resources/diff-view-html-builder.js
+++ b/libgitg/resources/diff-view-html-builder.js
@@ -1,3 +1,8 @@
+function log(e)
+{
+ self.postMessage({'log': e});
+}
+
function html_escape(s)
{
return s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
@@ -5,12 +10,11 @@ function html_escape(s)
function diff_file(file, lnstate, data)
{
- tabrepl = '<span class="tab" style="width: ' + data.settings.tab_width + 'ex">\t</span>';
-
- var tablecontent = '';
var added = 0;
var removed = 0;
+ var tablecontent = '';
+
for (var i = 0; i < file.hunks.length; ++i)
{
var h = file.hunks[i];
@@ -47,11 +51,10 @@ function diff_file(file, lnstate, data)
for (var j = 0; j < h.lines.length; ++j)
{
var l = h.lines[j];
- var o = String.fromCharCode(l.type);
var row = '<tr class="';
- switch (o)
+ switch (String.fromCharCode(l.type))
{
case ' ':
row += 'context"> \
@@ -60,7 +63,7 @@ function diff_file(file, lnstate, data)
cold++;
cnew++;
- break;
+ break;
case '+':
row += 'added"> \
<td class="gutter old"></td> \
@@ -68,7 +71,7 @@ function diff_file(file, lnstate, data)
cnew++;
added++;
- break;
+ break;
case '-':
row += 'removed"> \
<td class="gutter old">' + cold + '</td> \
@@ -76,7 +79,7 @@ function diff_file(file, lnstate, data)
cold++;
removed++;
- break;
+ break;
case '=':
case '>':
case '<':
@@ -84,13 +87,16 @@ function diff_file(file, lnstate, data)
<td class="gutter old"></td> \
<td class="gutter new"></td>';
l.content = l.content.substr(1, l.content.length);
- break;
+ break;
default:
row += '">';
- break;
+ break;
}
- row += '<td>' + html_escape(l.content).replace(/\t/g, tabrepl) + '</td>';
+ l.content = html_escape(l.content).replace(/\t/g, '<span class="tab" style="width: '
+ data.settings.tab_width + 'ex">\t</span>');
+
+ row += '<td>' + l.content + '</td>';
+
tablecontent += row;
lnstate.processed++;
@@ -167,11 +173,8 @@ function diff_file(file, lnstate, data)
function diff_files(files, lines, maxlines, data)
{
- var f = '';
-
var repl = [
'FILEPATH',
- 'GUTTER_DOTS',
'TABLE_BODY',
'STATS'
];
@@ -186,13 +189,15 @@ function diff_files(files, lines, maxlines, data)
var lnstate = {
lines: lines,
maxlines: maxlines,
- gutterdots: new Array(maxlines.toString().length + 1).join('.'),
processed: 0,
nexttick: 0,
tickfreq: 0.01,
+ gutterdots: new Array(maxlines.toString().length + 1).join('.'),
replacements: replacements,
};
+ var f = '';
+
for (var i = 0; i < files.length; ++i)
{
f += diff_file(files[i], lnstate, data);
@@ -201,11 +206,6 @@ function diff_files(files, lines, maxlines, data)
return f;
}
-function log(e)
-{
- self.postMessage({'log': e});
-}
-
self.onmessage = function(event) {
var data = event.data;
diff --git a/libgitg/resources/diff-view.html b/libgitg/resources/diff-view.html
index 221f2ae..7c0725c 100644
--- a/libgitg/resources/diff-view.html
+++ b/libgitg/resources/diff-view.html
@@ -19,7 +19,7 @@
<div class="sha1"></div>
</div>
- <!-- Hunk template -->
+ <!-- Diff template -->
<div class="file">
<table class="contents">
<colgroup>
diff --git a/libgitg/resources/diff-view.js b/libgitg/resources/diff-view.js
index 3b37240..1b749ac 100644
--- a/libgitg/resources/diff-view.js
+++ b/libgitg/resources/diff-view.js
@@ -25,7 +25,7 @@ var settings = {
stage: 'stage',
unstage: 'unstage',
loading_diff: 'Loading diff...'
- }
+ },
};
if ('settings' in params)
@@ -104,24 +104,13 @@ function run_template(name, context)
return templates[name].execute(context);
}
-var escapeDiv = document.createElement('div');
-var escapeElement = document.createTextNode('');
-escapeDiv.appendChild(escapeElement);
-
-function html_escape(str)
-{
- escapeElement.data = str;
- return escapeDiv.innerHTML;
-}
-
-
function write_commit(commit)
{
return run_template('commit', commit);
}
-var html_builder_worker = 0;
var html_builder_tick = 0;
+var html_builder_worker = 0;
function update_diff(id, lsettings)
{
@@ -151,7 +140,6 @@ function update_diff(id, lsettings)
workeruri += '?t' + t;
}
- html_builder_worker = new Worker(workeruri);
html_builder_tick = 0;
html_builder_progress_timeout = setTimeout(function (){
@@ -166,6 +154,8 @@ function update_diff(id, lsettings)
html_builder_progress_timeout = 0;
}, 200);
+ html_builder_worker = new Worker(workeruri);
+
html_builder_worker.onmessage = function (event) {
if (event.data.log)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]