author | Gregory Szorc <gregory.szorc@gmail.com> |
Sat, 26 Jan 2019 14:16:34 -0800 | |
changeset 41437 | 873a28d7e962 |
parent 37831 | 387af9e5df70 |
permissions | -rw-r--r-- |
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() { |
19530
a63d3ff0d765
hgweb: remove trailing whitespace in mercurial.js
Kevin Bullock <kbullock@ringworld.org>
parents:
19430
diff
changeset
|
26 |
|
14046
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 |
this.ctx = this.canvas.getContext('2d'); |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
29 |
this.ctx.strokeStyle = 'rgb(0, 0, 0)'; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
30 |
this.ctx.fillStyle = 'rgb(0, 0, 0)'; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
31 |
this.bg = [0, 4]; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
32 |
this.cell = [2, 0]; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
33 |
this.columns = 0; |
19530
a63d3ff0d765
hgweb: remove trailing whitespace in mercurial.js
Kevin Bullock <kbullock@ringworld.org>
parents:
19430
diff
changeset
|
34 |
|
35263
9c99541e3d56
hgweb: create Graph methods using a prototype
Anton Shestakov <av6@dwimlabs.net>
parents:
35262
diff
changeset
|
35 |
} |
9c99541e3d56
hgweb: create Graph methods using a prototype
Anton Shestakov <av6@dwimlabs.net>
parents:
35262
diff
changeset
|
36 |
|
9c99541e3d56
hgweb: create Graph methods using a prototype
Anton Shestakov <av6@dwimlabs.net>
parents:
35262
diff
changeset
|
37 |
Graph.prototype = { |
9c99541e3d56
hgweb: create Graph methods using a prototype
Anton Shestakov <av6@dwimlabs.net>
parents:
35262
diff
changeset
|
38 |
reset: function() { |
19780
659bc603bd0d
hgweb: add reset javascript function to Graph
Alexander Plavin <alexander@plav.in>
parents:
19760
diff
changeset
|
39 |
this.bg = [0, 4]; |
659bc603bd0d
hgweb: add reset javascript function to Graph
Alexander Plavin <alexander@plav.in>
parents:
19760
diff
changeset
|
40 |
this.cell = [2, 0]; |
659bc603bd0d
hgweb: add reset javascript function to Graph
Alexander Plavin <alexander@plav.in>
parents:
19760
diff
changeset
|
41 |
this.columns = 0; |
35263
9c99541e3d56
hgweb: create Graph methods using a prototype
Anton Shestakov <av6@dwimlabs.net>
parents:
35262
diff
changeset
|
42 |
}, |
19780
659bc603bd0d
hgweb: add reset javascript function to Graph
Alexander Plavin <alexander@plav.in>
parents:
19760
diff
changeset
|
43 |
|
35263
9c99541e3d56
hgweb: create Graph methods using a prototype
Anton Shestakov <av6@dwimlabs.net>
parents:
35262
diff
changeset
|
44 |
scale: function(height) { |
14046
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
45 |
this.bg_height = height; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
46 |
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
|
47 |
this.cell_height = this.box_size; |
35263
9c99541e3d56
hgweb: create Graph methods using a prototype
Anton Shestakov <av6@dwimlabs.net>
parents:
35262
diff
changeset
|
48 |
}, |
19530
a63d3ff0d765
hgweb: remove trailing whitespace in mercurial.js
Kevin Bullock <kbullock@ringworld.org>
parents:
19430
diff
changeset
|
49 |
|
35263
9c99541e3d56
hgweb: create Graph methods using a prototype
Anton Shestakov <av6@dwimlabs.net>
parents:
35262
diff
changeset
|
50 |
setColor: function(color, bg, fg) { |
19530
a63d3ff0d765
hgweb: remove trailing whitespace in mercurial.js
Kevin Bullock <kbullock@ringworld.org>
parents:
19430
diff
changeset
|
51 |
|
14046
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
52 |
// Set the colour. |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
53 |
// |
16138
6e4de55a41a4
hgweb: refactor graph customization javascript
Patrick Mezard <patrick@mezard.eu>
parents:
16137
diff
changeset
|
54 |
// If color is a string, expect an hexadecimal RGB |
6e4de55a41a4
hgweb: refactor graph customization javascript
Patrick Mezard <patrick@mezard.eu>
parents:
16137
diff
changeset
|
55 |
// value and apply it unchanged. If color is a number, |
6e4de55a41a4
hgweb: refactor graph customization javascript
Patrick Mezard <patrick@mezard.eu>
parents:
16137
diff
changeset
|
56 |
// pick a distinct colour based on an internal wheel; |
6e4de55a41a4
hgweb: refactor graph customization javascript
Patrick Mezard <patrick@mezard.eu>
parents:
16137
diff
changeset
|
57 |
// the bg parameter provides the value that should be |
6e4de55a41a4
hgweb: refactor graph customization javascript
Patrick Mezard <patrick@mezard.eu>
parents:
16137
diff
changeset
|
58 |
// assigned to the 'zero' colours and the fg parameter |
6e4de55a41a4
hgweb: refactor graph customization javascript
Patrick Mezard <patrick@mezard.eu>
parents:
16137
diff
changeset
|
59 |
// provides the multiplier that should be applied to |
6e4de55a41a4
hgweb: refactor graph customization javascript
Patrick Mezard <patrick@mezard.eu>
parents:
16137
diff
changeset
|
60 |
// the foreground colours. |
16130
33f702e52906
graph: in hgrc specify line color for main branch
Constantine Linnick <theaspect@gmail.com>
parents:
16129
diff
changeset
|
61 |
var s; |
35178
ccf86aa5797c
hgweb: use strict equals in mercurial.js
Anton Shestakov <av6@dwimlabs.net>
parents:
35156
diff
changeset
|
62 |
if(typeof color === "string") { |
16138
6e4de55a41a4
hgweb: refactor graph customization javascript
Patrick Mezard <patrick@mezard.eu>
parents:
16137
diff
changeset
|
63 |
s = "#" + color; |
35178
ccf86aa5797c
hgweb: use strict equals in mercurial.js
Anton Shestakov <av6@dwimlabs.net>
parents:
35156
diff
changeset
|
64 |
} else { //typeof color === "number" |
16130
33f702e52906
graph: in hgrc specify line color for main branch
Constantine Linnick <theaspect@gmail.com>
parents:
16129
diff
changeset
|
65 |
color %= colors.length; |
33f702e52906
graph: in hgrc specify line color for main branch
Constantine Linnick <theaspect@gmail.com>
parents:
16129
diff
changeset
|
66 |
var red = (colors[color][0] * fg) || bg; |
33f702e52906
graph: in hgrc specify line color for main branch
Constantine Linnick <theaspect@gmail.com>
parents:
16129
diff
changeset
|
67 |
var green = (colors[color][1] * fg) || bg; |
33f702e52906
graph: in hgrc specify line color for main branch
Constantine Linnick <theaspect@gmail.com>
parents:
16129
diff
changeset
|
68 |
var blue = (colors[color][2] * fg) || bg; |
33f702e52906
graph: in hgrc specify line color for main branch
Constantine Linnick <theaspect@gmail.com>
parents:
16129
diff
changeset
|
69 |
red = Math.round(red * 255); |
33f702e52906
graph: in hgrc specify line color for main branch
Constantine Linnick <theaspect@gmail.com>
parents:
16129
diff
changeset
|
70 |
green = Math.round(green * 255); |
33f702e52906
graph: in hgrc specify line color for main branch
Constantine Linnick <theaspect@gmail.com>
parents:
16129
diff
changeset
|
71 |
blue = Math.round(blue * 255); |
33f702e52906
graph: in hgrc specify line color for main branch
Constantine Linnick <theaspect@gmail.com>
parents:
16129
diff
changeset
|
72 |
s = 'rgb(' + red + ', ' + green + ', ' + blue + ')'; |
33f702e52906
graph: in hgrc specify line color for main branch
Constantine Linnick <theaspect@gmail.com>
parents:
16129
diff
changeset
|
73 |
} |
14046
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; |
19530
a63d3ff0d765
hgweb: remove trailing whitespace in mercurial.js
Kevin Bullock <kbullock@ringworld.org>
parents:
19430
diff
changeset
|
77 |
|
35263
9c99541e3d56
hgweb: create Graph methods using a prototype
Anton Shestakov <av6@dwimlabs.net>
parents:
35262
diff
changeset
|
78 |
}, |
14046
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
79 |
|
35263
9c99541e3d56
hgweb: create Graph methods using a prototype
Anton Shestakov <av6@dwimlabs.net>
parents:
35262
diff
changeset
|
80 |
edge: function(x0, y0, x1, y1, color, width) { |
19530
a63d3ff0d765
hgweb: remove trailing whitespace in mercurial.js
Kevin Bullock <kbullock@ringworld.org>
parents:
19430
diff
changeset
|
81 |
|
16137
8fd18eb8aab7
templates: move Graph.edge() implementation in mercurial.js
Patrick Mezard <patrick@mezard.eu>
parents:
16130
diff
changeset
|
82 |
this.setColor(color, 0.0, 0.65); |
16138
6e4de55a41a4
hgweb: refactor graph customization javascript
Patrick Mezard <patrick@mezard.eu>
parents:
16137
diff
changeset
|
83 |
if(width >= 0) |
6e4de55a41a4
hgweb: refactor graph customization javascript
Patrick Mezard <patrick@mezard.eu>
parents:
16137
diff
changeset
|
84 |
this.ctx.lineWidth = width; |
16137
8fd18eb8aab7
templates: move Graph.edge() implementation in mercurial.js
Patrick Mezard <patrick@mezard.eu>
parents:
16130
diff
changeset
|
85 |
this.ctx.beginPath(); |
8fd18eb8aab7
templates: move Graph.edge() implementation in mercurial.js
Patrick Mezard <patrick@mezard.eu>
parents:
16130
diff
changeset
|
86 |
this.ctx.moveTo(x0, y0); |
8fd18eb8aab7
templates: move Graph.edge() implementation in mercurial.js
Patrick Mezard <patrick@mezard.eu>
parents:
16130
diff
changeset
|
87 |
this.ctx.lineTo(x1, y1); |
8fd18eb8aab7
templates: move Graph.edge() implementation in mercurial.js
Patrick Mezard <patrick@mezard.eu>
parents:
16130
diff
changeset
|
88 |
this.ctx.stroke(); |
19530
a63d3ff0d765
hgweb: remove trailing whitespace in mercurial.js
Kevin Bullock <kbullock@ringworld.org>
parents:
19430
diff
changeset
|
89 |
|
35263
9c99541e3d56
hgweb: create Graph methods using a prototype
Anton Shestakov <av6@dwimlabs.net>
parents:
35262
diff
changeset
|
90 |
}, |
16137
8fd18eb8aab7
templates: move Graph.edge() implementation in mercurial.js
Patrick Mezard <patrick@mezard.eu>
parents:
16130
diff
changeset
|
91 |
|
35566
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
92 |
graphNodeCurrent: function(x, y, radius) { |
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
93 |
this.ctx.lineWidth = 2; |
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
94 |
this.ctx.beginPath(); |
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
95 |
this.ctx.arc(x, y, radius * 1.75, 0, Math.PI * 2, true); |
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
96 |
this.ctx.stroke(); |
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
97 |
}, |
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
98 |
|
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
99 |
graphNodeClosing: function(x, y, radius) { |
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
100 |
this.ctx.fillRect(x - radius, y - 1.5, radius * 2, 3); |
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
101 |
}, |
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
102 |
|
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
103 |
graphNodeUnstable: function(x, y, radius) { |
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
104 |
var x30 = radius * Math.cos(Math.PI / 6); |
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
105 |
var y30 = radius * Math.sin(Math.PI / 6); |
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
106 |
this.ctx.lineWidth = 2; |
35264
ad0de63e1d6a
hgweb: move common vertex code to Graph.prototype
Anton Shestakov <av6@dwimlabs.net>
parents:
35263
diff
changeset
|
107 |
this.ctx.beginPath(); |
35566
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
108 |
this.ctx.moveTo(x, y - radius); |
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
109 |
this.ctx.lineTo(x, y + radius); |
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
110 |
this.ctx.moveTo(x - x30, y - y30); |
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
111 |
this.ctx.lineTo(x + x30, y + y30); |
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
112 |
this.ctx.moveTo(x - x30, y + y30); |
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
113 |
this.ctx.lineTo(x + x30, y - y30); |
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
114 |
this.ctx.stroke(); |
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
115 |
}, |
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
116 |
|
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
117 |
graphNodeObsolete: function(x, y, radius) { |
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
118 |
var p45 = radius * Math.cos(Math.PI / 4); |
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
119 |
this.ctx.lineWidth = 3; |
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
120 |
this.ctx.beginPath(); |
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
121 |
this.ctx.moveTo(x - p45, y - p45); |
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
122 |
this.ctx.lineTo(x + p45, y + p45); |
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
123 |
this.ctx.moveTo(x - p45, y + p45); |
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
124 |
this.ctx.lineTo(x + p45, y - p45); |
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
125 |
this.ctx.stroke(); |
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
126 |
}, |
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
127 |
|
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
128 |
graphNodeNormal: function(x, y, radius) { |
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
129 |
this.ctx.beginPath(); |
35264
ad0de63e1d6a
hgweb: move common vertex code to Graph.prototype
Anton Shestakov <av6@dwimlabs.net>
parents:
35263
diff
changeset
|
130 |
this.ctx.arc(x, y, radius, 0, Math.PI * 2, true); |
ad0de63e1d6a
hgweb: move common vertex code to Graph.prototype
Anton Shestakov <av6@dwimlabs.net>
parents:
35263
diff
changeset
|
131 |
this.ctx.fill(); |
35566
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
132 |
}, |
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
133 |
|
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
134 |
vertex: function(x, y, radius, color, parity, cur) { |
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
135 |
this.ctx.save(); |
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
136 |
this.setColor(color, 0.25, 0.75); |
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
137 |
if (cur.graphnode[0] === '@') { |
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
138 |
this.graphNodeCurrent(x, y, radius); |
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
139 |
} |
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
140 |
switch (cur.graphnode.substr(-1)) { |
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
141 |
case '_': |
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
142 |
this.graphNodeClosing(x, y, radius); |
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
143 |
break; |
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
144 |
case '*': |
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
145 |
this.graphNodeUnstable(x, y, radius); |
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
146 |
break; |
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
147 |
case 'x': |
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
148 |
this.graphNodeObsolete(x, y, radius); |
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
149 |
break; |
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
150 |
default: |
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
151 |
this.graphNodeNormal(x, y, radius); |
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
152 |
} |
baca93a47992
hgweb: make different kinds of commits look differently on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35537
diff
changeset
|
153 |
this.ctx.restore(); |
35264
ad0de63e1d6a
hgweb: move common vertex code to Graph.prototype
Anton Shestakov <av6@dwimlabs.net>
parents:
35263
diff
changeset
|
154 |
|
ad0de63e1d6a
hgweb: move common vertex code to Graph.prototype
Anton Shestakov <av6@dwimlabs.net>
parents:
35263
diff
changeset
|
155 |
var left = (this.bg_height - this.box_size) + (this.columns + 1) * this.box_size; |
ad0de63e1d6a
hgweb: move common vertex code to Graph.prototype
Anton Shestakov <av6@dwimlabs.net>
parents:
35263
diff
changeset
|
156 |
var item = document.querySelector('[data-node="' + cur.node + '"]'); |
ad0de63e1d6a
hgweb: move common vertex code to Graph.prototype
Anton Shestakov <av6@dwimlabs.net>
parents:
35263
diff
changeset
|
157 |
if (item) { |
ad0de63e1d6a
hgweb: move common vertex code to Graph.prototype
Anton Shestakov <av6@dwimlabs.net>
parents:
35263
diff
changeset
|
158 |
item.style.paddingLeft = left + 'px'; |
ad0de63e1d6a
hgweb: move common vertex code to Graph.prototype
Anton Shestakov <av6@dwimlabs.net>
parents:
35263
diff
changeset
|
159 |
} |
ad0de63e1d6a
hgweb: move common vertex code to Graph.prototype
Anton Shestakov <av6@dwimlabs.net>
parents:
35263
diff
changeset
|
160 |
}, |
ad0de63e1d6a
hgweb: move common vertex code to Graph.prototype
Anton Shestakov <av6@dwimlabs.net>
parents:
35263
diff
changeset
|
161 |
|
35263
9c99541e3d56
hgweb: create Graph methods using a prototype
Anton Shestakov <av6@dwimlabs.net>
parents:
35262
diff
changeset
|
162 |
render: function(data) { |
19530
a63d3ff0d765
hgweb: remove trailing whitespace in mercurial.js
Kevin Bullock <kbullock@ringworld.org>
parents:
19430
diff
changeset
|
163 |
|
35414
27ab3150cd50
hgweb: calculate <canvas> width and height client-side
Anton Shestakov <av6@dwimlabs.net>
parents:
35264
diff
changeset
|
164 |
var i, j, cur, line, start, end, color, x, y, x0, y0, x1, y1, column, radius; |
19530
a63d3ff0d765
hgweb: remove trailing whitespace in mercurial.js
Kevin Bullock <kbullock@ringworld.org>
parents:
19430
diff
changeset
|
165 |
|
35414
27ab3150cd50
hgweb: calculate <canvas> width and height client-side
Anton Shestakov <av6@dwimlabs.net>
parents:
35264
diff
changeset
|
166 |
var cols = 0; |
27ab3150cd50
hgweb: calculate <canvas> width and height client-side
Anton Shestakov <av6@dwimlabs.net>
parents:
35264
diff
changeset
|
167 |
for (i = 0; i < data.length; i++) { |
27ab3150cd50
hgweb: calculate <canvas> width and height client-side
Anton Shestakov <av6@dwimlabs.net>
parents:
35264
diff
changeset
|
168 |
cur = data[i]; |
27ab3150cd50
hgweb: calculate <canvas> width and height client-side
Anton Shestakov <av6@dwimlabs.net>
parents:
35264
diff
changeset
|
169 |
for (j = 0; j < cur.edges.length; j++) { |
27ab3150cd50
hgweb: calculate <canvas> width and height client-side
Anton Shestakov <av6@dwimlabs.net>
parents:
35264
diff
changeset
|
170 |
line = cur.edges[j]; |
27ab3150cd50
hgweb: calculate <canvas> width and height client-side
Anton Shestakov <av6@dwimlabs.net>
parents:
35264
diff
changeset
|
171 |
cols = Math.max(cols, line[0], line[1]); |
27ab3150cd50
hgweb: calculate <canvas> width and height client-side
Anton Shestakov <av6@dwimlabs.net>
parents:
35264
diff
changeset
|
172 |
} |
27ab3150cd50
hgweb: calculate <canvas> width and height client-side
Anton Shestakov <av6@dwimlabs.net>
parents:
35264
diff
changeset
|
173 |
} |
27ab3150cd50
hgweb: calculate <canvas> width and height client-side
Anton Shestakov <av6@dwimlabs.net>
parents:
35264
diff
changeset
|
174 |
this.canvas.width = (cols + 1) * this.bg_height; |
27ab3150cd50
hgweb: calculate <canvas> width and height client-side
Anton Shestakov <av6@dwimlabs.net>
parents:
35264
diff
changeset
|
175 |
this.canvas.height = (data.length + 1) * this.bg_height - 27; |
27ab3150cd50
hgweb: calculate <canvas> width and height client-side
Anton Shestakov <av6@dwimlabs.net>
parents:
35264
diff
changeset
|
176 |
|
27ab3150cd50
hgweb: calculate <canvas> width and height client-side
Anton Shestakov <av6@dwimlabs.net>
parents:
35264
diff
changeset
|
177 |
for (i = 0; i < data.length; i++) { |
19530
a63d3ff0d765
hgweb: remove trailing whitespace in mercurial.js
Kevin Bullock <kbullock@ringworld.org>
parents:
19430
diff
changeset
|
178 |
|
14046
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
179 |
var parity = i % 2; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
180 |
this.cell[1] += this.bg_height; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
181 |
this.bg[1] += this.bg_height; |
19530
a63d3ff0d765
hgweb: remove trailing whitespace in mercurial.js
Kevin Bullock <kbullock@ringworld.org>
parents:
19430
diff
changeset
|
182 |
|
35414
27ab3150cd50
hgweb: calculate <canvas> width and height client-side
Anton Shestakov <av6@dwimlabs.net>
parents:
35264
diff
changeset
|
183 |
cur = data[i]; |
14046
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
184 |
var fold = false; |
19530
a63d3ff0d765
hgweb: remove trailing whitespace in mercurial.js
Kevin Bullock <kbullock@ringworld.org>
parents:
19430
diff
changeset
|
185 |
|
16138
6e4de55a41a4
hgweb: refactor graph customization javascript
Patrick Mezard <patrick@mezard.eu>
parents:
16137
diff
changeset
|
186 |
var prevWidth = this.ctx.lineWidth; |
35414
27ab3150cd50
hgweb: calculate <canvas> width and height client-side
Anton Shestakov <av6@dwimlabs.net>
parents:
35264
diff
changeset
|
187 |
for (j = 0; j < cur.edges.length; j++) { |
19530
a63d3ff0d765
hgweb: remove trailing whitespace in mercurial.js
Kevin Bullock <kbullock@ringworld.org>
parents:
19430
diff
changeset
|
188 |
|
35227
d61f2a3d5e53
hgweb: only include graph-related data in jsdata variable on /graph pages (BC)
Anton Shestakov <av6@dwimlabs.net>
parents:
35226
diff
changeset
|
189 |
line = cur.edges[j]; |
14046
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
190 |
start = line[0]; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
191 |
end = line[1]; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
192 |
color = line[2]; |
16138
6e4de55a41a4
hgweb: refactor graph customization javascript
Patrick Mezard <patrick@mezard.eu>
parents:
16137
diff
changeset
|
193 |
var width = line[3]; |
6e4de55a41a4
hgweb: refactor graph customization javascript
Patrick Mezard <patrick@mezard.eu>
parents:
16137
diff
changeset
|
194 |
if(width < 0) |
6e4de55a41a4
hgweb: refactor graph customization javascript
Patrick Mezard <patrick@mezard.eu>
parents:
16137
diff
changeset
|
195 |
width = prevWidth; |
6e4de55a41a4
hgweb: refactor graph customization javascript
Patrick Mezard <patrick@mezard.eu>
parents:
16137
diff
changeset
|
196 |
var branchcolor = line[4]; |
6e4de55a41a4
hgweb: refactor graph customization javascript
Patrick Mezard <patrick@mezard.eu>
parents:
16137
diff
changeset
|
197 |
if(branchcolor) |
6e4de55a41a4
hgweb: refactor graph customization javascript
Patrick Mezard <patrick@mezard.eu>
parents:
16137
diff
changeset
|
198 |
color = branchcolor; |
19530
a63d3ff0d765
hgweb: remove trailing whitespace in mercurial.js
Kevin Bullock <kbullock@ringworld.org>
parents:
19430
diff
changeset
|
199 |
|
14046
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
200 |
if (end > this.columns || start > this.columns) { |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
201 |
this.columns += 1; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
202 |
} |
19530
a63d3ff0d765
hgweb: remove trailing whitespace in mercurial.js
Kevin Bullock <kbullock@ringworld.org>
parents:
19430
diff
changeset
|
203 |
|
35178
ccf86aa5797c
hgweb: use strict equals in mercurial.js
Anton Shestakov <av6@dwimlabs.net>
parents:
35156
diff
changeset
|
204 |
if (start === this.columns && start > end) { |
35065
5f82e26cbed1
hgweb: fix jshint issues in mercurial.js
Anton Shestakov <av6@dwimlabs.net>
parents:
34392
diff
changeset
|
205 |
fold = true; |
14046
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
206 |
} |
19530
a63d3ff0d765
hgweb: remove trailing whitespace in mercurial.js
Kevin Bullock <kbullock@ringworld.org>
parents:
19430
diff
changeset
|
207 |
|
14046
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
208 |
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
|
209 |
y0 = this.bg[1] - this.bg_height / 2; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
210 |
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
|
211 |
y1 = this.bg[1] + this.bg_height / 2; |
19530
a63d3ff0d765
hgweb: remove trailing whitespace in mercurial.js
Kevin Bullock <kbullock@ringworld.org>
parents:
19430
diff
changeset
|
212 |
|
16138
6e4de55a41a4
hgweb: refactor graph customization javascript
Patrick Mezard <patrick@mezard.eu>
parents:
16137
diff
changeset
|
213 |
this.edge(x0, y0, x1, y1, color, width); |
19530
a63d3ff0d765
hgweb: remove trailing whitespace in mercurial.js
Kevin Bullock <kbullock@ringworld.org>
parents:
19430
diff
changeset
|
214 |
|
14046
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
215 |
} |
16138
6e4de55a41a4
hgweb: refactor graph customization javascript
Patrick Mezard <patrick@mezard.eu>
parents:
16137
diff
changeset
|
216 |
this.ctx.lineWidth = prevWidth; |
19530
a63d3ff0d765
hgweb: remove trailing whitespace in mercurial.js
Kevin Bullock <kbullock@ringworld.org>
parents:
19430
diff
changeset
|
217 |
|
14046
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
218 |
// Draw the revision node in the right column |
19530
a63d3ff0d765
hgweb: remove trailing whitespace in mercurial.js
Kevin Bullock <kbullock@ringworld.org>
parents:
19430
diff
changeset
|
219 |
|
35227
d61f2a3d5e53
hgweb: only include graph-related data in jsdata variable on /graph pages (BC)
Anton Shestakov <av6@dwimlabs.net>
parents:
35226
diff
changeset
|
220 |
column = cur.vertex[0]; |
d61f2a3d5e53
hgweb: only include graph-related data in jsdata variable on /graph pages (BC)
Anton Shestakov <av6@dwimlabs.net>
parents:
35226
diff
changeset
|
221 |
color = cur.vertex[1]; |
19530
a63d3ff0d765
hgweb: remove trailing whitespace in mercurial.js
Kevin Bullock <kbullock@ringworld.org>
parents:
19430
diff
changeset
|
222 |
|
14046
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
223 |
radius = this.box_size / 8; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
224 |
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
|
225 |
y = this.bg[1] - this.bg_height / 2; |
35537
8b958d21b19d
hgweb: stop adding strings to innerHTML of #graphnodes and #nodebgs (BC)
Anton Shestakov <av6@dwimlabs.net>
parents:
35416
diff
changeset
|
226 |
this.vertex(x, y, radius, color, parity, cur); |
19530
a63d3ff0d765
hgweb: remove trailing whitespace in mercurial.js
Kevin Bullock <kbullock@ringworld.org>
parents:
19430
diff
changeset
|
227 |
|
14046
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
228 |
if (fold) this.columns -= 1; |
19530
a63d3ff0d765
hgweb: remove trailing whitespace in mercurial.js
Kevin Bullock <kbullock@ringworld.org>
parents:
19430
diff
changeset
|
229 |
|
14046
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
230 |
} |
19530
a63d3ff0d765
hgweb: remove trailing whitespace in mercurial.js
Kevin Bullock <kbullock@ringworld.org>
parents:
19430
diff
changeset
|
231 |
|
35263
9c99541e3d56
hgweb: create Graph methods using a prototype
Anton Shestakov <av6@dwimlabs.net>
parents:
35262
diff
changeset
|
232 |
} |
14046
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
233 |
|
35263
9c99541e3d56
hgweb: create Graph methods using a prototype
Anton Shestakov <av6@dwimlabs.net>
parents:
35262
diff
changeset
|
234 |
}; |
14046
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 |
|
19858
4a8c5a51f7a1
hgweb: add parentSelector argument to process_dates
Alexander Plavin <alexander@plav.in>
parents:
19857
diff
changeset
|
237 |
function process_dates(parentSelector){ |
14046
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 |
// derived from code from mercurial/templatefilter.py |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
240 |
|
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
241 |
var scales = { |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
242 |
'year': 365 * 24 * 60 * 60, |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
243 |
'month': 30 * 24 * 60 * 60, |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
244 |
'week': 7 * 24 * 60 * 60, |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
245 |
'day': 24 * 60 * 60, |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
246 |
'hour': 60 * 60, |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
247 |
'minute': 60, |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
248 |
'second': 1 |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
249 |
}; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
250 |
|
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
251 |
function format(count, string){ |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
252 |
var ret = count + ' ' + string; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
253 |
if (count > 1){ |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
254 |
ret = ret + 's'; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
255 |
} |
14881
2e54387976d4
web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents:
14571
diff
changeset
|
256 |
return ret; |
2e54387976d4
web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents:
14571
diff
changeset
|
257 |
} |
2e54387976d4
web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents:
14571
diff
changeset
|
258 |
|
2e54387976d4
web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents:
14571
diff
changeset
|
259 |
function shortdate(date){ |
2e54387976d4
web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents:
14571
diff
changeset
|
260 |
var ret = date.getFullYear() + '-'; |
2e54387976d4
web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents:
14571
diff
changeset
|
261 |
// 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
|
262 |
var month = date.getMonth() + 1; |
2e54387976d4
web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents:
14571
diff
changeset
|
263 |
if (month <= 9){ |
2e54387976d4
web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents:
14571
diff
changeset
|
264 |
ret += '0' + month; |
2e54387976d4
web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents:
14571
diff
changeset
|
265 |
} else { |
2e54387976d4
web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents:
14571
diff
changeset
|
266 |
ret += month; |
2e54387976d4
web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents:
14571
diff
changeset
|
267 |
} |
2e54387976d4
web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents:
14571
diff
changeset
|
268 |
ret += '-'; |
2e54387976d4
web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents:
14571
diff
changeset
|
269 |
var day = date.getDate(); |
2e54387976d4
web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents:
14571
diff
changeset
|
270 |
if (day <= 9){ |
2e54387976d4
web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents:
14571
diff
changeset
|
271 |
ret += '0' + day; |
2e54387976d4
web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents:
14571
diff
changeset
|
272 |
} else { |
2e54387976d4
web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents:
14571
diff
changeset
|
273 |
ret += day; |
2e54387976d4
web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents:
14571
diff
changeset
|
274 |
} |
14046
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
275 |
return ret; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
276 |
} |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
277 |
|
14881
2e54387976d4
web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents:
14571
diff
changeset
|
278 |
function age(datestr){ |
2e54387976d4
web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents:
14571
diff
changeset
|
279 |
var now = new Date(); |
2e54387976d4
web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents:
14571
diff
changeset
|
280 |
var once = new Date(datestr); |
14046
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
281 |
if (isNaN(once.getTime())){ |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
282 |
// parsing error |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
283 |
return datestr; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
284 |
} |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
285 |
|
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
286 |
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
|
287 |
|
19834
80633eac7b9d
hgweb: eliminate extra complexity in process_dates definition
Alexander Plavin <alexander@plav.in>
parents:
19782
diff
changeset
|
288 |
var future = false; |
14046
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
289 |
if (delta < 0){ |
19834
80633eac7b9d
hgweb: eliminate extra complexity in process_dates definition
Alexander Plavin <alexander@plav.in>
parents:
19782
diff
changeset
|
290 |
future = true; |
14046
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
291 |
delta = -delta; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
292 |
if (delta > (30 * scales.year)){ |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
293 |
return "in the distant future"; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
294 |
} |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
295 |
} |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
296 |
|
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
297 |
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
|
298 |
return shortdate(once); |
14046
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
299 |
} |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
300 |
|
35065
5f82e26cbed1
hgweb: fix jshint issues in mercurial.js
Anton Shestakov <av6@dwimlabs.net>
parents:
34392
diff
changeset
|
301 |
for (var unit in scales){ |
35179
241da2de0e9f
hgweb: properly iterate over arrays and objects in mercurial.js
Anton Shestakov <av6@dwimlabs.net>
parents:
35178
diff
changeset
|
302 |
if (!scales.hasOwnProperty(unit)) { continue; } |
14046
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
303 |
var s = scales[unit]; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
304 |
var n = Math.floor(delta / s); |
35178
ccf86aa5797c
hgweb: use strict equals in mercurial.js
Anton Shestakov <av6@dwimlabs.net>
parents:
35156
diff
changeset
|
305 |
if ((n >= 2) || (s === 1)){ |
14046
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
306 |
if (future){ |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
307 |
return format(n, unit) + ' from now'; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
308 |
} else { |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
309 |
return format(n, unit) + ' ago'; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
310 |
} |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
311 |
} |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
312 |
} |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
313 |
} |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
314 |
|
19858
4a8c5a51f7a1
hgweb: add parentSelector argument to process_dates
Alexander Plavin <alexander@plav.in>
parents:
19857
diff
changeset
|
315 |
var nodes = document.querySelectorAll((parentSelector || '') + ' .age'); |
19834
80633eac7b9d
hgweb: eliminate extra complexity in process_dates definition
Alexander Plavin <alexander@plav.in>
parents:
19782
diff
changeset
|
316 |
var dateclass = new RegExp('\\bdate\\b'); |
80633eac7b9d
hgweb: eliminate extra complexity in process_dates definition
Alexander Plavin <alexander@plav.in>
parents:
19782
diff
changeset
|
317 |
for (var i=0; i<nodes.length; ++i){ |
80633eac7b9d
hgweb: eliminate extra complexity in process_dates definition
Alexander Plavin <alexander@plav.in>
parents:
19782
diff
changeset
|
318 |
var node = nodes[i]; |
80633eac7b9d
hgweb: eliminate extra complexity in process_dates definition
Alexander Plavin <alexander@plav.in>
parents:
19782
diff
changeset
|
319 |
var classes = node.className; |
19857
14fddba036f8
hgweb: optimize process_dates function
Alexander Plavin <alexander@plav.in>
parents:
19834
diff
changeset
|
320 |
var agevalue = age(node.textContent); |
14fddba036f8
hgweb: optimize process_dates function
Alexander Plavin <alexander@plav.in>
parents:
19834
diff
changeset
|
321 |
if (dateclass.test(classes)){ |
14fddba036f8
hgweb: optimize process_dates function
Alexander Plavin <alexander@plav.in>
parents:
19834
diff
changeset
|
322 |
// We want both: date + (age) |
14fddba036f8
hgweb: optimize process_dates function
Alexander Plavin <alexander@plav.in>
parents:
19834
diff
changeset
|
323 |
node.textContent += ' ('+agevalue+')'; |
14fddba036f8
hgweb: optimize process_dates function
Alexander Plavin <alexander@plav.in>
parents:
19834
diff
changeset
|
324 |
} else { |
14fddba036f8
hgweb: optimize process_dates function
Alexander Plavin <alexander@plav.in>
parents:
19834
diff
changeset
|
325 |
node.title = node.textContent; |
14fddba036f8
hgweb: optimize process_dates function
Alexander Plavin <alexander@plav.in>
parents:
19834
diff
changeset
|
326 |
node.textContent = agevalue; |
14046
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
327 |
} |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
328 |
} |
19834
80633eac7b9d
hgweb: eliminate extra complexity in process_dates definition
Alexander Plavin <alexander@plav.in>
parents:
19782
diff
changeset
|
329 |
} |
14571
17c0cb1045e5
paper, coal: display diffstat on the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14046
diff
changeset
|
330 |
|
37831
387af9e5df70
hgweb: prevent triggering dummy href="#" handler
Yuya Nishihara <yuya@tcha.org>
parents:
37829
diff
changeset
|
331 |
function toggleDiffstat(event) { |
19428
c3cdba6e5d7f
hgweb: toggleDiffstat function instead of showDiffstat and hideDiffstat
Alexander Plavin <me@aplavin.ru>
parents:
17694
diff
changeset
|
332 |
var curdetails = document.getElementById('diffstatdetails').style.display; |
35178
ccf86aa5797c
hgweb: use strict equals in mercurial.js
Anton Shestakov <av6@dwimlabs.net>
parents:
35156
diff
changeset
|
333 |
var curexpand = curdetails === 'none' ? 'inline' : 'none'; |
19428
c3cdba6e5d7f
hgweb: toggleDiffstat function instead of showDiffstat and hideDiffstat
Alexander Plavin <me@aplavin.ru>
parents:
17694
diff
changeset
|
334 |
document.getElementById('diffstatdetails').style.display = curexpand; |
c3cdba6e5d7f
hgweb: toggleDiffstat function instead of showDiffstat and hideDiffstat
Alexander Plavin <me@aplavin.ru>
parents:
17694
diff
changeset
|
335 |
document.getElementById('diffstatexpand').style.display = curdetails; |
37831
387af9e5df70
hgweb: prevent triggering dummy href="#" handler
Yuya Nishihara <yuya@tcha.org>
parents:
37829
diff
changeset
|
336 |
event.preventDefault(); |
14571
17c0cb1045e5
paper, coal: display diffstat on the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14046
diff
changeset
|
337 |
} |
19430
5ec5097b4c0f
hgweb: add line wrapping switch to file source view
Alexander Plavin <me@aplavin.ru>
parents:
19428
diff
changeset
|
338 |
|
37831
387af9e5df70
hgweb: prevent triggering dummy href="#" handler
Yuya Nishihara <yuya@tcha.org>
parents:
37829
diff
changeset
|
339 |
function toggleLinewrap(event) { |
19430
5ec5097b4c0f
hgweb: add line wrapping switch to file source view
Alexander Plavin <me@aplavin.ru>
parents:
19428
diff
changeset
|
340 |
function getLinewrap() { |
5ec5097b4c0f
hgweb: add line wrapping switch to file source view
Alexander Plavin <me@aplavin.ru>
parents:
19428
diff
changeset
|
341 |
var nodes = document.getElementsByClassName('sourcelines'); |
5ec5097b4c0f
hgweb: add line wrapping switch to file source view
Alexander Plavin <me@aplavin.ru>
parents:
19428
diff
changeset
|
342 |
// if there are no such nodes, error is thrown here |
5ec5097b4c0f
hgweb: add line wrapping switch to file source view
Alexander Plavin <me@aplavin.ru>
parents:
19428
diff
changeset
|
343 |
return nodes[0].classList.contains('wrap'); |
5ec5097b4c0f
hgweb: add line wrapping switch to file source view
Alexander Plavin <me@aplavin.ru>
parents:
19428
diff
changeset
|
344 |
} |
5ec5097b4c0f
hgweb: add line wrapping switch to file source view
Alexander Plavin <me@aplavin.ru>
parents:
19428
diff
changeset
|
345 |
|
5ec5097b4c0f
hgweb: add line wrapping switch to file source view
Alexander Plavin <me@aplavin.ru>
parents:
19428
diff
changeset
|
346 |
function setLinewrap(enable) { |
5ec5097b4c0f
hgweb: add line wrapping switch to file source view
Alexander Plavin <me@aplavin.ru>
parents:
19428
diff
changeset
|
347 |
var nodes = document.getElementsByClassName('sourcelines'); |
35065
5f82e26cbed1
hgweb: fix jshint issues in mercurial.js
Anton Shestakov <av6@dwimlabs.net>
parents:
34392
diff
changeset
|
348 |
var i; |
5f82e26cbed1
hgweb: fix jshint issues in mercurial.js
Anton Shestakov <av6@dwimlabs.net>
parents:
34392
diff
changeset
|
349 |
for (i = 0; i < nodes.length; i++) { |
19430
5ec5097b4c0f
hgweb: add line wrapping switch to file source view
Alexander Plavin <me@aplavin.ru>
parents:
19428
diff
changeset
|
350 |
if (enable) { |
5ec5097b4c0f
hgweb: add line wrapping switch to file source view
Alexander Plavin <me@aplavin.ru>
parents:
19428
diff
changeset
|
351 |
nodes[i].classList.add('wrap'); |
5ec5097b4c0f
hgweb: add line wrapping switch to file source view
Alexander Plavin <me@aplavin.ru>
parents:
19428
diff
changeset
|
352 |
} else { |
5ec5097b4c0f
hgweb: add line wrapping switch to file source view
Alexander Plavin <me@aplavin.ru>
parents:
19428
diff
changeset
|
353 |
nodes[i].classList.remove('wrap'); |
5ec5097b4c0f
hgweb: add line wrapping switch to file source view
Alexander Plavin <me@aplavin.ru>
parents:
19428
diff
changeset
|
354 |
} |
5ec5097b4c0f
hgweb: add line wrapping switch to file source view
Alexander Plavin <me@aplavin.ru>
parents:
19428
diff
changeset
|
355 |
} |
5ec5097b4c0f
hgweb: add line wrapping switch to file source view
Alexander Plavin <me@aplavin.ru>
parents:
19428
diff
changeset
|
356 |
|
5ec5097b4c0f
hgweb: add line wrapping switch to file source view
Alexander Plavin <me@aplavin.ru>
parents:
19428
diff
changeset
|
357 |
var links = document.getElementsByClassName('linewraplink'); |
35065
5f82e26cbed1
hgweb: fix jshint issues in mercurial.js
Anton Shestakov <av6@dwimlabs.net>
parents:
34392
diff
changeset
|
358 |
for (i = 0; i < links.length; i++) { |
19430
5ec5097b4c0f
hgweb: add line wrapping switch to file source view
Alexander Plavin <me@aplavin.ru>
parents:
19428
diff
changeset
|
359 |
links[i].innerHTML = enable ? 'on' : 'off'; |
5ec5097b4c0f
hgweb: add line wrapping switch to file source view
Alexander Plavin <me@aplavin.ru>
parents:
19428
diff
changeset
|
360 |
} |
5ec5097b4c0f
hgweb: add line wrapping switch to file source view
Alexander Plavin <me@aplavin.ru>
parents:
19428
diff
changeset
|
361 |
} |
5ec5097b4c0f
hgweb: add line wrapping switch to file source view
Alexander Plavin <me@aplavin.ru>
parents:
19428
diff
changeset
|
362 |
|
5ec5097b4c0f
hgweb: add line wrapping switch to file source view
Alexander Plavin <me@aplavin.ru>
parents:
19428
diff
changeset
|
363 |
setLinewrap(!getLinewrap()); |
37831
387af9e5df70
hgweb: prevent triggering dummy href="#" handler
Yuya Nishihara <yuya@tcha.org>
parents:
37829
diff
changeset
|
364 |
event.preventDefault(); |
19430
5ec5097b4c0f
hgweb: add line wrapping switch to file source view
Alexander Plavin <me@aplavin.ru>
parents:
19428
diff
changeset
|
365 |
} |
19739
5bdc179e58c1
hgweb: add format javascript function
Alexander Plavin <alexander@plav.in>
parents:
19531
diff
changeset
|
366 |
|
5bdc179e58c1
hgweb: add format javascript function
Alexander Plavin <alexander@plav.in>
parents:
19531
diff
changeset
|
367 |
function format(str, replacements) { |
5bdc179e58c1
hgweb: add format javascript function
Alexander Plavin <alexander@plav.in>
parents:
19531
diff
changeset
|
368 |
return str.replace(/%(\w+)%/g, function(match, p1) { |
5bdc179e58c1
hgweb: add format javascript function
Alexander Plavin <alexander@plav.in>
parents:
19531
diff
changeset
|
369 |
return String(replacements[p1]); |
5bdc179e58c1
hgweb: add format javascript function
Alexander Plavin <alexander@plav.in>
parents:
19531
diff
changeset
|
370 |
}); |
5bdc179e58c1
hgweb: add format javascript function
Alexander Plavin <alexander@plav.in>
parents:
19531
diff
changeset
|
371 |
} |
19740
2228bd109706
hgweb: add makeRequest javascript function
Alexander Plavin <alexander@plav.in>
parents:
19739
diff
changeset
|
372 |
|
2228bd109706
hgweb: add makeRequest javascript function
Alexander Plavin <alexander@plav.in>
parents:
19739
diff
changeset
|
373 |
function makeRequest(url, method, onstart, onsuccess, onerror, oncomplete) { |
35181
69a865dc2ada
hgweb: define locally used variables as actually local in mercurial.js
Anton Shestakov <av6@dwimlabs.net>
parents:
35180
diff
changeset
|
374 |
var xhr = new XMLHttpRequest(); |
35180
018aac6d7cb0
hgweb: rename an instance of XMLHttpRequest to xhr in mercurial.js
Anton Shestakov <av6@dwimlabs.net>
parents:
35179
diff
changeset
|
375 |
xhr.onreadystatechange = function() { |
018aac6d7cb0
hgweb: rename an instance of XMLHttpRequest to xhr in mercurial.js
Anton Shestakov <av6@dwimlabs.net>
parents:
35179
diff
changeset
|
376 |
if (xhr.readyState === 4) { |
19740
2228bd109706
hgweb: add makeRequest javascript function
Alexander Plavin <alexander@plav.in>
parents:
19739
diff
changeset
|
377 |
try { |
35180
018aac6d7cb0
hgweb: rename an instance of XMLHttpRequest to xhr in mercurial.js
Anton Shestakov <av6@dwimlabs.net>
parents:
35179
diff
changeset
|
378 |
if (xhr.status === 200) { |
018aac6d7cb0
hgweb: rename an instance of XMLHttpRequest to xhr in mercurial.js
Anton Shestakov <av6@dwimlabs.net>
parents:
35179
diff
changeset
|
379 |
onsuccess(xhr.responseText); |
19740
2228bd109706
hgweb: add makeRequest javascript function
Alexander Plavin <alexander@plav.in>
parents:
19739
diff
changeset
|
380 |
} else { |
2228bd109706
hgweb: add makeRequest javascript function
Alexander Plavin <alexander@plav.in>
parents:
19739
diff
changeset
|
381 |
throw 'server error'; |
2228bd109706
hgweb: add makeRequest javascript function
Alexander Plavin <alexander@plav.in>
parents:
19739
diff
changeset
|
382 |
} |
2228bd109706
hgweb: add makeRequest javascript function
Alexander Plavin <alexander@plav.in>
parents:
19739
diff
changeset
|
383 |
} catch (e) { |
2228bd109706
hgweb: add makeRequest javascript function
Alexander Plavin <alexander@plav.in>
parents:
19739
diff
changeset
|
384 |
onerror(e); |
2228bd109706
hgweb: add makeRequest javascript function
Alexander Plavin <alexander@plav.in>
parents:
19739
diff
changeset
|
385 |
} finally { |
2228bd109706
hgweb: add makeRequest javascript function
Alexander Plavin <alexander@plav.in>
parents:
19739
diff
changeset
|
386 |
oncomplete(); |
2228bd109706
hgweb: add makeRequest javascript function
Alexander Plavin <alexander@plav.in>
parents:
19739
diff
changeset
|
387 |
} |
2228bd109706
hgweb: add makeRequest javascript function
Alexander Plavin <alexander@plav.in>
parents:
19739
diff
changeset
|
388 |
} |
2228bd109706
hgweb: add makeRequest javascript function
Alexander Plavin <alexander@plav.in>
parents:
19739
diff
changeset
|
389 |
}; |
2228bd109706
hgweb: add makeRequest javascript function
Alexander Plavin <alexander@plav.in>
parents:
19739
diff
changeset
|
390 |
|
35180
018aac6d7cb0
hgweb: rename an instance of XMLHttpRequest to xhr in mercurial.js
Anton Shestakov <av6@dwimlabs.net>
parents:
35179
diff
changeset
|
391 |
xhr.open(method, url); |
018aac6d7cb0
hgweb: rename an instance of XMLHttpRequest to xhr in mercurial.js
Anton Shestakov <av6@dwimlabs.net>
parents:
35179
diff
changeset
|
392 |
xhr.overrideMimeType("text/xhtml; charset=" + document.characterSet.toLowerCase()); |
018aac6d7cb0
hgweb: rename an instance of XMLHttpRequest to xhr in mercurial.js
Anton Shestakov <av6@dwimlabs.net>
parents:
35179
diff
changeset
|
393 |
xhr.send(); |
19740
2228bd109706
hgweb: add makeRequest javascript function
Alexander Plavin <alexander@plav.in>
parents:
19739
diff
changeset
|
394 |
onstart(); |
35180
018aac6d7cb0
hgweb: rename an instance of XMLHttpRequest to xhr in mercurial.js
Anton Shestakov <av6@dwimlabs.net>
parents:
35179
diff
changeset
|
395 |
return xhr; |
19740
2228bd109706
hgweb: add makeRequest javascript function
Alexander Plavin <alexander@plav.in>
parents:
19739
diff
changeset
|
396 |
} |
19741
2a9a21e1e1db
hgweb: add docFromHTML javascript function
Alexander Plavin <alexander@plav.in>
parents:
19740
diff
changeset
|
397 |
|
19742
ac68009c31a4
hgweb: add removeByClassName javascript function
Alexander Plavin <alexander@plav.in>
parents:
19741
diff
changeset
|
398 |
function removeByClassName(className) { |
ac68009c31a4
hgweb: add removeByClassName javascript function
Alexander Plavin <alexander@plav.in>
parents:
19741
diff
changeset
|
399 |
var nodes = document.getElementsByClassName(className); |
ac68009c31a4
hgweb: add removeByClassName javascript function
Alexander Plavin <alexander@plav.in>
parents:
19741
diff
changeset
|
400 |
while (nodes.length) { |
ac68009c31a4
hgweb: add removeByClassName javascript function
Alexander Plavin <alexander@plav.in>
parents:
19741
diff
changeset
|
401 |
nodes[0].parentNode.removeChild(nodes[0]); |
ac68009c31a4
hgweb: add removeByClassName javascript function
Alexander Plavin <alexander@plav.in>
parents:
19741
diff
changeset
|
402 |
} |
ac68009c31a4
hgweb: add removeByClassName javascript function
Alexander Plavin <alexander@plav.in>
parents:
19741
diff
changeset
|
403 |
} |
ac68009c31a4
hgweb: add removeByClassName javascript function
Alexander Plavin <alexander@plav.in>
parents:
19741
diff
changeset
|
404 |
|
19741
2a9a21e1e1db
hgweb: add docFromHTML javascript function
Alexander Plavin <alexander@plav.in>
parents:
19740
diff
changeset
|
405 |
function docFromHTML(html) { |
2a9a21e1e1db
hgweb: add docFromHTML javascript function
Alexander Plavin <alexander@plav.in>
parents:
19740
diff
changeset
|
406 |
var doc = document.implementation.createHTMLDocument(''); |
2a9a21e1e1db
hgweb: add docFromHTML javascript function
Alexander Plavin <alexander@plav.in>
parents:
19740
diff
changeset
|
407 |
doc.documentElement.innerHTML = html; |
2a9a21e1e1db
hgweb: add docFromHTML javascript function
Alexander Plavin <alexander@plav.in>
parents:
19740
diff
changeset
|
408 |
return doc; |
2a9a21e1e1db
hgweb: add docFromHTML javascript function
Alexander Plavin <alexander@plav.in>
parents:
19740
diff
changeset
|
409 |
} |
19743
fdd41257def8
hgweb: add appendFormatHTML javascript function
Alexander Plavin <alexander@plav.in>
parents:
19742
diff
changeset
|
410 |
|
fdd41257def8
hgweb: add appendFormatHTML javascript function
Alexander Plavin <alexander@plav.in>
parents:
19742
diff
changeset
|
411 |
function appendFormatHTML(element, formatStr, replacements) { |
fdd41257def8
hgweb: add appendFormatHTML javascript function
Alexander Plavin <alexander@plav.in>
parents:
19742
diff
changeset
|
412 |
element.insertAdjacentHTML('beforeend', format(formatStr, replacements)); |
fdd41257def8
hgweb: add appendFormatHTML javascript function
Alexander Plavin <alexander@plav.in>
parents:
19742
diff
changeset
|
413 |
} |
19746
9ad7dd9574a9
hgweb: add ajaxScrollInit function, which does the ajax requests and processing
Alexander Plavin <alexander@plav.in>
parents:
19743
diff
changeset
|
414 |
|
35226
fcc96cf0983d
hgweb: adopt child nodes in ajaxScrollInit on /graph pages too
Anton Shestakov <av6@dwimlabs.net>
parents:
35182
diff
changeset
|
415 |
function adoptChildren(from, to) { |
fcc96cf0983d
hgweb: adopt child nodes in ajaxScrollInit on /graph pages too
Anton Shestakov <av6@dwimlabs.net>
parents:
35182
diff
changeset
|
416 |
var nodes = from.children; |
fcc96cf0983d
hgweb: adopt child nodes in ajaxScrollInit on /graph pages too
Anton Shestakov <av6@dwimlabs.net>
parents:
35182
diff
changeset
|
417 |
var curClass = 'c' + Date.now(); |
fcc96cf0983d
hgweb: adopt child nodes in ajaxScrollInit on /graph pages too
Anton Shestakov <av6@dwimlabs.net>
parents:
35182
diff
changeset
|
418 |
while (nodes.length) { |
fcc96cf0983d
hgweb: adopt child nodes in ajaxScrollInit on /graph pages too
Anton Shestakov <av6@dwimlabs.net>
parents:
35182
diff
changeset
|
419 |
var node = nodes[0]; |
fcc96cf0983d
hgweb: adopt child nodes in ajaxScrollInit on /graph pages too
Anton Shestakov <av6@dwimlabs.net>
parents:
35182
diff
changeset
|
420 |
node = document.adoptNode(node); |
fcc96cf0983d
hgweb: adopt child nodes in ajaxScrollInit on /graph pages too
Anton Shestakov <av6@dwimlabs.net>
parents:
35182
diff
changeset
|
421 |
node.classList.add(curClass); |
fcc96cf0983d
hgweb: adopt child nodes in ajaxScrollInit on /graph pages too
Anton Shestakov <av6@dwimlabs.net>
parents:
35182
diff
changeset
|
422 |
to.appendChild(node); |
fcc96cf0983d
hgweb: adopt child nodes in ajaxScrollInit on /graph pages too
Anton Shestakov <av6@dwimlabs.net>
parents:
35182
diff
changeset
|
423 |
} |
fcc96cf0983d
hgweb: adopt child nodes in ajaxScrollInit on /graph pages too
Anton Shestakov <av6@dwimlabs.net>
parents:
35182
diff
changeset
|
424 |
process_dates('.' + curClass); |
fcc96cf0983d
hgweb: adopt child nodes in ajaxScrollInit on /graph pages too
Anton Shestakov <av6@dwimlabs.net>
parents:
35182
diff
changeset
|
425 |
} |
fcc96cf0983d
hgweb: adopt child nodes in ajaxScrollInit on /graph pages too
Anton Shestakov <av6@dwimlabs.net>
parents:
35182
diff
changeset
|
426 |
|
19746
9ad7dd9574a9
hgweb: add ajaxScrollInit function, which does the ajax requests and processing
Alexander Plavin <alexander@plav.in>
parents:
19743
diff
changeset
|
427 |
function ajaxScrollInit(urlFormat, |
19781
74564c90026b
hgweb: make infinite scroll handling more generic and extensible
Alexander Plavin <alexander@plav.in>
parents:
19780
diff
changeset
|
428 |
nextPageVar, |
74564c90026b
hgweb: make infinite scroll handling more generic and extensible
Alexander Plavin <alexander@plav.in>
parents:
19780
diff
changeset
|
429 |
nextPageVarGet, |
19746
9ad7dd9574a9
hgweb: add ajaxScrollInit function, which does the ajax requests and processing
Alexander Plavin <alexander@plav.in>
parents:
19743
diff
changeset
|
430 |
containerSelector, |
19782
8123f50555ff
hgweb: add graph mode of ajax response processing
Alexander Plavin <alexander@plav.in>
parents:
19781
diff
changeset
|
431 |
messageFormat, |
8123f50555ff
hgweb: add graph mode of ajax response processing
Alexander Plavin <alexander@plav.in>
parents:
19781
diff
changeset
|
432 |
mode) { |
35181
69a865dc2ada
hgweb: define locally used variables as actually local in mercurial.js
Anton Shestakov <av6@dwimlabs.net>
parents:
35180
diff
changeset
|
433 |
var updateInitiated = false; |
69a865dc2ada
hgweb: define locally used variables as actually local in mercurial.js
Anton Shestakov <av6@dwimlabs.net>
parents:
35180
diff
changeset
|
434 |
var container = document.querySelector(containerSelector); |
19746
9ad7dd9574a9
hgweb: add ajaxScrollInit function, which does the ajax requests and processing
Alexander Plavin <alexander@plav.in>
parents:
19743
diff
changeset
|
435 |
|
9ad7dd9574a9
hgweb: add ajaxScrollInit function, which does the ajax requests and processing
Alexander Plavin <alexander@plav.in>
parents:
19743
diff
changeset
|
436 |
function scrollHandler() { |
9ad7dd9574a9
hgweb: add ajaxScrollInit function, which does the ajax requests and processing
Alexander Plavin <alexander@plav.in>
parents:
19743
diff
changeset
|
437 |
if (updateInitiated) { |
9ad7dd9574a9
hgweb: add ajaxScrollInit function, which does the ajax requests and processing
Alexander Plavin <alexander@plav.in>
parents:
19743
diff
changeset
|
438 |
return; |
9ad7dd9574a9
hgweb: add ajaxScrollInit function, which does the ajax requests and processing
Alexander Plavin <alexander@plav.in>
parents:
19743
diff
changeset
|
439 |
} |
9ad7dd9574a9
hgweb: add ajaxScrollInit function, which does the ajax requests and processing
Alexander Plavin <alexander@plav.in>
parents:
19743
diff
changeset
|
440 |
|
9ad7dd9574a9
hgweb: add ajaxScrollInit function, which does the ajax requests and processing
Alexander Plavin <alexander@plav.in>
parents:
19743
diff
changeset
|
441 |
var scrollHeight = document.documentElement.scrollHeight; |
9ad7dd9574a9
hgweb: add ajaxScrollInit function, which does the ajax requests and processing
Alexander Plavin <alexander@plav.in>
parents:
19743
diff
changeset
|
442 |
var clientHeight = document.documentElement.clientHeight; |
35065
5f82e26cbed1
hgweb: fix jshint issues in mercurial.js
Anton Shestakov <av6@dwimlabs.net>
parents:
34392
diff
changeset
|
443 |
var scrollTop = document.body.scrollTop || document.documentElement.scrollTop; |
19746
9ad7dd9574a9
hgweb: add ajaxScrollInit function, which does the ajax requests and processing
Alexander Plavin <alexander@plav.in>
parents:
19743
diff
changeset
|
444 |
|
9ad7dd9574a9
hgweb: add ajaxScrollInit function, which does the ajax requests and processing
Alexander Plavin <alexander@plav.in>
parents:
19743
diff
changeset
|
445 |
if (scrollHeight - (scrollTop + clientHeight) < 50) { |
9ad7dd9574a9
hgweb: add ajaxScrollInit function, which does the ajax requests and processing
Alexander Plavin <alexander@plav.in>
parents:
19743
diff
changeset
|
446 |
updateInitiated = true; |
19756
54981b899406
hgweb: show message when an error occured during ajax loading
Alexander Plavin <alexander@plav.in>
parents:
19755
diff
changeset
|
447 |
removeByClassName('scroll-loading-error'); |
19760
2ac4e89ad769
hgweb: add CSS class to the last entry on a page
Alexander Plavin <alexander@plav.in>
parents:
19756
diff
changeset
|
448 |
container.lastElementChild.classList.add('scroll-separator'); |
19746
9ad7dd9574a9
hgweb: add ajaxScrollInit function, which does the ajax requests and processing
Alexander Plavin <alexander@plav.in>
parents:
19743
diff
changeset
|
449 |
|
19781
74564c90026b
hgweb: make infinite scroll handling more generic and extensible
Alexander Plavin <alexander@plav.in>
parents:
19780
diff
changeset
|
450 |
if (!nextPageVar) { |
19754
c35e8805cf53
hgweb: show a message when there are no more entries in the list
Alexander Plavin <alexander@plav.in>
parents:
19746
diff
changeset
|
451 |
var message = { |
26832
3ed635cb108e
hgweb: escape class keyword when used as a js object property (issue4913)
Anton Shestakov <av6@dwimlabs.net>
parents:
20973
diff
changeset
|
452 |
'class': 'scroll-loading-info', |
19754
c35e8805cf53
hgweb: show a message when there are no more entries in the list
Alexander Plavin <alexander@plav.in>
parents:
19746
diff
changeset
|
453 |
text: 'No more entries' |
c35e8805cf53
hgweb: show a message when there are no more entries in the list
Alexander Plavin <alexander@plav.in>
parents:
19746
diff
changeset
|
454 |
}; |
c35e8805cf53
hgweb: show a message when there are no more entries in the list
Alexander Plavin <alexander@plav.in>
parents:
19746
diff
changeset
|
455 |
appendFormatHTML(container, messageFormat, message); |
19746
9ad7dd9574a9
hgweb: add ajaxScrollInit function, which does the ajax requests and processing
Alexander Plavin <alexander@plav.in>
parents:
19743
diff
changeset
|
456 |
return; |
9ad7dd9574a9
hgweb: add ajaxScrollInit function, which does the ajax requests and processing
Alexander Plavin <alexander@plav.in>
parents:
19743
diff
changeset
|
457 |
} |
9ad7dd9574a9
hgweb: add ajaxScrollInit function, which does the ajax requests and processing
Alexander Plavin <alexander@plav.in>
parents:
19743
diff
changeset
|
458 |
|
9ad7dd9574a9
hgweb: add ajaxScrollInit function, which does the ajax requests and processing
Alexander Plavin <alexander@plav.in>
parents:
19743
diff
changeset
|
459 |
makeRequest( |
19781
74564c90026b
hgweb: make infinite scroll handling more generic and extensible
Alexander Plavin <alexander@plav.in>
parents:
19780
diff
changeset
|
460 |
format(urlFormat, {next: nextPageVar}), |
19746
9ad7dd9574a9
hgweb: add ajaxScrollInit function, which does the ajax requests and processing
Alexander Plavin <alexander@plav.in>
parents:
19743
diff
changeset
|
461 |
'GET', |
9ad7dd9574a9
hgweb: add ajaxScrollInit function, which does the ajax requests and processing
Alexander Plavin <alexander@plav.in>
parents:
19743
diff
changeset
|
462 |
function onstart() { |
19755
00b9f6aab761
hgweb: show loading indicator while an ajax request is in process
Alexander Plavin <alexander@plav.in>
parents:
19754
diff
changeset
|
463 |
var message = { |
26832
3ed635cb108e
hgweb: escape class keyword when used as a js object property (issue4913)
Anton Shestakov <av6@dwimlabs.net>
parents:
20973
diff
changeset
|
464 |
'class': 'scroll-loading', |
19755
00b9f6aab761
hgweb: show loading indicator while an ajax request is in process
Alexander Plavin <alexander@plav.in>
parents:
19754
diff
changeset
|
465 |
text: 'Loading...' |
00b9f6aab761
hgweb: show loading indicator while an ajax request is in process
Alexander Plavin <alexander@plav.in>
parents:
19754
diff
changeset
|
466 |
}; |
00b9f6aab761
hgweb: show loading indicator while an ajax request is in process
Alexander Plavin <alexander@plav.in>
parents:
19754
diff
changeset
|
467 |
appendFormatHTML(container, messageFormat, message); |
19746
9ad7dd9574a9
hgweb: add ajaxScrollInit function, which does the ajax requests and processing
Alexander Plavin <alexander@plav.in>
parents:
19743
diff
changeset
|
468 |
}, |
9ad7dd9574a9
hgweb: add ajaxScrollInit function, which does the ajax requests and processing
Alexander Plavin <alexander@plav.in>
parents:
19743
diff
changeset
|
469 |
function onsuccess(htmlText) { |
35226
fcc96cf0983d
hgweb: adopt child nodes in ajaxScrollInit on /graph pages too
Anton Shestakov <av6@dwimlabs.net>
parents:
35182
diff
changeset
|
470 |
var doc = docFromHTML(htmlText); |
fcc96cf0983d
hgweb: adopt child nodes in ajaxScrollInit on /graph pages too
Anton Shestakov <av6@dwimlabs.net>
parents:
35182
diff
changeset
|
471 |
|
35178
ccf86aa5797c
hgweb: use strict equals in mercurial.js
Anton Shestakov <av6@dwimlabs.net>
parents:
35156
diff
changeset
|
472 |
if (mode === 'graph') { |
35181
69a865dc2ada
hgweb: define locally used variables as actually local in mercurial.js
Anton Shestakov <av6@dwimlabs.net>
parents:
35180
diff
changeset
|
473 |
var graph = window.graph; |
19782
8123f50555ff
hgweb: add graph mode of ajax response processing
Alexander Plavin <alexander@plav.in>
parents:
19781
diff
changeset
|
474 |
var dataStr = htmlText.match(/^\s*var data = (.*);$/m)[1]; |
19957
80aa912dcb2d
hgweb: add missing semicolon
Takumi IINO <trot.thunder@gmail.com>
parents:
19907
diff
changeset
|
475 |
var data = JSON.parse(dataStr); |
19782
8123f50555ff
hgweb: add graph mode of ajax response processing
Alexander Plavin <alexander@plav.in>
parents:
19781
diff
changeset
|
476 |
graph.reset(); |
35226
fcc96cf0983d
hgweb: adopt child nodes in ajaxScrollInit on /graph pages too
Anton Shestakov <av6@dwimlabs.net>
parents:
35182
diff
changeset
|
477 |
adoptChildren(doc.querySelector('#graphnodes'), container.querySelector('#graphnodes')); |
19782
8123f50555ff
hgweb: add graph mode of ajax response processing
Alexander Plavin <alexander@plav.in>
parents:
19781
diff
changeset
|
478 |
graph.render(data); |
8123f50555ff
hgweb: add graph mode of ajax response processing
Alexander Plavin <alexander@plav.in>
parents:
19781
diff
changeset
|
479 |
} else { |
35226
fcc96cf0983d
hgweb: adopt child nodes in ajaxScrollInit on /graph pages too
Anton Shestakov <av6@dwimlabs.net>
parents:
35182
diff
changeset
|
480 |
adoptChildren(doc.querySelector(containerSelector), container); |
19746
9ad7dd9574a9
hgweb: add ajaxScrollInit function, which does the ajax requests and processing
Alexander Plavin <alexander@plav.in>
parents:
19743
diff
changeset
|
481 |
} |
19907
aebfbb68fe92
hgweb: fix unstoppable loading of graph when no more results
Alexander Plavin <alexander@plav.in>
parents:
19859
diff
changeset
|
482 |
|
35654
59c842a3d1e1
hgweb: remove unused second argument of nextPageVarGet()
Anton Shestakov <av6@dwimlabs.net>
parents:
35605
diff
changeset
|
483 |
nextPageVar = nextPageVarGet(htmlText); |
19746
9ad7dd9574a9
hgweb: add ajaxScrollInit function, which does the ajax requests and processing
Alexander Plavin <alexander@plav.in>
parents:
19743
diff
changeset
|
484 |
}, |
9ad7dd9574a9
hgweb: add ajaxScrollInit function, which does the ajax requests and processing
Alexander Plavin <alexander@plav.in>
parents:
19743
diff
changeset
|
485 |
function onerror(errorText) { |
19756
54981b899406
hgweb: show message when an error occured during ajax loading
Alexander Plavin <alexander@plav.in>
parents:
19755
diff
changeset
|
486 |
var message = { |
26832
3ed635cb108e
hgweb: escape class keyword when used as a js object property (issue4913)
Anton Shestakov <av6@dwimlabs.net>
parents:
20973
diff
changeset
|
487 |
'class': 'scroll-loading-error', |
19756
54981b899406
hgweb: show message when an error occured during ajax loading
Alexander Plavin <alexander@plav.in>
parents:
19755
diff
changeset
|
488 |
text: 'Error: ' + errorText |
54981b899406
hgweb: show message when an error occured during ajax loading
Alexander Plavin <alexander@plav.in>
parents:
19755
diff
changeset
|
489 |
}; |
54981b899406
hgweb: show message when an error occured during ajax loading
Alexander Plavin <alexander@plav.in>
parents:
19755
diff
changeset
|
490 |
appendFormatHTML(container, messageFormat, message); |
19746
9ad7dd9574a9
hgweb: add ajaxScrollInit function, which does the ajax requests and processing
Alexander Plavin <alexander@plav.in>
parents:
19743
diff
changeset
|
491 |
}, |
9ad7dd9574a9
hgweb: add ajaxScrollInit function, which does the ajax requests and processing
Alexander Plavin <alexander@plav.in>
parents:
19743
diff
changeset
|
492 |
function oncomplete() { |
19755
00b9f6aab761
hgweb: show loading indicator while an ajax request is in process
Alexander Plavin <alexander@plav.in>
parents:
19754
diff
changeset
|
493 |
removeByClassName('scroll-loading'); |
19746
9ad7dd9574a9
hgweb: add ajaxScrollInit function, which does the ajax requests and processing
Alexander Plavin <alexander@plav.in>
parents:
19743
diff
changeset
|
494 |
updateInitiated = false; |
9ad7dd9574a9
hgweb: add ajaxScrollInit function, which does the ajax requests and processing
Alexander Plavin <alexander@plav.in>
parents:
19743
diff
changeset
|
495 |
scrollHandler(); |
9ad7dd9574a9
hgweb: add ajaxScrollInit function, which does the ajax requests and processing
Alexander Plavin <alexander@plav.in>
parents:
19743
diff
changeset
|
496 |
} |
9ad7dd9574a9
hgweb: add ajaxScrollInit function, which does the ajax requests and processing
Alexander Plavin <alexander@plav.in>
parents:
19743
diff
changeset
|
497 |
); |
9ad7dd9574a9
hgweb: add ajaxScrollInit function, which does the ajax requests and processing
Alexander Plavin <alexander@plav.in>
parents:
19743
diff
changeset
|
498 |
} |
9ad7dd9574a9
hgweb: add ajaxScrollInit function, which does the ajax requests and processing
Alexander Plavin <alexander@plav.in>
parents:
19743
diff
changeset
|
499 |
} |
9ad7dd9574a9
hgweb: add ajaxScrollInit function, which does the ajax requests and processing
Alexander Plavin <alexander@plav.in>
parents:
19743
diff
changeset
|
500 |
|
9ad7dd9574a9
hgweb: add ajaxScrollInit function, which does the ajax requests and processing
Alexander Plavin <alexander@plav.in>
parents:
19743
diff
changeset
|
501 |
window.addEventListener('scroll', scrollHandler); |
9ad7dd9574a9
hgweb: add ajaxScrollInit function, which does the ajax requests and processing
Alexander Plavin <alexander@plav.in>
parents:
19743
diff
changeset
|
502 |
window.addEventListener('resize', scrollHandler); |
9ad7dd9574a9
hgweb: add ajaxScrollInit function, which does the ajax requests and processing
Alexander Plavin <alexander@plav.in>
parents:
19743
diff
changeset
|
503 |
scrollHandler(); |
9ad7dd9574a9
hgweb: add ajaxScrollInit function, which does the ajax requests and processing
Alexander Plavin <alexander@plav.in>
parents:
19743
diff
changeset
|
504 |
} |
30765
eb7de21b15be
hgweb: call process_dates() via DOM event listener
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27934
diff
changeset
|
505 |
|
34392
6797f1fbc642
hgweb: add HTML elements to control whitespace settings for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30765
diff
changeset
|
506 |
function renderDiffOptsForm() { |
6797f1fbc642
hgweb: add HTML elements to control whitespace settings for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30765
diff
changeset
|
507 |
// We use URLSearchParams for query string manipulation. Old browsers don't |
6797f1fbc642
hgweb: add HTML elements to control whitespace settings for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30765
diff
changeset
|
508 |
// support this API. |
6797f1fbc642
hgweb: add HTML elements to control whitespace settings for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30765
diff
changeset
|
509 |
if (!("URLSearchParams" in window)) { |
6797f1fbc642
hgweb: add HTML elements to control whitespace settings for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30765
diff
changeset
|
510 |
return; |
6797f1fbc642
hgweb: add HTML elements to control whitespace settings for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30765
diff
changeset
|
511 |
} |
6797f1fbc642
hgweb: add HTML elements to control whitespace settings for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30765
diff
changeset
|
512 |
|
6797f1fbc642
hgweb: add HTML elements to control whitespace settings for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30765
diff
changeset
|
513 |
var form = document.getElementById("diffopts-form"); |
6797f1fbc642
hgweb: add HTML elements to control whitespace settings for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30765
diff
changeset
|
514 |
|
6797f1fbc642
hgweb: add HTML elements to control whitespace settings for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30765
diff
changeset
|
515 |
var KEYS = [ |
6797f1fbc642
hgweb: add HTML elements to control whitespace settings for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30765
diff
changeset
|
516 |
"ignorews", |
6797f1fbc642
hgweb: add HTML elements to control whitespace settings for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30765
diff
changeset
|
517 |
"ignorewsamount", |
6797f1fbc642
hgweb: add HTML elements to control whitespace settings for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30765
diff
changeset
|
518 |
"ignorewseol", |
6797f1fbc642
hgweb: add HTML elements to control whitespace settings for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30765
diff
changeset
|
519 |
"ignoreblanklines", |
6797f1fbc642
hgweb: add HTML elements to control whitespace settings for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30765
diff
changeset
|
520 |
]; |
6797f1fbc642
hgweb: add HTML elements to control whitespace settings for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30765
diff
changeset
|
521 |
|
35182
1207a50a6dc3
hgweb: look up "URLSearchParams" in "window" to work around jshint issues
Anton Shestakov <av6@dwimlabs.net>
parents:
35181
diff
changeset
|
522 |
var urlParams = new window.URLSearchParams(window.location.search); |
34392
6797f1fbc642
hgweb: add HTML elements to control whitespace settings for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30765
diff
changeset
|
523 |
|
6797f1fbc642
hgweb: add HTML elements to control whitespace settings for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30765
diff
changeset
|
524 |
function updateAndRefresh(e) { |
6797f1fbc642
hgweb: add HTML elements to control whitespace settings for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30765
diff
changeset
|
525 |
var checkbox = e.target; |
6797f1fbc642
hgweb: add HTML elements to control whitespace settings for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30765
diff
changeset
|
526 |
var name = checkbox.id.substr(0, checkbox.id.indexOf("-")); |
6797f1fbc642
hgweb: add HTML elements to control whitespace settings for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30765
diff
changeset
|
527 |
urlParams.set(name, checkbox.checked ? "1" : "0"); |
6797f1fbc642
hgweb: add HTML elements to control whitespace settings for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30765
diff
changeset
|
528 |
window.location.search = urlParams.toString(); |
6797f1fbc642
hgweb: add HTML elements to control whitespace settings for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30765
diff
changeset
|
529 |
} |
6797f1fbc642
hgweb: add HTML elements to control whitespace settings for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30765
diff
changeset
|
530 |
|
35178
ccf86aa5797c
hgweb: use strict equals in mercurial.js
Anton Shestakov <av6@dwimlabs.net>
parents:
35156
diff
changeset
|
531 |
var allChecked = form.getAttribute("data-ignorews") === "1"; |
34392
6797f1fbc642
hgweb: add HTML elements to control whitespace settings for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30765
diff
changeset
|
532 |
|
6797f1fbc642
hgweb: add HTML elements to control whitespace settings for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30765
diff
changeset
|
533 |
for (var i = 0; i < KEYS.length; i++) { |
6797f1fbc642
hgweb: add HTML elements to control whitespace settings for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30765
diff
changeset
|
534 |
var key = KEYS[i]; |
6797f1fbc642
hgweb: add HTML elements to control whitespace settings for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30765
diff
changeset
|
535 |
|
6797f1fbc642
hgweb: add HTML elements to control whitespace settings for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30765
diff
changeset
|
536 |
var checkbox = document.getElementById(key + "-checkbox"); |
6797f1fbc642
hgweb: add HTML elements to control whitespace settings for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30765
diff
changeset
|
537 |
if (!checkbox) { |
6797f1fbc642
hgweb: add HTML elements to control whitespace settings for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30765
diff
changeset
|
538 |
continue; |
6797f1fbc642
hgweb: add HTML elements to control whitespace settings for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30765
diff
changeset
|
539 |
} |
6797f1fbc642
hgweb: add HTML elements to control whitespace settings for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30765
diff
changeset
|
540 |
|
35181
69a865dc2ada
hgweb: define locally used variables as actually local in mercurial.js
Anton Shestakov <av6@dwimlabs.net>
parents:
35180
diff
changeset
|
541 |
var currentValue = form.getAttribute("data-" + key); |
35178
ccf86aa5797c
hgweb: use strict equals in mercurial.js
Anton Shestakov <av6@dwimlabs.net>
parents:
35156
diff
changeset
|
542 |
checkbox.checked = currentValue !== "0"; |
34392
6797f1fbc642
hgweb: add HTML elements to control whitespace settings for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30765
diff
changeset
|
543 |
|
6797f1fbc642
hgweb: add HTML elements to control whitespace settings for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30765
diff
changeset
|
544 |
// ignorews implies ignorewsamount and ignorewseol. |
35178
ccf86aa5797c
hgweb: use strict equals in mercurial.js
Anton Shestakov <av6@dwimlabs.net>
parents:
35156
diff
changeset
|
545 |
if (allChecked && (key === "ignorewsamount" || key === "ignorewseol")) { |
34392
6797f1fbc642
hgweb: add HTML elements to control whitespace settings for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30765
diff
changeset
|
546 |
checkbox.checked = true; |
6797f1fbc642
hgweb: add HTML elements to control whitespace settings for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30765
diff
changeset
|
547 |
checkbox.disabled = true; |
6797f1fbc642
hgweb: add HTML elements to control whitespace settings for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30765
diff
changeset
|
548 |
} |
6797f1fbc642
hgweb: add HTML elements to control whitespace settings for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30765
diff
changeset
|
549 |
|
6797f1fbc642
hgweb: add HTML elements to control whitespace settings for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30765
diff
changeset
|
550 |
checkbox.addEventListener("change", updateAndRefresh, false); |
6797f1fbc642
hgweb: add HTML elements to control whitespace settings for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30765
diff
changeset
|
551 |
} |
6797f1fbc642
hgweb: add HTML elements to control whitespace settings for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30765
diff
changeset
|
552 |
|
6797f1fbc642
hgweb: add HTML elements to control whitespace settings for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30765
diff
changeset
|
553 |
form.style.display = 'block'; |
6797f1fbc642
hgweb: add HTML elements to control whitespace settings for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30765
diff
changeset
|
554 |
} |
6797f1fbc642
hgweb: add HTML elements to control whitespace settings for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30765
diff
changeset
|
555 |
|
37829
2ead51dcde71
paper: don't register click handlers with inline javascript (issue5812)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35654
diff
changeset
|
556 |
function addDiffStatToggle() { |
2ead51dcde71
paper: don't register click handlers with inline javascript (issue5812)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35654
diff
changeset
|
557 |
var els = document.getElementsByClassName("diffstattoggle"); |
2ead51dcde71
paper: don't register click handlers with inline javascript (issue5812)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35654
diff
changeset
|
558 |
|
2ead51dcde71
paper: don't register click handlers with inline javascript (issue5812)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35654
diff
changeset
|
559 |
for (var i = 0; i < els.length; i++) { |
2ead51dcde71
paper: don't register click handlers with inline javascript (issue5812)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35654
diff
changeset
|
560 |
els[i].addEventListener("click", toggleDiffstat, false); |
2ead51dcde71
paper: don't register click handlers with inline javascript (issue5812)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35654
diff
changeset
|
561 |
} |
2ead51dcde71
paper: don't register click handlers with inline javascript (issue5812)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35654
diff
changeset
|
562 |
} |
2ead51dcde71
paper: don't register click handlers with inline javascript (issue5812)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35654
diff
changeset
|
563 |
|
2ead51dcde71
paper: don't register click handlers with inline javascript (issue5812)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35654
diff
changeset
|
564 |
function addLineWrapToggle() { |
2ead51dcde71
paper: don't register click handlers with inline javascript (issue5812)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35654
diff
changeset
|
565 |
var els = document.getElementsByClassName("linewraptoggle"); |
2ead51dcde71
paper: don't register click handlers with inline javascript (issue5812)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35654
diff
changeset
|
566 |
|
2ead51dcde71
paper: don't register click handlers with inline javascript (issue5812)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35654
diff
changeset
|
567 |
for (var i = 0; i < els.length; i++) { |
2ead51dcde71
paper: don't register click handlers with inline javascript (issue5812)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35654
diff
changeset
|
568 |
var nodes = els[i].getElementsByClassName("linewraplink"); |
2ead51dcde71
paper: don't register click handlers with inline javascript (issue5812)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35654
diff
changeset
|
569 |
|
2ead51dcde71
paper: don't register click handlers with inline javascript (issue5812)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35654
diff
changeset
|
570 |
for (var j = 0; j < nodes.length; j++) { |
2ead51dcde71
paper: don't register click handlers with inline javascript (issue5812)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35654
diff
changeset
|
571 |
nodes[j].addEventListener("click", toggleLinewrap, false); |
2ead51dcde71
paper: don't register click handlers with inline javascript (issue5812)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35654
diff
changeset
|
572 |
} |
2ead51dcde71
paper: don't register click handlers with inline javascript (issue5812)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35654
diff
changeset
|
573 |
} |
2ead51dcde71
paper: don't register click handlers with inline javascript (issue5812)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35654
diff
changeset
|
574 |
} |
2ead51dcde71
paper: don't register click handlers with inline javascript (issue5812)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35654
diff
changeset
|
575 |
|
30765
eb7de21b15be
hgweb: call process_dates() via DOM event listener
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27934
diff
changeset
|
576 |
document.addEventListener('DOMContentLoaded', function() { |
eb7de21b15be
hgweb: call process_dates() via DOM event listener
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27934
diff
changeset
|
577 |
process_dates(); |
37829
2ead51dcde71
paper: don't register click handlers with inline javascript (issue5812)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35654
diff
changeset
|
578 |
addDiffStatToggle(); |
2ead51dcde71
paper: don't register click handlers with inline javascript (issue5812)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35654
diff
changeset
|
579 |
addLineWrapToggle(); |
30765
eb7de21b15be
hgweb: call process_dates() via DOM event listener
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27934
diff
changeset
|
580 |
}, false); |