-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathui.html
More file actions
179 lines (145 loc) · 5.35 KB
/
ui.html
File metadata and controls
179 lines (145 loc) · 5.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<html>
<style>
body {
font: 12px sans-serif;
text-align: center;
color: #3C3C3C;
margin: 10px;
}
button {
border-radius: 5px;
background: white;
color: black;
border: none;
padding: 8px 12px;
margin: 0 2px;
box-shadow: inset 0 0 0 1px black;
outline: none;
}
button:disabled {
color: grey;
box-shadow: inset 0 0 0 1px grey;
}
button:active {
background: lightgray;
}
</style>
<button id="start" style="width: 70;">Start</button>
<button id="reset">Reset</button>
<button id="help">?</button>
<div id="helptext" hidden> <br /> <br />
Type the time you want to count down in Timer: HH:MM:SS format (e.g. Timer: 5:00) in any text field, then press
'Start'.
You can also use HH:MM:SS format (e.g. 5:00). In this case you need to select the text layer before pressing 'Start'.
</div>
<div id=timers-container hidden>
<br />
<br />
<b id="timers" text-align=left style="border-bottom: 1px dashed #E6E6E6;" ;> </b>
</div>
</html>
<script>
document.getElementById('start').onclick = () => {
var currentButtonState = document.getElementById('start').textContent;
switch (currentButtonState) {
case 'Start':
parent.postMessage({ pluginMessage: { type: 'start' } }, '*');
document.getElementById('start').textContent = 'Pause';
break;
case 'Pause':
parent.postMessage({ pluginMessage: { type: 'pause' } }, '*');
document.getElementById('start').textContent = 'Continue';
break;
case 'Continue':
parent.postMessage({ pluginMessage: { type: 'continue' } }, '*');
document.getElementById('start').textContent = 'Pause';
break;
default:
console.log('button pressed, but event was not coded for');
}
}
document.getElementById('reset').onclick = () => {
parent.postMessage({ pluginMessage: { type: 'reset' } }, '*')
document.getElementById('start').textContent = 'Start';
var timersHTMLelement = document.getElementById("timers");
timersHTMLelement.innerHTML = "";
}
document.getElementById('help').onclick = () => {
if (document.getElementById('helptext').hidden == true) {
document.getElementById('helptext').hidden = false;
parent.postMessage({ pluginMessage: { type: 'helpon' } }, '*')
} else {
document.getElementById('helptext').hidden = true;
parent.postMessage({ pluginMessage: { type: 'helpoff' } }, '*')
}
}
const progressBar = {
width: 200,
height: 10,
margin: 5,
};
/**
* message events coming from code.ts where the main logic for the timer sits
* messages contain timer information by ID, so that we can update UI.html with timer info
*/
onmessage = (event) => {
var eventType = event.data.pluginMessage[0];
var timerText = event.data.pluginMessage[1];
var timerID = event.data.pluginMessage[2];
var secondsToGo = event.data.pluginMessage[3];
var secondsToStart = event.data.pluginMessage[4];
switch (eventType) {
case 'start timer':
document.getElementById('timers-container').hidden = false;
createTimerUIElements(timerID);
break;
case 'counting':
var newProgressBarWidth = progressBar.width * secondsToGo / secondsToStart;
updateTimer(timerID, timerText, newProgressBarWidth);
break;
case 'timer done':
updateTimer(timerID, timerText, 0);
break;
}
}
function createTimerUIElements(timerID) {
// create spacing between timers
var spacing = document.createElement('div');
spacing.lineHeight = 3;
spacing.textContent = "---";
spacing.style.color = 'white';
timers.appendChild(spacing);
// create a timer text e.g. Timer: 3:34
var timerTextElement = document.createElement('div');
timerTextElement.style.fontSize = 11;
timerTextElement.style.color = 'black';
timerTextElement.style.textAlign = 'left';
timerTextElement.style.fontWeight = 200;
timers.appendChild(timerTextElement);
timerTextElement.id = timerID;
// create a timer progress bar
var mySVG = document.createElementNS("http://www.w3.org/2000/svg", 'svg');
var progressBarFront = document.createElementNS("http://www.w3.org/2000/svg", 'rect');
var progressBarBack = document.createElementNS("http://www.w3.org/2000/svg", 'rect');
progressBarFront.id = "progress" + timerID;
mySVG.id = "svg" + timerID;
mySVG.setAttribute('width', progressBar.width);
mySVG.setAttribute('height', progressBar.height + 20);
progressBarFront.setAttribute("y", progressBar.margin);
progressBarFront.setAttribute("width", progressBar.width);
progressBarFront.setAttribute("height", progressBar.height);
progressBarFront.setAttribute("fill", "#009FC2");
progressBarBack.setAttribute("y", progressBar.margin);
progressBarBack.setAttribute("width", progressBar.width);
progressBarBack.setAttribute("height", progressBar.height);
progressBarBack.setAttribute("fill", "#E4E4E4");
mySVG.appendChild(progressBarBack);
mySVG.appendChild(progressBarFront);
timers.appendChild(mySVG);
}
function updateTimer(timerID, timerText, newWidth) {
var progressBarUpdate = document.getElementById("progress" + timerID);
progressBarUpdate.setAttribute("width", newWidth);
document.getElementById(timerID).textContent = "Timer " + timerID + ": " + timerText;
}
</script>