-
Notifications
You must be signed in to change notification settings - Fork 60
/
external-title.html
107 lines (94 loc) · 4.36 KB
/
external-title.html
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
<!DOCTYPE html>
<html>
<head>
<title>wnr</title>
<meta charset="UTF-8" />
<meta http-equiv="Content-Type" content="text/html" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimal-ui" />
<script>
window.$ = require("jquery/dist/jquery.slim.min.js");
</script>
<link rel="stylesheet" href="node_modules/bootstrap/dist/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="res/fonts/iconfont.css" />
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<script src="supporter.js"></script>
<div class="d-flex mx-auto text-dark" id="main">
<div id="timer" class="justify-content-left align-content-left text-left" style="transform: translateY(3px)">
<input type="text" id="title" class="h5" maxlength="14" width="100px" /><br />
<input type="text" id="notes" class="extreme-small text-muted" maxlength="39" width="100px" /><br
id="notes-space" />
<div class="extreme-small" id="floating-close">
<a href="javascript: call('external-title-destroy')" class="text-muted text-right">
<i class="iconfont icon-close" id="exit"></i>
</a>
</div>
<script>
$('#exit').attr('title', i18n.__('exit'));
</script>
</div>
</div><!-- for things with 'work' mark, when it's resting, the color should be changed -->
<script>
if (process.platform === "darwin") {
$("#floating-close").css("display", "none");
}
let largerSpanW = 160;
let titleNode = document.getElementById("title");
titleNode.addEventListener('input', titleNodeResizer);
function titleNodeResizer() {
let n = document.createElement('h5');
n.style.display = "inline-block";
n.style.whiteSpace = "pre";
n.style.maxWidth = "100%";
n.innerHTML = titleNode.value;
titleNode.parentNode.insertBefore(n, titleNode.nextSibling);
let spanW = n.getBoundingClientRect().width;
if (spanW < 10) spanW = 100;
if (spanW > largerSpanW) {
largerSpanW = spanW;
ipc.send("external-title-resize", largerSpanW + 30);
} else turnSmallerResizer();
titleNode.parentNode.removeChild(n);
titleNode.style.width = spanW + 'px';
ipc.send("sync-timer-win-title", { title: titleNode.value, notes: notesNode.value })
}
let notesNode = document.getElementById("notes");
notesNode.addEventListener('input', notesNodeResizer);
function notesNodeResizer() {
let n = document.createElement('span');
n.classList.add("extreme-small");
n.style.display = "inline-block";
n.style.whiteSpace = "pre";
n.style.maxWidth = "100%";
n.innerHTML = notesNode.value;
notesNode.parentNode.insertBefore(n, notesNode.nextSibling);
let spanW = n.getBoundingClientRect().width;
if (spanW < 5) spanW = 100;
if (spanW > largerSpanW) {
largerSpanW = spanW;
ipc.send("external-title-resize", largerSpanW + 30);
} else turnSmallerResizer();
notesNode.parentNode.removeChild(n);
notesNode.style.width = spanW + 'px';
ipc.send("sync-timer-win-title", { title: titleNode.value, notes: notesNode.value })
}
function turnSmallerResizer() {
function max(width1, width2) {
return (width1 > width2) ? width1 : width2;
}
if (max(document.getElementById("title").getBoundingClientRect().width, document.getElementById("notes").getBoundingClientRect().width) < largerSpanW) {
largerSpanW = max(document.getElementById("title").getBoundingClientRect().width, document.getElementById("notes").getBoundingClientRect().width);
ipc.send("external-title-resize", largerSpanW + 16);
}
}
ipc.on("send-title", function (event, message) {
$("#title").val(message.title);
$("#notes").val(message.notes);
titleNodeResizer();
notesNodeResizer();
})
</script>
<script src="renderer.js"></script>
</body>
</html>