-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
142 lines (106 loc) · 4.1 KB
/
script.js
File metadata and controls
142 lines (106 loc) · 4.1 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
document.addEventListener("DOMContentLoaded", () => {
const theme = localStorage.getItem("theme") || "light";
document.body.classList.toggle("dark", theme === "dark");
});
function toggleDarkMode() {
const isDark = document.body.classList.toggle("dark");
localStorage.setItem("theme", isDark ? "dark" : "light");
}
function toggleSidebar() {
const sidebar = document.querySelector('.sidebar');
sidebar.classList.toggle('show');
}
dragElement(document.querySelector(".horizontal #separator"), "H");
function dragElement(element, direction) {
const drag = { x: 0, y: 0 };
const delta = { x: 0, y: 0 };
element.onmousedown = dragMouseDown;
function dragMouseDown(e) {
drag.x = e.clientX;
drag.y = e.clientY;
document.onmousemove = onMouseMove;
document.onmouseup = () => {
document.onmousemove = document.onmouseup = null;
};
}
function onMouseMove(e) {
const first = document.getElementById("first");
const second = document.getElementById("second");
if (direction === "H") {
const currentX = e.clientX;
delta.x = currentX - drag.x;
let firstWidth = first.clientWidth + delta.x;
let secondWidth = second.clientWidth - delta.x;
const splitterWidth = document.getElementById("splitter").clientWidth;
if (firstWidth >= 0 && secondWidth >= 0 && (firstWidth + secondWidth) <= splitterWidth) {
first.style.width = firstWidth + "px";
second.style.width = secondWidth + "px";
element.style.left = firstWidth + "px";
}
drag.x = currentX;
} else if (direction === "V") {
const currentY = e.clientY;
delta.y = currentY - drag.y;
let firstHeight = first.clientHeight + delta.y;
let secondHeight = second.clientHeight - delta.y;
const splitterHeight = document.getElementById("splitter").clientHeight;
if (firstHeight >= 0 && secondHeight >= 0 && (firstHeight + secondHeight) <= splitterHeight) {
first.style.height = firstHeight + "px";
second.style.height = secondHeight + "px";
element.style.top = firstHeight + "px";
}
drag.y = currentY;
}
setSizeIndicator();
}
}
document.addEventListener('DOMContentLoaded', function () {
if (window.innerWidth <= 430) {
setOrientation();
}
setSizeIndicator();
window.addEventListener('resize', setSizeIndicator);
let textBoxes = document.querySelectorAll(".textbox");
textBoxes.forEach(textBox => {
textBox.addEventListener('keydown', (e) => {
if (e.key == 'Tab') {
e.preventDefault();
var start = textBox.selectionStart;
var end = textBox.selectionEnd;
textBox.value = textBox.value.substring(0, start) +
"\t" + textBox.value.substring(end);
textBox.selectionEnd = start + 1;
}
});
});
});
function setSizeIndicator() {
const first = document.querySelector("#first");
const second = document.querySelector("#second");
const splitter = document.querySelector(".splitter");
let sizeIndicator = document.getElementById("sizeIndicator");
if (splitter.classList.contains("horizontal")) {
const firstWidth = first.clientWidth;
const secondWidth = second.clientWidth;
sizeIndicator.innerHTML = firstWidth + " x " + secondWidth;
} else if (splitter.classList.contains("vertical")) {
const firstHeight = first.clientHeight;
const secondHeight = second.clientHeight;
sizeIndicator.innerHTML = firstHeight + " x " + secondHeight;
}
}
function setOrientation(orientation = "") {
var splitter = document.querySelector(".splitter");
if (splitter.classList.contains("horizontal")) {
splitter.classList.remove("horizontal");
splitter.classList.add("vertical");
dragElement(document.querySelector(".vertical #separator"), "V");
} else if (splitter.classList.contains("vertical")) {
splitter.classList.remove('vertical');
splitter.classList.add('horizontal');
dragElement(document.querySelector(".horizontal #separator"), "H");
}
setSizeIndicator();
let orientationIcon = document.querySelector(".orientation-icon");
orientationIcon.classList.toggle('rotate-90');
}