##// END OF EJS Templates
hgweb: use strict equals in mercurial.js...
av6 -
r35158:ccf86aa5 default
parent child Browse files
Show More
@@ -1,487 +1,487 b''
1 // mercurial.js - JavaScript utility functions
1 // mercurial.js - JavaScript utility functions
2 //
2 //
3 // Rendering of branch DAGs on the client side
3 // Rendering of branch DAGs on the client side
4 // Display of elapsed time
4 // Display of elapsed time
5 // Show or hide diffstat
5 // Show or hide diffstat
6 //
6 //
7 // Copyright 2008 Dirkjan Ochtman <dirkjan AT ochtman DOT nl>
7 // Copyright 2008 Dirkjan Ochtman <dirkjan AT ochtman DOT nl>
8 // Copyright 2006 Alexander Schremmer <alex AT alexanderweb DOT de>
8 // Copyright 2006 Alexander Schremmer <alex AT alexanderweb DOT de>
9 //
9 //
10 // derived from code written by Scott James Remnant <scott@ubuntu.com>
10 // derived from code written by Scott James Remnant <scott@ubuntu.com>
11 // Copyright 2005 Canonical Ltd.
11 // Copyright 2005 Canonical Ltd.
12 //
12 //
13 // This software may be used and distributed according to the terms
13 // This software may be used and distributed according to the terms
14 // of the GNU General Public License, incorporated herein by reference.
14 // of the GNU General Public License, incorporated herein by reference.
15
15
16 var colors = [
16 var colors = [
17 [ 1.0, 0.0, 0.0 ],
17 [ 1.0, 0.0, 0.0 ],
18 [ 1.0, 1.0, 0.0 ],
18 [ 1.0, 1.0, 0.0 ],
19 [ 0.0, 1.0, 0.0 ],
19 [ 0.0, 1.0, 0.0 ],
20 [ 0.0, 1.0, 1.0 ],
20 [ 0.0, 1.0, 1.0 ],
21 [ 0.0, 0.0, 1.0 ],
21 [ 0.0, 0.0, 1.0 ],
22 [ 1.0, 0.0, 1.0 ]
22 [ 1.0, 0.0, 1.0 ]
23 ];
23 ];
24
24
25 function Graph() {
25 function Graph() {
26
26
27 this.canvas = document.getElementById('graph');
27 this.canvas = document.getElementById('graph');
28 if (window.G_vmlCanvasManager) this.canvas = window.G_vmlCanvasManager.initElement(this.canvas);
28 if (window.G_vmlCanvasManager) this.canvas = window.G_vmlCanvasManager.initElement(this.canvas);
29 this.ctx = this.canvas.getContext('2d');
29 this.ctx = this.canvas.getContext('2d');
30 this.ctx.strokeStyle = 'rgb(0, 0, 0)';
30 this.ctx.strokeStyle = 'rgb(0, 0, 0)';
31 this.ctx.fillStyle = 'rgb(0, 0, 0)';
31 this.ctx.fillStyle = 'rgb(0, 0, 0)';
32 this.cur = [0, 0];
32 this.cur = [0, 0];
33 this.bg = [0, 4];
33 this.bg = [0, 4];
34 this.cell = [2, 0];
34 this.cell = [2, 0];
35 this.columns = 0;
35 this.columns = 0;
36
36
37 this.reset = function() {
37 this.reset = function() {
38 this.bg = [0, 4];
38 this.bg = [0, 4];
39 this.cell = [2, 0];
39 this.cell = [2, 0];
40 this.columns = 0;
40 this.columns = 0;
41 document.getElementById('nodebgs').innerHTML = '';
41 document.getElementById('nodebgs').innerHTML = '';
42 document.getElementById('graphnodes').innerHTML = '';
42 document.getElementById('graphnodes').innerHTML = '';
43 };
43 };
44
44
45 this.scale = function(height) {
45 this.scale = function(height) {
46 this.bg_height = height;
46 this.bg_height = height;
47 this.box_size = Math.floor(this.bg_height / 1.2);
47 this.box_size = Math.floor(this.bg_height / 1.2);
48 this.cell_height = this.box_size;
48 this.cell_height = this.box_size;
49 };
49 };
50
50
51 this.setColor = function(color, bg, fg) {
51 this.setColor = function(color, bg, fg) {
52
52
53 // Set the colour.
53 // Set the colour.
54 //
54 //
55 // If color is a string, expect an hexadecimal RGB
55 // If color is a string, expect an hexadecimal RGB
56 // value and apply it unchanged. If color is a number,
56 // value and apply it unchanged. If color is a number,
57 // pick a distinct colour based on an internal wheel;
57 // pick a distinct colour based on an internal wheel;
58 // the bg parameter provides the value that should be
58 // the bg parameter provides the value that should be
59 // assigned to the 'zero' colours and the fg parameter
59 // assigned to the 'zero' colours and the fg parameter
60 // provides the multiplier that should be applied to
60 // provides the multiplier that should be applied to
61 // the foreground colours.
61 // the foreground colours.
62 var s;
62 var s;
63 if(typeof color == "string") {
63 if(typeof color === "string") {
64 s = "#" + color;
64 s = "#" + color;
65 } else { //typeof color == "number"
65 } else { //typeof color === "number"
66 color %= colors.length;
66 color %= colors.length;
67 var red = (colors[color][0] * fg) || bg;
67 var red = (colors[color][0] * fg) || bg;
68 var green = (colors[color][1] * fg) || bg;
68 var green = (colors[color][1] * fg) || bg;
69 var blue = (colors[color][2] * fg) || bg;
69 var blue = (colors[color][2] * fg) || bg;
70 red = Math.round(red * 255);
70 red = Math.round(red * 255);
71 green = Math.round(green * 255);
71 green = Math.round(green * 255);
72 blue = Math.round(blue * 255);
72 blue = Math.round(blue * 255);
73 s = 'rgb(' + red + ', ' + green + ', ' + blue + ')';
73 s = 'rgb(' + red + ', ' + green + ', ' + blue + ')';
74 }
74 }
75 this.ctx.strokeStyle = s;
75 this.ctx.strokeStyle = s;
76 this.ctx.fillStyle = s;
76 this.ctx.fillStyle = s;
77 return s;
77 return s;
78
78
79 };
79 };
80
80
81 this.edge = function(x0, y0, x1, y1, color, width) {
81 this.edge = function(x0, y0, x1, y1, color, width) {
82
82
83 this.setColor(color, 0.0, 0.65);
83 this.setColor(color, 0.0, 0.65);
84 if(width >= 0)
84 if(width >= 0)
85 this.ctx.lineWidth = width;
85 this.ctx.lineWidth = width;
86 this.ctx.beginPath();
86 this.ctx.beginPath();
87 this.ctx.moveTo(x0, y0);
87 this.ctx.moveTo(x0, y0);
88 this.ctx.lineTo(x1, y1);
88 this.ctx.lineTo(x1, y1);
89 this.ctx.stroke();
89 this.ctx.stroke();
90
90
91 };
91 };
92
92
93 this.render = function(data) {
93 this.render = function(data) {
94
94
95 var backgrounds = '';
95 var backgrounds = '';
96 var nodedata = '';
96 var nodedata = '';
97
97
98 for (var i in data) {
98 for (var i in data) {
99
99
100 var parity = i % 2;
100 var parity = i % 2;
101 this.cell[1] += this.bg_height;
101 this.cell[1] += this.bg_height;
102 this.bg[1] += this.bg_height;
102 this.bg[1] += this.bg_height;
103
103
104 var cur = data[i];
104 var cur = data[i];
105 var node = cur[1];
105 var node = cur[1];
106 var edges = cur[2];
106 var edges = cur[2];
107 var fold = false;
107 var fold = false;
108
108
109 var prevWidth = this.ctx.lineWidth;
109 var prevWidth = this.ctx.lineWidth;
110 for (var j in edges) {
110 for (var j in edges) {
111
111
112 line = edges[j];
112 line = edges[j];
113 start = line[0];
113 start = line[0];
114 end = line[1];
114 end = line[1];
115 color = line[2];
115 color = line[2];
116 var width = line[3];
116 var width = line[3];
117 if(width < 0)
117 if(width < 0)
118 width = prevWidth;
118 width = prevWidth;
119 var branchcolor = line[4];
119 var branchcolor = line[4];
120 if(branchcolor)
120 if(branchcolor)
121 color = branchcolor;
121 color = branchcolor;
122
122
123 if (end > this.columns || start > this.columns) {
123 if (end > this.columns || start > this.columns) {
124 this.columns += 1;
124 this.columns += 1;
125 }
125 }
126
126
127 if (start == this.columns && start > end) {
127 if (start === this.columns && start > end) {
128 fold = true;
128 fold = true;
129 }
129 }
130
130
131 x0 = this.cell[0] + this.box_size * start + this.box_size / 2;
131 x0 = this.cell[0] + this.box_size * start + this.box_size / 2;
132 y0 = this.bg[1] - this.bg_height / 2;
132 y0 = this.bg[1] - this.bg_height / 2;
133 x1 = this.cell[0] + this.box_size * end + this.box_size / 2;
133 x1 = this.cell[0] + this.box_size * end + this.box_size / 2;
134 y1 = this.bg[1] + this.bg_height / 2;
134 y1 = this.bg[1] + this.bg_height / 2;
135
135
136 this.edge(x0, y0, x1, y1, color, width);
136 this.edge(x0, y0, x1, y1, color, width);
137
137
138 }
138 }
139 this.ctx.lineWidth = prevWidth;
139 this.ctx.lineWidth = prevWidth;
140
140
141 // Draw the revision node in the right column
141 // Draw the revision node in the right column
142
142
143 column = node[0];
143 column = node[0];
144 color = node[1];
144 color = node[1];
145
145
146 radius = this.box_size / 8;
146 radius = this.box_size / 8;
147 x = this.cell[0] + this.box_size * column + this.box_size / 2;
147 x = this.cell[0] + this.box_size * column + this.box_size / 2;
148 y = this.bg[1] - this.bg_height / 2;
148 y = this.bg[1] - this.bg_height / 2;
149 var add = this.vertex(x, y, color, parity, cur);
149 var add = this.vertex(x, y, color, parity, cur);
150 backgrounds += add[0];
150 backgrounds += add[0];
151 nodedata += add[1];
151 nodedata += add[1];
152
152
153 if (fold) this.columns -= 1;
153 if (fold) this.columns -= 1;
154
154
155 }
155 }
156
156
157 document.getElementById('nodebgs').innerHTML += backgrounds;
157 document.getElementById('nodebgs').innerHTML += backgrounds;
158 document.getElementById('graphnodes').innerHTML += nodedata;
158 document.getElementById('graphnodes').innerHTML += nodedata;
159
159
160 };
160 };
161
161
162 }
162 }
163
163
164
164
165 function process_dates(parentSelector){
165 function process_dates(parentSelector){
166
166
167 // derived from code from mercurial/templatefilter.py
167 // derived from code from mercurial/templatefilter.py
168
168
169 var scales = {
169 var scales = {
170 'year': 365 * 24 * 60 * 60,
170 'year': 365 * 24 * 60 * 60,
171 'month': 30 * 24 * 60 * 60,
171 'month': 30 * 24 * 60 * 60,
172 'week': 7 * 24 * 60 * 60,
172 'week': 7 * 24 * 60 * 60,
173 'day': 24 * 60 * 60,
173 'day': 24 * 60 * 60,
174 'hour': 60 * 60,
174 'hour': 60 * 60,
175 'minute': 60,
175 'minute': 60,
176 'second': 1
176 'second': 1
177 };
177 };
178
178
179 function format(count, string){
179 function format(count, string){
180 var ret = count + ' ' + string;
180 var ret = count + ' ' + string;
181 if (count > 1){
181 if (count > 1){
182 ret = ret + 's';
182 ret = ret + 's';
183 }
183 }
184 return ret;
184 return ret;
185 }
185 }
186
186
187 function shortdate(date){
187 function shortdate(date){
188 var ret = date.getFullYear() + '-';
188 var ret = date.getFullYear() + '-';
189 // getMonth() gives a 0-11 result
189 // getMonth() gives a 0-11 result
190 var month = date.getMonth() + 1;
190 var month = date.getMonth() + 1;
191 if (month <= 9){
191 if (month <= 9){
192 ret += '0' + month;
192 ret += '0' + month;
193 } else {
193 } else {
194 ret += month;
194 ret += month;
195 }
195 }
196 ret += '-';
196 ret += '-';
197 var day = date.getDate();
197 var day = date.getDate();
198 if (day <= 9){
198 if (day <= 9){
199 ret += '0' + day;
199 ret += '0' + day;
200 } else {
200 } else {
201 ret += day;
201 ret += day;
202 }
202 }
203 return ret;
203 return ret;
204 }
204 }
205
205
206 function age(datestr){
206 function age(datestr){
207 var now = new Date();
207 var now = new Date();
208 var once = new Date(datestr);
208 var once = new Date(datestr);
209 if (isNaN(once.getTime())){
209 if (isNaN(once.getTime())){
210 // parsing error
210 // parsing error
211 return datestr;
211 return datestr;
212 }
212 }
213
213
214 var delta = Math.floor((now.getTime() - once.getTime()) / 1000);
214 var delta = Math.floor((now.getTime() - once.getTime()) / 1000);
215
215
216 var future = false;
216 var future = false;
217 if (delta < 0){
217 if (delta < 0){
218 future = true;
218 future = true;
219 delta = -delta;
219 delta = -delta;
220 if (delta > (30 * scales.year)){
220 if (delta > (30 * scales.year)){
221 return "in the distant future";
221 return "in the distant future";
222 }
222 }
223 }
223 }
224
224
225 if (delta > (2 * scales.year)){
225 if (delta > (2 * scales.year)){
226 return shortdate(once);
226 return shortdate(once);
227 }
227 }
228
228
229 for (var unit in scales){
229 for (var unit in scales){
230 var s = scales[unit];
230 var s = scales[unit];
231 var n = Math.floor(delta / s);
231 var n = Math.floor(delta / s);
232 if ((n >= 2) || (s == 1)){
232 if ((n >= 2) || (s === 1)){
233 if (future){
233 if (future){
234 return format(n, unit) + ' from now';
234 return format(n, unit) + ' from now';
235 } else {
235 } else {
236 return format(n, unit) + ' ago';
236 return format(n, unit) + ' ago';
237 }
237 }
238 }
238 }
239 }
239 }
240 }
240 }
241
241
242 var nodes = document.querySelectorAll((parentSelector || '') + ' .age');
242 var nodes = document.querySelectorAll((parentSelector || '') + ' .age');
243 var dateclass = new RegExp('\\bdate\\b');
243 var dateclass = new RegExp('\\bdate\\b');
244 for (var i=0; i<nodes.length; ++i){
244 for (var i=0; i<nodes.length; ++i){
245 var node = nodes[i];
245 var node = nodes[i];
246 var classes = node.className;
246 var classes = node.className;
247 var agevalue = age(node.textContent);
247 var agevalue = age(node.textContent);
248 if (dateclass.test(classes)){
248 if (dateclass.test(classes)){
249 // We want both: date + (age)
249 // We want both: date + (age)
250 node.textContent += ' ('+agevalue+')';
250 node.textContent += ' ('+agevalue+')';
251 } else {
251 } else {
252 node.title = node.textContent;
252 node.title = node.textContent;
253 node.textContent = agevalue;
253 node.textContent = agevalue;
254 }
254 }
255 }
255 }
256 }
256 }
257
257
258 function toggleDiffstat() {
258 function toggleDiffstat() {
259 var curdetails = document.getElementById('diffstatdetails').style.display;
259 var curdetails = document.getElementById('diffstatdetails').style.display;
260 var curexpand = curdetails == 'none' ? 'inline' : 'none';
260 var curexpand = curdetails === 'none' ? 'inline' : 'none';
261 document.getElementById('diffstatdetails').style.display = curexpand;
261 document.getElementById('diffstatdetails').style.display = curexpand;
262 document.getElementById('diffstatexpand').style.display = curdetails;
262 document.getElementById('diffstatexpand').style.display = curdetails;
263 }
263 }
264
264
265 function toggleLinewrap() {
265 function toggleLinewrap() {
266 function getLinewrap() {
266 function getLinewrap() {
267 var nodes = document.getElementsByClassName('sourcelines');
267 var nodes = document.getElementsByClassName('sourcelines');
268 // if there are no such nodes, error is thrown here
268 // if there are no such nodes, error is thrown here
269 return nodes[0].classList.contains('wrap');
269 return nodes[0].classList.contains('wrap');
270 }
270 }
271
271
272 function setLinewrap(enable) {
272 function setLinewrap(enable) {
273 var nodes = document.getElementsByClassName('sourcelines');
273 var nodes = document.getElementsByClassName('sourcelines');
274 var i;
274 var i;
275 for (i = 0; i < nodes.length; i++) {
275 for (i = 0; i < nodes.length; i++) {
276 if (enable) {
276 if (enable) {
277 nodes[i].classList.add('wrap');
277 nodes[i].classList.add('wrap');
278 } else {
278 } else {
279 nodes[i].classList.remove('wrap');
279 nodes[i].classList.remove('wrap');
280 }
280 }
281 }
281 }
282
282
283 var links = document.getElementsByClassName('linewraplink');
283 var links = document.getElementsByClassName('linewraplink');
284 for (i = 0; i < links.length; i++) {
284 for (i = 0; i < links.length; i++) {
285 links[i].innerHTML = enable ? 'on' : 'off';
285 links[i].innerHTML = enable ? 'on' : 'off';
286 }
286 }
287 }
287 }
288
288
289 setLinewrap(!getLinewrap());
289 setLinewrap(!getLinewrap());
290 }
290 }
291
291
292 function format(str, replacements) {
292 function format(str, replacements) {
293 return str.replace(/%(\w+)%/g, function(match, p1) {
293 return str.replace(/%(\w+)%/g, function(match, p1) {
294 return String(replacements[p1]);
294 return String(replacements[p1]);
295 });
295 });
296 }
296 }
297
297
298 function makeRequest(url, method, onstart, onsuccess, onerror, oncomplete) {
298 function makeRequest(url, method, onstart, onsuccess, onerror, oncomplete) {
299 xfr = new XMLHttpRequest();
299 xfr = new XMLHttpRequest();
300 xfr.onreadystatechange = function() {
300 xfr.onreadystatechange = function() {
301 if (xfr.readyState === 4) {
301 if (xfr.readyState === 4) {
302 try {
302 try {
303 if (xfr.status === 200) {
303 if (xfr.status === 200) {
304 onsuccess(xfr.responseText);
304 onsuccess(xfr.responseText);
305 } else {
305 } else {
306 throw 'server error';
306 throw 'server error';
307 }
307 }
308 } catch (e) {
308 } catch (e) {
309 onerror(e);
309 onerror(e);
310 } finally {
310 } finally {
311 oncomplete();
311 oncomplete();
312 }
312 }
313 }
313 }
314 };
314 };
315
315
316 xfr.open(method, url);
316 xfr.open(method, url);
317 xfr.overrideMimeType("text/xhtml; charset=" + document.characterSet.toLowerCase());
317 xfr.overrideMimeType("text/xhtml; charset=" + document.characterSet.toLowerCase());
318 xfr.send();
318 xfr.send();
319 onstart();
319 onstart();
320 return xfr;
320 return xfr;
321 }
321 }
322
322
323 function removeByClassName(className) {
323 function removeByClassName(className) {
324 var nodes = document.getElementsByClassName(className);
324 var nodes = document.getElementsByClassName(className);
325 while (nodes.length) {
325 while (nodes.length) {
326 nodes[0].parentNode.removeChild(nodes[0]);
326 nodes[0].parentNode.removeChild(nodes[0]);
327 }
327 }
328 }
328 }
329
329
330 function docFromHTML(html) {
330 function docFromHTML(html) {
331 var doc = document.implementation.createHTMLDocument('');
331 var doc = document.implementation.createHTMLDocument('');
332 doc.documentElement.innerHTML = html;
332 doc.documentElement.innerHTML = html;
333 return doc;
333 return doc;
334 }
334 }
335
335
336 function appendFormatHTML(element, formatStr, replacements) {
336 function appendFormatHTML(element, formatStr, replacements) {
337 element.insertAdjacentHTML('beforeend', format(formatStr, replacements));
337 element.insertAdjacentHTML('beforeend', format(formatStr, replacements));
338 }
338 }
339
339
340 function ajaxScrollInit(urlFormat,
340 function ajaxScrollInit(urlFormat,
341 nextPageVar,
341 nextPageVar,
342 nextPageVarGet,
342 nextPageVarGet,
343 containerSelector,
343 containerSelector,
344 messageFormat,
344 messageFormat,
345 mode) {
345 mode) {
346 updateInitiated = false;
346 updateInitiated = false;
347 container = document.querySelector(containerSelector);
347 container = document.querySelector(containerSelector);
348
348
349 function scrollHandler() {
349 function scrollHandler() {
350 if (updateInitiated) {
350 if (updateInitiated) {
351 return;
351 return;
352 }
352 }
353
353
354 var scrollHeight = document.documentElement.scrollHeight;
354 var scrollHeight = document.documentElement.scrollHeight;
355 var clientHeight = document.documentElement.clientHeight;
355 var clientHeight = document.documentElement.clientHeight;
356 var scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
356 var scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
357
357
358 if (scrollHeight - (scrollTop + clientHeight) < 50) {
358 if (scrollHeight - (scrollTop + clientHeight) < 50) {
359 updateInitiated = true;
359 updateInitiated = true;
360 removeByClassName('scroll-loading-error');
360 removeByClassName('scroll-loading-error');
361 container.lastElementChild.classList.add('scroll-separator');
361 container.lastElementChild.classList.add('scroll-separator');
362
362
363 if (!nextPageVar) {
363 if (!nextPageVar) {
364 var message = {
364 var message = {
365 'class': 'scroll-loading-info',
365 'class': 'scroll-loading-info',
366 text: 'No more entries'
366 text: 'No more entries'
367 };
367 };
368 appendFormatHTML(container, messageFormat, message);
368 appendFormatHTML(container, messageFormat, message);
369 return;
369 return;
370 }
370 }
371
371
372 makeRequest(
372 makeRequest(
373 format(urlFormat, {next: nextPageVar}),
373 format(urlFormat, {next: nextPageVar}),
374 'GET',
374 'GET',
375 function onstart() {
375 function onstart() {
376 var message = {
376 var message = {
377 'class': 'scroll-loading',
377 'class': 'scroll-loading',
378 text: 'Loading...'
378 text: 'Loading...'
379 };
379 };
380 appendFormatHTML(container, messageFormat, message);
380 appendFormatHTML(container, messageFormat, message);
381 },
381 },
382 function onsuccess(htmlText) {
382 function onsuccess(htmlText) {
383 if (mode == 'graph') {
383 if (mode === 'graph') {
384 var sizes = htmlText.match(/^\s*<canvas id="graph" width="(\d+)" height="(\d+)"><\/canvas>$/m);
384 var sizes = htmlText.match(/^\s*<canvas id="graph" width="(\d+)" height="(\d+)"><\/canvas>$/m);
385 var addWidth = sizes[1];
385 var addWidth = sizes[1];
386 var addHeight = sizes[2];
386 var addHeight = sizes[2];
387 addWidth = parseInt(addWidth);
387 addWidth = parseInt(addWidth);
388 addHeight = parseInt(addHeight);
388 addHeight = parseInt(addHeight);
389 graph.canvas.width = addWidth;
389 graph.canvas.width = addWidth;
390 graph.canvas.height = addHeight;
390 graph.canvas.height = addHeight;
391
391
392 var dataStr = htmlText.match(/^\s*var data = (.*);$/m)[1];
392 var dataStr = htmlText.match(/^\s*var data = (.*);$/m)[1];
393 var data = JSON.parse(dataStr);
393 var data = JSON.parse(dataStr);
394 if (data.length < nextPageVar) {
394 if (data.length < nextPageVar) {
395 nextPageVar = undefined;
395 nextPageVar = undefined;
396 }
396 }
397 graph.reset();
397 graph.reset();
398 graph.render(data);
398 graph.render(data);
399 } else {
399 } else {
400 var doc = docFromHTML(htmlText);
400 var doc = docFromHTML(htmlText);
401 var nodes = doc.querySelector(containerSelector).children;
401 var nodes = doc.querySelector(containerSelector).children;
402 var curClass = 'c' + Date.now();
402 var curClass = 'c' + Date.now();
403 while (nodes.length) {
403 while (nodes.length) {
404 var node = nodes[0];
404 var node = nodes[0];
405 node = document.adoptNode(node);
405 node = document.adoptNode(node);
406 node.classList.add(curClass);
406 node.classList.add(curClass);
407 container.appendChild(node);
407 container.appendChild(node);
408 }
408 }
409 process_dates('.' + curClass);
409 process_dates('.' + curClass);
410 }
410 }
411
411
412 nextPageVar = nextPageVarGet(htmlText, nextPageVar);
412 nextPageVar = nextPageVarGet(htmlText, nextPageVar);
413 },
413 },
414 function onerror(errorText) {
414 function onerror(errorText) {
415 var message = {
415 var message = {
416 'class': 'scroll-loading-error',
416 'class': 'scroll-loading-error',
417 text: 'Error: ' + errorText
417 text: 'Error: ' + errorText
418 };
418 };
419 appendFormatHTML(container, messageFormat, message);
419 appendFormatHTML(container, messageFormat, message);
420 },
420 },
421 function oncomplete() {
421 function oncomplete() {
422 removeByClassName('scroll-loading');
422 removeByClassName('scroll-loading');
423 updateInitiated = false;
423 updateInitiated = false;
424 scrollHandler();
424 scrollHandler();
425 }
425 }
426 );
426 );
427 }
427 }
428 }
428 }
429
429
430 window.addEventListener('scroll', scrollHandler);
430 window.addEventListener('scroll', scrollHandler);
431 window.addEventListener('resize', scrollHandler);
431 window.addEventListener('resize', scrollHandler);
432 scrollHandler();
432 scrollHandler();
433 }
433 }
434
434
435 function renderDiffOptsForm() {
435 function renderDiffOptsForm() {
436 // We use URLSearchParams for query string manipulation. Old browsers don't
436 // We use URLSearchParams for query string manipulation. Old browsers don't
437 // support this API.
437 // support this API.
438 if (!("URLSearchParams" in window)) {
438 if (!("URLSearchParams" in window)) {
439 return;
439 return;
440 }
440 }
441
441
442 var form = document.getElementById("diffopts-form");
442 var form = document.getElementById("diffopts-form");
443
443
444 var KEYS = [
444 var KEYS = [
445 "ignorews",
445 "ignorews",
446 "ignorewsamount",
446 "ignorewsamount",
447 "ignorewseol",
447 "ignorewseol",
448 "ignoreblanklines",
448 "ignoreblanklines",
449 ];
449 ];
450
450
451 var urlParams = new URLSearchParams(window.location.search);
451 var urlParams = new URLSearchParams(window.location.search);
452
452
453 function updateAndRefresh(e) {
453 function updateAndRefresh(e) {
454 var checkbox = e.target;
454 var checkbox = e.target;
455 var name = checkbox.id.substr(0, checkbox.id.indexOf("-"));
455 var name = checkbox.id.substr(0, checkbox.id.indexOf("-"));
456 urlParams.set(name, checkbox.checked ? "1" : "0");
456 urlParams.set(name, checkbox.checked ? "1" : "0");
457 window.location.search = urlParams.toString();
457 window.location.search = urlParams.toString();
458 }
458 }
459
459
460 var allChecked = form.getAttribute("data-ignorews") == "1";
460 var allChecked = form.getAttribute("data-ignorews") === "1";
461
461
462 for (var i = 0; i < KEYS.length; i++) {
462 for (var i = 0; i < KEYS.length; i++) {
463 var key = KEYS[i];
463 var key = KEYS[i];
464
464
465 var checkbox = document.getElementById(key + "-checkbox");
465 var checkbox = document.getElementById(key + "-checkbox");
466 if (!checkbox) {
466 if (!checkbox) {
467 continue;
467 continue;
468 }
468 }
469
469
470 currentValue = form.getAttribute("data-" + key);
470 currentValue = form.getAttribute("data-" + key);
471 checkbox.checked = currentValue != "0";
471 checkbox.checked = currentValue !== "0";
472
472
473 // ignorews implies ignorewsamount and ignorewseol.
473 // ignorews implies ignorewsamount and ignorewseol.
474 if (allChecked && (key == "ignorewsamount" || key == "ignorewseol")) {
474 if (allChecked && (key === "ignorewsamount" || key === "ignorewseol")) {
475 checkbox.checked = true;
475 checkbox.checked = true;
476 checkbox.disabled = true;
476 checkbox.disabled = true;
477 }
477 }
478
478
479 checkbox.addEventListener("change", updateAndRefresh, false);
479 checkbox.addEventListener("change", updateAndRefresh, false);
480 }
480 }
481
481
482 form.style.display = 'block';
482 form.style.display = 'block';
483 }
483 }
484
484
485 document.addEventListener('DOMContentLoaded', function() {
485 document.addEventListener('DOMContentLoaded', function() {
486 process_dates();
486 process_dates();
487 }, false);
487 }, false);
General Comments 0
You need to be logged in to leave comments. Login now