mercurial/templates/static/mercurial.js
author Jens Bäckman <jens.backman@gmail.com>
Wed, 25 Jan 2012 09:33:48 +0100
branchstable
changeset 15979 2be0253f6249
parent 14881 2e54387976d4
child 16129 5e50982c633c
permissions -rw-r--r--
i18n-sv: translating strings for add, annotate, debuginstall
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14046
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
     1
// mercurial.js - JavaScript utility functions
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
     2
//
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
     3
// Rendering of branch DAGs on the client side
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
     4
// Display of elapsed time
14571
17c0cb1045e5 paper, coal: display diffstat on the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents: 14046
diff changeset
     5
// Show or hide diffstat
14046
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
     6
//
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
     7
// Copyright 2008 Dirkjan Ochtman <dirkjan AT ochtman DOT nl>
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
     8
// Copyright 2006 Alexander Schremmer <alex AT alexanderweb DOT de>
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
     9
//
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    10
// derived from code written by Scott James Remnant <scott@ubuntu.com>
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    11
// Copyright 2005 Canonical Ltd.
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    12
//
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    13
// This software may be used and distributed according to the terms
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    14
// of the GNU General Public License, incorporated herein by reference.
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    15
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    16
var colors = [
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    17
	[ 1.0, 0.0, 0.0 ],
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    18
	[ 1.0, 1.0, 0.0 ],
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    19
	[ 0.0, 1.0, 0.0 ],
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    20
	[ 0.0, 1.0, 1.0 ],
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    21
	[ 0.0, 0.0, 1.0 ],
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    22
	[ 1.0, 0.0, 1.0 ]
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    23
];
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    24
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    25
function Graph() {
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    26
	
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    27
	this.canvas = document.getElementById('graph');
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    28
	if (navigator.userAgent.indexOf('MSIE') >= 0) this.canvas = window.G_vmlCanvasManager.initElement(this.canvas);
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    29
	this.ctx = this.canvas.getContext('2d');
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    30
	this.ctx.strokeStyle = 'rgb(0, 0, 0)';
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    31
	this.ctx.fillStyle = 'rgb(0, 0, 0)';
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    32
	this.cur = [0, 0];
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    33
	this.line_width = 3;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    34
	this.bg = [0, 4];
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    35
	this.cell = [2, 0];
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    36
	this.columns = 0;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    37
	this.revlink = '';
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    38
	
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    39
	this.scale = function(height) {
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    40
		this.bg_height = height;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    41
		this.box_size = Math.floor(this.bg_height / 1.2);
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    42
		this.cell_height = this.box_size;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    43
	}
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    44
	
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    45
	function colorPart(num) {
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    46
		num *= 255
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    47
		num = num < 0 ? 0 : num;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    48
		num = num > 255 ? 255 : num;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    49
		var digits = Math.round(num).toString(16);
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    50
		if (num < 16) {
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    51
			return '0' + digits;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    52
		} else {
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    53
			return digits;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    54
		}
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    55
	}
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    56
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    57
	this.setColor = function(color, bg, fg) {
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    58
		
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    59
		// Set the colour.
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    60
		//
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    61
		// Picks a distinct colour based on an internal wheel; the bg
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    62
		// parameter provides the value that should be assigned to the 'zero'
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    63
		// colours and the fg parameter provides the multiplier that should be
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    64
		// applied to the foreground colours.
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    65
		
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    66
		color %= colors.length;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    67
		var red = (colors[color][0] * fg) || bg;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    68
		var green = (colors[color][1] * fg) || bg;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    69
		var blue = (colors[color][2] * fg) || bg;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    70
		red = Math.round(red * 255);
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    71
		green = Math.round(green * 255);
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    72
		blue = Math.round(blue * 255);
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    73
		var s = 'rgb(' + red + ', ' + green + ', ' + blue + ')';
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    74
		this.ctx.strokeStyle = s;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    75
		this.ctx.fillStyle = s;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    76
		return s;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    77
		
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    78
	}
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    79
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    80
	this.render = function(data) {
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    81
		
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    82
		var backgrounds = '';
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    83
		var nodedata = '';
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    84
		
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    85
		for (var i in data) {
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    86
			
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    87
			var parity = i % 2;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    88
			this.cell[1] += this.bg_height;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    89
			this.bg[1] += this.bg_height;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    90
			
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    91
			var cur = data[i];
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    92
			var node = cur[1];
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    93
			var edges = cur[2];
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    94
			var fold = false;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    95
			
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    96
			for (var j in edges) {
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    97
				
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    98
				line = edges[j];
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    99
				start = line[0];
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   100
				end = line[1];
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   101
				color = line[2];
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   102
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   103
				if (end > this.columns || start > this.columns) {
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   104
					this.columns += 1;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   105
				}
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   106
				
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   107
				if (start == this.columns && start > end) {
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   108
					var fold = true;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   109
				}
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   110
				
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   111
				x0 = this.cell[0] + this.box_size * start + this.box_size / 2;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   112
				y0 = this.bg[1] - this.bg_height / 2;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   113
				x1 = this.cell[0] + this.box_size * end + this.box_size / 2;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   114
				y1 = this.bg[1] + this.bg_height / 2;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   115
				
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   116
				this.edge(x0, y0, x1, y1, color);
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   117
				
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   118
			}
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   119
			
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   120
			// Draw the revision node in the right column
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   121
			
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   122
			column = node[0]
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   123
			color = node[1]
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   124
			
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   125
			radius = this.box_size / 8;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   126
			x = this.cell[0] + this.box_size * column + this.box_size / 2;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   127
			y = this.bg[1] - this.bg_height / 2;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   128
			var add = this.vertex(x, y, color, parity, cur);
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   129
			backgrounds += add[0];
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   130
			nodedata += add[1];
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   131
			
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   132
			if (fold) this.columns -= 1;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   133
			
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   134
		}
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   135
		
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   136
		document.getElementById('nodebgs').innerHTML += backgrounds;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   137
		document.getElementById('graphnodes').innerHTML += nodedata;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   138
		
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   139
	}
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   140
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   141
}
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   142
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   143
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   144
process_dates = (function(document, RegExp, Math, isNaN, Date, _false, _true){
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   145
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   146
	// derived from code from mercurial/templatefilter.py
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   147
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   148
	var scales = {
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   149
		'year':  365 * 24 * 60 * 60,
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   150
		'month':  30 * 24 * 60 * 60,
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   151
		'week':    7 * 24 * 60 * 60,
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   152
		'day':    24 * 60 * 60,
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   153
		'hour':   60 * 60,
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   154
		'minute': 60,
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   155
		'second': 1
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   156
	};
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   157
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   158
	function format(count, string){
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   159
		var ret = count + ' ' + string;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   160
		if (count > 1){
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   161
			ret = ret + 's';
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   162
		}
14881
2e54387976d4 web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents: 14571
diff changeset
   163
 		return ret;
2e54387976d4 web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents: 14571
diff changeset
   164
 	}
2e54387976d4 web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents: 14571
diff changeset
   165
2e54387976d4 web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents: 14571
diff changeset
   166
	function shortdate(date){
2e54387976d4 web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents: 14571
diff changeset
   167
		var ret = date.getFullYear() + '-';
2e54387976d4 web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents: 14571
diff changeset
   168
		// getMonth() gives a 0-11 result
2e54387976d4 web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents: 14571
diff changeset
   169
		var month = date.getMonth() + 1;
2e54387976d4 web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents: 14571
diff changeset
   170
		if (month <= 9){
2e54387976d4 web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents: 14571
diff changeset
   171
			ret += '0' + month;
2e54387976d4 web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents: 14571
diff changeset
   172
		} else {
2e54387976d4 web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents: 14571
diff changeset
   173
			ret += month;
2e54387976d4 web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents: 14571
diff changeset
   174
		}
2e54387976d4 web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents: 14571
diff changeset
   175
		ret += '-';
2e54387976d4 web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents: 14571
diff changeset
   176
		var day = date.getDate();
2e54387976d4 web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents: 14571
diff changeset
   177
		if (day <= 9){
2e54387976d4 web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents: 14571
diff changeset
   178
			ret += '0' + day;
2e54387976d4 web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents: 14571
diff changeset
   179
		} else {
2e54387976d4 web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents: 14571
diff changeset
   180
			ret += day;
2e54387976d4 web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents: 14571
diff changeset
   181
		}
14046
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   182
		return ret;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   183
	}
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   184
14881
2e54387976d4 web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents: 14571
diff changeset
   185
 	function age(datestr){
2e54387976d4 web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents: 14571
diff changeset
   186
 		var now = new Date();
2e54387976d4 web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents: 14571
diff changeset
   187
 		var once = new Date(datestr);
14046
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   188
		if (isNaN(once.getTime())){
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   189
			// parsing error
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   190
			return datestr;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   191
		}
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   192
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   193
		var delta = Math.floor((now.getTime() - once.getTime()) / 1000);
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   194
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   195
		var future = _false;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   196
		if (delta < 0){
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   197
			future = _true;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   198
			delta = -delta;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   199
			if (delta > (30 * scales.year)){
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   200
				return "in the distant future";
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   201
			}
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   202
		}
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   203
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   204
		if (delta > (2 * scales.year)){
14881
2e54387976d4 web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents: 14571
diff changeset
   205
			return shortdate(once);
14046
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   206
		}
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   207
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   208
		for (unit in scales){
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   209
			var s = scales[unit];
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   210
			var n = Math.floor(delta / s);
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   211
			if ((n >= 2) || (s == 1)){
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   212
				if (future){
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   213
					return format(n, unit) + ' from now';
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   214
				} else {
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   215
					return format(n, unit) + ' ago';
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   216
				}
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   217
			}
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   218
		}
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   219
	}
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   220
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   221
	return function(){
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   222
		var nodes = document.getElementsByTagName('*');
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   223
		var ageclass = new RegExp('\\bage\\b');
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   224
		var dateclass = new RegExp('\\bdate\\b');
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   225
		for (var i=0; i<nodes.length; ++i){
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   226
			var node = nodes[i];
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   227
			var classes = node.className;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   228
			if (ageclass.test(classes)){
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   229
				var agevalue = age(node.textContent);
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   230
				if (dateclass.test(classes)){
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   231
					// We want both: date + (age)
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   232
					node.textContent += ' ('+agevalue+')';
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   233
				} else {
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   234
					node.textContent = agevalue;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   235
				}
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   236
			}
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   237
		}
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   238
	}
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   239
})(document, RegExp, Math, isNaN, Date, false, true)
14571
17c0cb1045e5 paper, coal: display diffstat on the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents: 14046
diff changeset
   240
17c0cb1045e5 paper, coal: display diffstat on the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents: 14046
diff changeset
   241
function showDiffstat() {
17c0cb1045e5 paper, coal: display diffstat on the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents: 14046
diff changeset
   242
	document.getElementById('diffstatdetails').style.display = 'inline';
17c0cb1045e5 paper, coal: display diffstat on the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents: 14046
diff changeset
   243
	document.getElementById('diffstatexpand').style.display = 'none';
17c0cb1045e5 paper, coal: display diffstat on the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents: 14046
diff changeset
   244
}
17c0cb1045e5 paper, coal: display diffstat on the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents: 14046
diff changeset
   245
17c0cb1045e5 paper, coal: display diffstat on the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents: 14046
diff changeset
   246
function hideDiffstat() {
17c0cb1045e5 paper, coal: display diffstat on the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents: 14046
diff changeset
   247
	document.getElementById('diffstatdetails').style.display = 'none';
17c0cb1045e5 paper, coal: display diffstat on the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents: 14046
diff changeset
   248
	document.getElementById('diffstatexpand').style.display = 'inline';
17c0cb1045e5 paper, coal: display diffstat on the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents: 14046
diff changeset
   249
}