##// END OF EJS Templates
hgweb: rename an instance of XMLHttpRequest to xhr in mercurial.js...
av6 -
r35160:018aac6d default
parent child Browse files
Show More
@@ -1,488 +1,488 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 = 0; i < data.length; i++) {
98 for (var i = 0; i < data.length; i++) {
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 = 0; j < edges.length; j++) {
110 for (var j = 0; j < edges.length; j++) {
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 if (!scales.hasOwnProperty(unit)) { continue; }
230 if (!scales.hasOwnProperty(unit)) { continue; }
231 var s = scales[unit];
231 var s = scales[unit];
232 var n = Math.floor(delta / s);
232 var n = Math.floor(delta / s);
233 if ((n >= 2) || (s === 1)){
233 if ((n >= 2) || (s === 1)){
234 if (future){
234 if (future){
235 return format(n, unit) + ' from now';
235 return format(n, unit) + ' from now';
236 } else {
236 } else {
237 return format(n, unit) + ' ago';
237 return format(n, unit) + ' ago';
238 }
238 }
239 }
239 }
240 }
240 }
241 }
241 }
242
242
243 var nodes = document.querySelectorAll((parentSelector || '') + ' .age');
243 var nodes = document.querySelectorAll((parentSelector || '') + ' .age');
244 var dateclass = new RegExp('\\bdate\\b');
244 var dateclass = new RegExp('\\bdate\\b');
245 for (var i=0; i<nodes.length; ++i){
245 for (var i=0; i<nodes.length; ++i){
246 var node = nodes[i];
246 var node = nodes[i];
247 var classes = node.className;
247 var classes = node.className;
248 var agevalue = age(node.textContent);
248 var agevalue = age(node.textContent);
249 if (dateclass.test(classes)){
249 if (dateclass.test(classes)){
250 // We want both: date + (age)
250 // We want both: date + (age)
251 node.textContent += ' ('+agevalue+')';
251 node.textContent += ' ('+agevalue+')';
252 } else {
252 } else {
253 node.title = node.textContent;
253 node.title = node.textContent;
254 node.textContent = agevalue;
254 node.textContent = agevalue;
255 }
255 }
256 }
256 }
257 }
257 }
258
258
259 function toggleDiffstat() {
259 function toggleDiffstat() {
260 var curdetails = document.getElementById('diffstatdetails').style.display;
260 var curdetails = document.getElementById('diffstatdetails').style.display;
261 var curexpand = curdetails === 'none' ? 'inline' : 'none';
261 var curexpand = curdetails === 'none' ? 'inline' : 'none';
262 document.getElementById('diffstatdetails').style.display = curexpand;
262 document.getElementById('diffstatdetails').style.display = curexpand;
263 document.getElementById('diffstatexpand').style.display = curdetails;
263 document.getElementById('diffstatexpand').style.display = curdetails;
264 }
264 }
265
265
266 function toggleLinewrap() {
266 function toggleLinewrap() {
267 function getLinewrap() {
267 function getLinewrap() {
268 var nodes = document.getElementsByClassName('sourcelines');
268 var nodes = document.getElementsByClassName('sourcelines');
269 // if there are no such nodes, error is thrown here
269 // if there are no such nodes, error is thrown here
270 return nodes[0].classList.contains('wrap');
270 return nodes[0].classList.contains('wrap');
271 }
271 }
272
272
273 function setLinewrap(enable) {
273 function setLinewrap(enable) {
274 var nodes = document.getElementsByClassName('sourcelines');
274 var nodes = document.getElementsByClassName('sourcelines');
275 var i;
275 var i;
276 for (i = 0; i < nodes.length; i++) {
276 for (i = 0; i < nodes.length; i++) {
277 if (enable) {
277 if (enable) {
278 nodes[i].classList.add('wrap');
278 nodes[i].classList.add('wrap');
279 } else {
279 } else {
280 nodes[i].classList.remove('wrap');
280 nodes[i].classList.remove('wrap');
281 }
281 }
282 }
282 }
283
283
284 var links = document.getElementsByClassName('linewraplink');
284 var links = document.getElementsByClassName('linewraplink');
285 for (i = 0; i < links.length; i++) {
285 for (i = 0; i < links.length; i++) {
286 links[i].innerHTML = enable ? 'on' : 'off';
286 links[i].innerHTML = enable ? 'on' : 'off';
287 }
287 }
288 }
288 }
289
289
290 setLinewrap(!getLinewrap());
290 setLinewrap(!getLinewrap());
291 }
291 }
292
292
293 function format(str, replacements) {
293 function format(str, replacements) {
294 return str.replace(/%(\w+)%/g, function(match, p1) {
294 return str.replace(/%(\w+)%/g, function(match, p1) {
295 return String(replacements[p1]);
295 return String(replacements[p1]);
296 });
296 });
297 }
297 }
298
298
299 function makeRequest(url, method, onstart, onsuccess, onerror, oncomplete) {
299 function makeRequest(url, method, onstart, onsuccess, onerror, oncomplete) {
300 xfr = new XMLHttpRequest();
300 xhr = new XMLHttpRequest();
301 xfr.onreadystatechange = function() {
301 xhr.onreadystatechange = function() {
302 if (xfr.readyState === 4) {
302 if (xhr.readyState === 4) {
303 try {
303 try {
304 if (xfr.status === 200) {
304 if (xhr.status === 200) {
305 onsuccess(xfr.responseText);
305 onsuccess(xhr.responseText);
306 } else {
306 } else {
307 throw 'server error';
307 throw 'server error';
308 }
308 }
309 } catch (e) {
309 } catch (e) {
310 onerror(e);
310 onerror(e);
311 } finally {
311 } finally {
312 oncomplete();
312 oncomplete();
313 }
313 }
314 }
314 }
315 };
315 };
316
316
317 xfr.open(method, url);
317 xhr.open(method, url);
318 xfr.overrideMimeType("text/xhtml; charset=" + document.characterSet.toLowerCase());
318 xhr.overrideMimeType("text/xhtml; charset=" + document.characterSet.toLowerCase());
319 xfr.send();
319 xhr.send();
320 onstart();
320 onstart();
321 return xfr;
321 return xhr;
322 }
322 }
323
323
324 function removeByClassName(className) {
324 function removeByClassName(className) {
325 var nodes = document.getElementsByClassName(className);
325 var nodes = document.getElementsByClassName(className);
326 while (nodes.length) {
326 while (nodes.length) {
327 nodes[0].parentNode.removeChild(nodes[0]);
327 nodes[0].parentNode.removeChild(nodes[0]);
328 }
328 }
329 }
329 }
330
330
331 function docFromHTML(html) {
331 function docFromHTML(html) {
332 var doc = document.implementation.createHTMLDocument('');
332 var doc = document.implementation.createHTMLDocument('');
333 doc.documentElement.innerHTML = html;
333 doc.documentElement.innerHTML = html;
334 return doc;
334 return doc;
335 }
335 }
336
336
337 function appendFormatHTML(element, formatStr, replacements) {
337 function appendFormatHTML(element, formatStr, replacements) {
338 element.insertAdjacentHTML('beforeend', format(formatStr, replacements));
338 element.insertAdjacentHTML('beforeend', format(formatStr, replacements));
339 }
339 }
340
340
341 function ajaxScrollInit(urlFormat,
341 function ajaxScrollInit(urlFormat,
342 nextPageVar,
342 nextPageVar,
343 nextPageVarGet,
343 nextPageVarGet,
344 containerSelector,
344 containerSelector,
345 messageFormat,
345 messageFormat,
346 mode) {
346 mode) {
347 updateInitiated = false;
347 updateInitiated = false;
348 container = document.querySelector(containerSelector);
348 container = document.querySelector(containerSelector);
349
349
350 function scrollHandler() {
350 function scrollHandler() {
351 if (updateInitiated) {
351 if (updateInitiated) {
352 return;
352 return;
353 }
353 }
354
354
355 var scrollHeight = document.documentElement.scrollHeight;
355 var scrollHeight = document.documentElement.scrollHeight;
356 var clientHeight = document.documentElement.clientHeight;
356 var clientHeight = document.documentElement.clientHeight;
357 var scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
357 var scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
358
358
359 if (scrollHeight - (scrollTop + clientHeight) < 50) {
359 if (scrollHeight - (scrollTop + clientHeight) < 50) {
360 updateInitiated = true;
360 updateInitiated = true;
361 removeByClassName('scroll-loading-error');
361 removeByClassName('scroll-loading-error');
362 container.lastElementChild.classList.add('scroll-separator');
362 container.lastElementChild.classList.add('scroll-separator');
363
363
364 if (!nextPageVar) {
364 if (!nextPageVar) {
365 var message = {
365 var message = {
366 'class': 'scroll-loading-info',
366 'class': 'scroll-loading-info',
367 text: 'No more entries'
367 text: 'No more entries'
368 };
368 };
369 appendFormatHTML(container, messageFormat, message);
369 appendFormatHTML(container, messageFormat, message);
370 return;
370 return;
371 }
371 }
372
372
373 makeRequest(
373 makeRequest(
374 format(urlFormat, {next: nextPageVar}),
374 format(urlFormat, {next: nextPageVar}),
375 'GET',
375 'GET',
376 function onstart() {
376 function onstart() {
377 var message = {
377 var message = {
378 'class': 'scroll-loading',
378 'class': 'scroll-loading',
379 text: 'Loading...'
379 text: 'Loading...'
380 };
380 };
381 appendFormatHTML(container, messageFormat, message);
381 appendFormatHTML(container, messageFormat, message);
382 },
382 },
383 function onsuccess(htmlText) {
383 function onsuccess(htmlText) {
384 if (mode === 'graph') {
384 if (mode === 'graph') {
385 var sizes = htmlText.match(/^\s*<canvas id="graph" width="(\d+)" height="(\d+)"><\/canvas>$/m);
385 var sizes = htmlText.match(/^\s*<canvas id="graph" width="(\d+)" height="(\d+)"><\/canvas>$/m);
386 var addWidth = sizes[1];
386 var addWidth = sizes[1];
387 var addHeight = sizes[2];
387 var addHeight = sizes[2];
388 addWidth = parseInt(addWidth);
388 addWidth = parseInt(addWidth);
389 addHeight = parseInt(addHeight);
389 addHeight = parseInt(addHeight);
390 graph.canvas.width = addWidth;
390 graph.canvas.width = addWidth;
391 graph.canvas.height = addHeight;
391 graph.canvas.height = addHeight;
392
392
393 var dataStr = htmlText.match(/^\s*var data = (.*);$/m)[1];
393 var dataStr = htmlText.match(/^\s*var data = (.*);$/m)[1];
394 var data = JSON.parse(dataStr);
394 var data = JSON.parse(dataStr);
395 if (data.length < nextPageVar) {
395 if (data.length < nextPageVar) {
396 nextPageVar = undefined;
396 nextPageVar = undefined;
397 }
397 }
398 graph.reset();
398 graph.reset();
399 graph.render(data);
399 graph.render(data);
400 } else {
400 } else {
401 var doc = docFromHTML(htmlText);
401 var doc = docFromHTML(htmlText);
402 var nodes = doc.querySelector(containerSelector).children;
402 var nodes = doc.querySelector(containerSelector).children;
403 var curClass = 'c' + Date.now();
403 var curClass = 'c' + Date.now();
404 while (nodes.length) {
404 while (nodes.length) {
405 var node = nodes[0];
405 var node = nodes[0];
406 node = document.adoptNode(node);
406 node = document.adoptNode(node);
407 node.classList.add(curClass);
407 node.classList.add(curClass);
408 container.appendChild(node);
408 container.appendChild(node);
409 }
409 }
410 process_dates('.' + curClass);
410 process_dates('.' + curClass);
411 }
411 }
412
412
413 nextPageVar = nextPageVarGet(htmlText, nextPageVar);
413 nextPageVar = nextPageVarGet(htmlText, nextPageVar);
414 },
414 },
415 function onerror(errorText) {
415 function onerror(errorText) {
416 var message = {
416 var message = {
417 'class': 'scroll-loading-error',
417 'class': 'scroll-loading-error',
418 text: 'Error: ' + errorText
418 text: 'Error: ' + errorText
419 };
419 };
420 appendFormatHTML(container, messageFormat, message);
420 appendFormatHTML(container, messageFormat, message);
421 },
421 },
422 function oncomplete() {
422 function oncomplete() {
423 removeByClassName('scroll-loading');
423 removeByClassName('scroll-loading');
424 updateInitiated = false;
424 updateInitiated = false;
425 scrollHandler();
425 scrollHandler();
426 }
426 }
427 );
427 );
428 }
428 }
429 }
429 }
430
430
431 window.addEventListener('scroll', scrollHandler);
431 window.addEventListener('scroll', scrollHandler);
432 window.addEventListener('resize', scrollHandler);
432 window.addEventListener('resize', scrollHandler);
433 scrollHandler();
433 scrollHandler();
434 }
434 }
435
435
436 function renderDiffOptsForm() {
436 function renderDiffOptsForm() {
437 // We use URLSearchParams for query string manipulation. Old browsers don't
437 // We use URLSearchParams for query string manipulation. Old browsers don't
438 // support this API.
438 // support this API.
439 if (!("URLSearchParams" in window)) {
439 if (!("URLSearchParams" in window)) {
440 return;
440 return;
441 }
441 }
442
442
443 var form = document.getElementById("diffopts-form");
443 var form = document.getElementById("diffopts-form");
444
444
445 var KEYS = [
445 var KEYS = [
446 "ignorews",
446 "ignorews",
447 "ignorewsamount",
447 "ignorewsamount",
448 "ignorewseol",
448 "ignorewseol",
449 "ignoreblanklines",
449 "ignoreblanklines",
450 ];
450 ];
451
451
452 var urlParams = new URLSearchParams(window.location.search);
452 var urlParams = new URLSearchParams(window.location.search);
453
453
454 function updateAndRefresh(e) {
454 function updateAndRefresh(e) {
455 var checkbox = e.target;
455 var checkbox = e.target;
456 var name = checkbox.id.substr(0, checkbox.id.indexOf("-"));
456 var name = checkbox.id.substr(0, checkbox.id.indexOf("-"));
457 urlParams.set(name, checkbox.checked ? "1" : "0");
457 urlParams.set(name, checkbox.checked ? "1" : "0");
458 window.location.search = urlParams.toString();
458 window.location.search = urlParams.toString();
459 }
459 }
460
460
461 var allChecked = form.getAttribute("data-ignorews") === "1";
461 var allChecked = form.getAttribute("data-ignorews") === "1";
462
462
463 for (var i = 0; i < KEYS.length; i++) {
463 for (var i = 0; i < KEYS.length; i++) {
464 var key = KEYS[i];
464 var key = KEYS[i];
465
465
466 var checkbox = document.getElementById(key + "-checkbox");
466 var checkbox = document.getElementById(key + "-checkbox");
467 if (!checkbox) {
467 if (!checkbox) {
468 continue;
468 continue;
469 }
469 }
470
470
471 currentValue = form.getAttribute("data-" + key);
471 currentValue = form.getAttribute("data-" + key);
472 checkbox.checked = currentValue !== "0";
472 checkbox.checked = currentValue !== "0";
473
473
474 // ignorews implies ignorewsamount and ignorewseol.
474 // ignorews implies ignorewsamount and ignorewseol.
475 if (allChecked && (key === "ignorewsamount" || key === "ignorewseol")) {
475 if (allChecked && (key === "ignorewsamount" || key === "ignorewseol")) {
476 checkbox.checked = true;
476 checkbox.checked = true;
477 checkbox.disabled = true;
477 checkbox.disabled = true;
478 }
478 }
479
479
480 checkbox.addEventListener("change", updateAndRefresh, false);
480 checkbox.addEventListener("change", updateAndRefresh, false);
481 }
481 }
482
482
483 form.style.display = 'block';
483 form.style.display = 'block';
484 }
484 }
485
485
486 document.addEventListener('DOMContentLoaded', function() {
486 document.addEventListener('DOMContentLoaded', function() {
487 process_dates();
487 process_dates();
488 }, false);
488 }, false);
General Comments 0
You need to be logged in to leave comments. Login now