[gitg/wip/techlivezh/diff-view-clean-up: 26/33] 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: 26/33] Clean up code a bit
- Date: Mon, 23 Dec 2013 17:57:40 +0000 (UTC)
commit ab843d625a4c1c4259fe32859bf4cc3b74a53c43
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 | 35 +++++++++++++--------------
libgitg/resources/diff-view.js | 16 ++----------
2 files changed, 20 insertions(+), 31 deletions(-)
---
diff --git a/libgitg/resources/diff-view-html-builder.js b/libgitg/resources/diff-view-html-builder.js
index 3698326..4ccba87 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,8 +10,6 @@ function html_escape(s)
function diff_file(file, lnstate, data)
{
- tabrepl = '<span class="tab" style="width: ' + data.settings.tab_width + 'ex">\t</span>';
-
var added = 0;
var removed = 0;
@@ -32,11 +35,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"> \
@@ -45,7 +47,7 @@ function diff_file(file, lnstate, data)
cold++;
cnew++;
- break;
+ break;
case '+':
row += 'added"> \
<td class="gutter old"></td> \
@@ -53,7 +55,7 @@ function diff_file(file, lnstate, data)
cnew++;
added++;
- break;
+ break;
case '-':
row += 'removed"> \
<td class="gutter old">' + cold + '</td> \
@@ -61,7 +63,7 @@ function diff_file(file, lnstate, data)
cold++;
removed++;
- break;
+ break;
case '=':
case '>':
case '<':
@@ -69,13 +71,15 @@ 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 class="code">' + 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 class="code">' + l.content + '</td>';
row += '</tr>';
@@ -139,8 +143,6 @@ function diff_file(file, lnstate, data)
function diff_files(files, lines, maxlines, data)
{
- var f = '';
-
var repl = [
'FILE_PATH',
'FILE_BODY',
@@ -157,10 +159,10 @@ 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('.'),
stagebutton: '',
replacements: replacements,
};
@@ -184,6 +186,8 @@ function diff_files(files, lines, maxlines, data)
lnstate.stagebutton = '<span class="' + cls + '">' + nm + '</span>';
}
+ var f = '';
+
for (var i = 0; i < files.length; ++i)
{
f += diff_file(files[i], lnstate, data);
@@ -192,11 +196,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.js b/libgitg/resources/diff-view.js
index d77b75a..6ded617 100644
--- a/libgitg/resources/diff-view.js
+++ b/libgitg/resources/diff-view.js
@@ -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 (){
@@ -170,6 +158,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]