OLD | NEW |
1 /* | 1 /* |
2 * This Source Code is subject to the terms of the Mozilla Public License | 2 * This Source Code is subject to the terms of the Mozilla Public License |
3 * version 2.0 (the "License"). You can obtain a copy of the License at | 3 * version 2.0 (the "License"). You can obtain a copy of the License at |
4 * http://mozilla.org/MPL/2.0/. | 4 * http://mozilla.org/MPL/2.0/. |
5 */ | 5 */ |
6 | 6 |
7 (function() | 7 (function() |
8 { | 8 { |
9 let progressBar, canvas, headers; | 9 let progressBar, canvas, headers, isRTL; |
10 | 10 |
11 function onLoad() | 11 function onLoad() |
12 { | 12 { |
13 window.removeEventListener("load", onLoad, false); | 13 window.removeEventListener("load", onLoad, false); |
14 | 14 |
15 // Init global variables | 15 // Init global variables |
16 progressBar = document.getElementById("progressBar"); | 16 progressBar = document.getElementById("progressBar"); |
17 canvas = document.getElementById("progressBarCanvas"); | 17 canvas = document.getElementById("progressBarCanvas"); |
18 | 18 |
19 headers = Array.prototype.slice.call(progressBar.getElementsByTagName("label
")); | 19 headers = Array.prototype.slice.call(progressBar.getElementsByTagName("label
")); |
20 for (let i = 0; i < headers.length; i++) | 20 for (let i = 0; i < headers.length; i++) |
21 canvas.parentNode.appendChild(headers[i]); | 21 canvas.parentNode.appendChild(headers[i]); |
22 | 22 |
23 // Expose properties | 23 // Expose properties |
24 progressBar.__defineGetter__("activeItem", getActiveItem); | 24 progressBar.__defineGetter__("activeItem", getActiveItem); |
25 progressBar.__defineSetter__("activeItem", setActiveItem); | 25 progressBar.__defineSetter__("activeItem", setActiveItem); |
26 progressBar.__defineGetter__("activeItemComplete", getActiveItemComplete); | 26 progressBar.__defineGetter__("activeItemComplete", getActiveItemComplete); |
27 progressBar.__defineSetter__("activeItemComplete", setActiveItemComplete); | 27 progressBar.__defineSetter__("activeItemComplete", setActiveItemComplete); |
28 | 28 |
| 29 isRTL = (window.getComputedStyle(document.documentElement).direction == "rtl
"); |
| 30 |
29 // Run actual drawing delayed, once the sizes are fixed | 31 // Run actual drawing delayed, once the sizes are fixed |
30 window.setTimeout(init, 0); | 32 window.setTimeout(init, 0); |
31 }; | 33 }; |
32 window.addEventListener("load", onLoad, false); | 34 window.addEventListener("load", onLoad, false); |
33 | 35 |
34 function init() | 36 function init() |
35 { | 37 { |
36 const gapWidth = 5; | 38 const gapWidth = 5; |
37 const arrowheadWidth = 5; | 39 const arrowheadWidth = 5; |
38 | 40 |
39 let width = canvas.width = canvas.offsetWidth; | 41 let width = canvas.width = canvas.offsetWidth; |
40 let height = canvas.height = canvas.offsetHeight; | 42 let height = canvas.height = canvas.offsetHeight; |
41 | 43 |
42 let context = canvas.getContext("2d"); | 44 let context = canvas.getContext("2d"); |
43 context.fillStyle = window.getComputedStyle(progressBar, "").color; | 45 context.fillStyle = window.getComputedStyle(progressBar, "").color; |
44 context.strokeStyle = window.getComputedStyle(progressBar, "").color; | 46 context.strokeStyle = window.getComputedStyle(progressBar, "").color; |
45 context.lineWidth = 1; | 47 context.lineWidth = 1; |
| 48 if (isRTL) |
| 49 { |
| 50 context.translate(width, 0); |
| 51 context.scale(-1, 1); |
| 52 } |
46 | 53 |
47 let panelCount = headers.length; | 54 let panelCount = headers.length; |
48 let panelWidth = (width - gapWidth * (panelCount - 1) - 1) / panelCount; | 55 let panelWidth = (width - gapWidth * (panelCount - 1) - 1) / panelCount; |
49 for (let i = 0; i < panelCount; i++) | 56 for (let i = 0; i < panelCount; i++) |
50 { | 57 { |
51 context.save(); | 58 context.save(); |
52 context.translate(Math.round(i * (panelWidth + gapWidth)) + 0.5, 0.5); | 59 context.translate(Math.round(i * (panelWidth + gapWidth)) + 0.5, 0.5); |
53 context.beginPath(); | 60 context.beginPath(); |
54 if (i) | 61 if (i) |
55 context.moveTo(-arrowheadWidth, 0); | 62 context.moveTo(-arrowheadWidth, 0); |
56 else | 63 else |
57 context.moveTo(0, 0); | 64 context.moveTo(0, 0); |
58 context.lineTo(panelWidth - arrowheadWidth, 0); | 65 context.lineTo(panelWidth - arrowheadWidth, 0); |
59 context.lineTo(panelWidth, (height - 1) / 2); | 66 context.lineTo(panelWidth, (height - 1) / 2); |
60 context.lineTo(panelWidth - arrowheadWidth, height - 1); | 67 context.lineTo(panelWidth - arrowheadWidth, height - 1); |
61 if (i) | 68 if (i) |
62 { | 69 { |
63 context.lineTo(-arrowheadWidth, height - 1); | 70 context.lineTo(-arrowheadWidth, height - 1); |
64 context.lineTo(0, (height - 1) / 2); | 71 context.lineTo(0, (height - 1) / 2); |
65 context.lineTo(-arrowheadWidth, 0); | 72 context.lineTo(-arrowheadWidth, 0); |
66 } | 73 } |
67 else | 74 else |
68 { | 75 { |
69 context.lineTo(0, height - 1); | 76 context.lineTo(0, height - 1); |
70 context.lineTo(0, 0); | 77 context.lineTo(0, 0); |
71 } | 78 } |
| 79 |
72 context.stroke(); | 80 context.stroke(); |
73 context.restore(); | 81 context.restore(); |
74 | 82 |
75 let childLeft = Math.round(i * (panelWidth + gapWidth) + 1); | 83 let childLeft = Math.round(i * (panelWidth + gapWidth) + 1); |
76 let childWidth = panelWidth - arrowheadWidth - 2; | 84 let childWidth = panelWidth - arrowheadWidth - 2; |
77 let child = headers[i]; | 85 let child = headers[i]; |
78 child.style.marginLeft = childLeft + "px"; | 86 child.style.MozMarginStart = childLeft + "px"; |
79 child.style.marginRight = (width - childLeft - childWidth) + "px"; | 87 child.style.MozMarginEnd = (width - childLeft - childWidth) + "px"; |
80 child.style.width = childWidth + "px"; | 88 child.style.width = childWidth + "px"; |
81 } | 89 } |
82 | 90 |
83 // Resize after initialization should be ignored | 91 // Resize after initialization should be ignored |
84 canvas.parentNode.removeAttribute("flex"); | 92 canvas.parentNode.removeAttribute("flex"); |
85 } | 93 } |
86 | 94 |
87 function getActiveItem() | 95 function getActiveItem() |
88 { | 96 { |
89 for (let i = 0; i < headers.length; i++) | 97 for (let i = 0; i < headers.length; i++) |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 let activeItem = this.activeItem; | 138 let activeItem = this.activeItem; |
131 if (!activeItem) | 139 if (!activeItem) |
132 return; | 140 return; |
133 | 141 |
134 if (!val && activeItem.value[0] == "✔") | 142 if (!val && activeItem.value[0] == "✔") |
135 activeItem.value = activeItem.value.replace(/^✔\s*/, ""); | 143 activeItem.value = activeItem.value.replace(/^✔\s*/, ""); |
136 else if (val && activeItem.value[0] != "✔") | 144 else if (val && activeItem.value[0] != "✔") |
137 activeItem.value = "✔ " + activeItem.value; | 145 activeItem.value = "✔ " + activeItem.value; |
138 } | 146 } |
139 })(); | 147 })(); |
OLD | NEW |