Mercurial > public > mercurial-scm > hg
comparison mercurial/templates/static/mercurial.js @ 35157:ccf86aa5797c
hgweb: use strict equals in mercurial.js
This patch changes "==" (equals operator) to "===" (strict equals operator).
The difference between them is that the latter doesn't do any type coercions.
It's handy to compare string '1' to number 1 sometimes, but most of the time
using "==" is inadvertent and can be replaced by an explicit type conversion.
(This corresponds to "eqeqeq" option of jshint).
Some of the changes in this patch are straightforward, e.g. when comparing
results of typeof (they could only be strings). The same goes for 'none' and
similar strings that can't be sensibly coerced to some other type. Two changes
that compare values to "1" and "0" can be clarified: getAttribute() returns
either a string or null, but comparing null to a string is always false, so no
logic is lost.
author | Anton Shestakov <av6@dwimlabs.net> |
---|---|
date | Wed, 22 Nov 2017 20:52:59 +0800 |
parents | e46f0b653002 |
children | 241da2de0e9f |
comparison
equal
deleted
inserted
replaced
35156:9f44d44626a0 | 35157:ccf86aa5797c |
---|---|
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); |
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; |
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 } |
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() { |
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); |
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); |