Skip to content

Commit 9542cce

Browse files
committed
Added a line and reworked the selection mechanic
1 parent a2dc5ca commit 9542cce

File tree

2 files changed

+41
-33
lines changed

2 files changed

+41
-33
lines changed

resources/ext.multicodeblock/css/codeblock.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656

5757
.inner.tab-content {
5858
margin-top: calc(-2em - 10px);
59+
padding: 0;
60+
padding-top: 15px;
5961
}
6062

6163
.inner.tab-sidebar {
@@ -133,6 +135,10 @@
133135
font-size: 15.2px;
134136
}
135137

138+
.code-table th.second {
139+
border-bottom: solid .5px rgba(204, 204, 204, .5);
140+
}
141+
136142
.copy {
137143
position: absolute;
138144
right: 0;

resources/ext.multicodeblock/js/multicodeblock.js

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -33,56 +33,58 @@ for (let i = 0; i < tabButtons.length; i++) {
3333
/* Hover mechanics */
3434

3535
const second = document.getElementsByClassName('second');
36-
let lockedElems = [];
36+
let lockedElems = null;
37+
let firstClick = true;
3738

38-
let secondMouseDown = false;
39-
let lastMouseUp = false;
40-
let lastMouseDown = false;
41-
let lockClick = true;
39+
let currentElem = null;
4240

4341
for(let i = 0; i < second.length; i++) {
4442
second[i].addEventListener('mouseover', () => {
45-
if(!lastMouseUp) {
46-
second[i].classList.add('onHover');
47-
}
43+
second[i].classList.add('onHover');
4844

49-
if(secondMouseDown) {
50-
let secondElem = second[i].parentElement.getElementsByClassName('first')[0];
51-
secondElem.classList.add('locked');
52-
lockedElems.push(secondElem);
53-
}
45+
currentElem = second[i];
5446
});
5547

5648
second[i].addEventListener('mouseout', () => {
57-
if(!secondMouseDown && !lastMouseUp) {
58-
second[i].classList.remove('onHover');
59-
}
49+
currentElem = null;
50+
51+
if(lockedElems !== null)
52+
return;
53+
54+
second[i].classList.remove('onHover');
6055
});
6156

6257
second[i].addEventListener('mousedown', () => {
63-
secondMouseDown = true;
64-
lastMouseDown = true;
65-
});
58+
lockedElems = second[i].parentElement.parentElement.getElementsByClassName('first');
6659

67-
second[i].addEventListener('mouseup', () => {
68-
secondMouseDown = false;
69-
lastMouseUp = true;
70-
setTimeout(function(){lockClick = false;},5);
60+
for(let i = 0; i < lockedElems.length; ++i) {
61+
lockedElems[i].classList.add('locked');
62+
}
7163
});
7264
}
7365

74-
document.addEventListener('click', () => {
75-
if(!lockClick) {
76-
lastMouseUp = false;
77-
for(let i = 0;i < lockedElems.length; i++) {
78-
lockedElems[i].classList.remove('locked');
79-
}
80-
for(let i = 0; i < second.length; i++) {
81-
second[i].classList.remove('onHover');
82-
}
66+
document.addEventListener('click', (event) => {
67+
if(lockedElems === null)
68+
return;
69+
70+
if(firstClick) {
71+
firstClick = false;
72+
return;
73+
}
8374

84-
lockClick = true;
75+
for(let i = 0; i < lockedElems.length; ++i) {
76+
lockedElems[i].classList.remove('locked');
8577
}
78+
79+
lockedElems = null;
80+
81+
for(let i = 0; i < second.length; ++i) {
82+
second[i].classList.remove('onHover');
83+
}
84+
85+
firstClick = true;
86+
87+
currentElem?.classList.add('onHover');
8688
});
8789

8890
/* Copy */

0 commit comments

Comments
 (0)