HTMLviews: various cleanups

This commit is contained in:
Stephen Celis
2008-10-21 15:16:49 +02:00
committed by Pieter de Bie
parent 43bb12317c
commit 66f490ff17
4 changed files with 16 additions and 25 deletions
-1
View File
@@ -6,7 +6,6 @@
*/
function $(element) {
Controller.log_("Calling _");
return document.getElementById(element);
}
+1 -2
View File
@@ -68,8 +68,7 @@ var gistie = function() {
// TODO: Replace true with private preference
token = Controller.getConfig_("github.token");
login = Controller.getConfig_("github.user");
if (token && login)
{
if (token && login) {
parameters.login = login;
parameters.token = token;
} else {
+9 -7
View File
@@ -9,24 +9,26 @@
<script>
var showFileChanges = function(file, cached) {
// New file?
var diff = $("diff");
if (file.status == 0)
{
var contents = file.unstagedChanges();
if (contents)
$("diff").innerHTML = contents.escapeHTML();
diff.innerHTML = contents.escapeHTML();
else
$("diff").innerHTML = "Could not display changes";
diff.innerHTML = "Could not display changes";
$("diff").style.display = '';
diff.style.display= '';
$('title').innerHTML = "New file: " + file.path;
} else {
$("diff").style.display = 'none';
diff.style.display = 'none';
if (cached)
$("diff").innerHTML = file.cachedChangesAmend_(Controller.amend()).escapeHTML();
diff.innerHTML = file.cachedChangesAmend_(Controller.amend()).escapeHTML();
else
$("diff").innerHTML = file.unstagedChanges().escapeHTML();
diff.innerHTML = file.unstagedChanges().escapeHTML();
highlightDiffs();
$("diff").style.display = '';
diff.style.display = '';
$("title").innerHTML = "Changes for " + file.path;
}
}
+6 -15
View File
@@ -1,9 +1,7 @@
// If we run from a Safari instance, we don't
// have a Controller object. Instead, we fake it by
// using the console
if (typeof Controller == 'undefined')
{
if (typeof Controller == 'undefined') {
Controller = console;
Controller.log_ = console.log;
}
@@ -42,23 +40,19 @@ var highlightDiffs = function() {
continue;
}
if (firstChar == "+") {
// Highlight trailing whitespace
if (m = l.match(/\s+$/))
l = l.replace(/\s+$/, "<span class='whitespace'>" + m + "</span>");
l = l.replace(/\s+$/, "<span class='whitespace'>" + m + "</span>");
line1 += "\n";
line2 += ++hunk_start_line_2 + "\n";
diffContent += "<div class='addline'>" + l + "</div>";
}
else if (firstChar == "-") {
} else if (firstChar == "-") {
line1 += ++hunk_start_line_1 + "\n";
line2 += "\n";
diffContent += "<div class='delline'>" + l + "</div>";
}
else if (firstChar == "@")
{
} else if (firstChar == "@") {
header = false;
if (m = l.match(/@@ \-([0-9]+),\d+ \+(\d+),\d+ @@/))
{
@@ -68,22 +62,19 @@ var highlightDiffs = function() {
line1 += "...\n";
line2 += "...\n";
diffContent += "<div class='hunkheader'>" + l + "</div>";
}
else if (firstChar == " ")
{
} else if (firstChar == " ") {
line1 += ++hunk_start_line_1 + "\n";
line2 += ++hunk_start_line_2 + "\n";
diffContent += l + "\n";
}
}
// This takes about 7ms
diff.innerHTML = "<table class='diff'><tr><td class='lineno'l><pre>" + line1 + "</pre></td>" +
"<td class='lineno'l><pre>" + line2 + "</pre></td>" +
"<td width='100%'><pre width='100%'>" + diffContent + "</pre></td></tr></table>";
}
// TODO: Replace this with a performance pref call
if (false)
Controller.log_("Total time:" + (new Date().getTime() - start));