Skip to content

Commit f8aafe2

Browse files
committed
Commented clickMenu.js a little more
I'm beginning work on the embed builder menu, and had no idea what was going on in the clickMenu.js file. I updated some deprecations, and added some comments (to the left click section) to get a better understanding of what is going on.
1 parent 5516ec6 commit f8aafe2

2 files changed

Lines changed: 26 additions & 7 deletions

File tree

js/clickMenu.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414

1515
"use strict";
1616

17-
const { User } = require('discord.js');
17+
18+
// This file handles all menus that appear out of nowhere when an element is clicked
19+
1820

1921
function addDocListener() {
2022
document.addEventListener('keydown', (e) => {
@@ -35,39 +37,52 @@ function addDocListener() {
3537
let y = e.clientY;
3638

3739
let rcMenu = document.getElementById('rcMenu');
38-
if (e.which == 1) {
40+
if (e.button == 0) {
3941
// Left click
4042
// Close the right click menus
4143
rcMenu.classList.remove('open');
4244

4345
// Find if a distant child of certain parent
4446
let domElements = ['mLOuterDiv', 'memberMenu'];
47+
// If the element clicked is not in domElements, recurse to the parent
48+
// The purpose of this is to check that anywhere inside of an element, even one of the children, is clicked
4549
while (
4650
!domElements.some((r) => target.classList.contains(r)) &&
4751
target != document.body
4852
) {
4953
target = target.parentElement;
5054
}
55+
56+
// If the element clicked is not the member menu, delete the member menu
5157
if (!target.classList.contains(domElements[1])) {
5258
let element = document.getElementsByClassName('memberMenu')[0];
5359
if (element) element.parentElement.removeChild(element);
5460
}
5561
if (target == document.body) return;
5662

57-
// Build the member menu
63+
// If the element clicked is a member on the member list, build the member menu
5864
if (target.classList.contains(domElements[0])) {
5965
buildMemberMenu(target);
6066
}
61-
} else if (e.which == 3) {
67+
68+
// This is not in the domElements, because it has no child elements to check for
69+
if (target.id == "embedBuilderIcon") {
70+
buildEmbedMenu();
71+
}
72+
73+
// If the element clicked is not the embed builder menu, delete the embed builder menu
74+
75+
} else if (e.button == 2) {
6276
// Right click
6377
// Clear the menu (It's only needed here because you only open it when you right click)
6478
rcMenu.innerHTML = '';
6579

6680
if (
6781
e.target.classList.contains('rcOption') ||
6882
e.target.parentElement.classList.contains('rcOption')
69-
)
83+
) {
7084
return rcMenu.classList.remove('open');
85+
}
7186
// Get the message block containing the message
7287
let domElements = [
7388
'messageBlock',
@@ -113,7 +128,7 @@ function addDocListener() {
113128

114129
rcMenu.style.left = `${x}px`;
115130
rcMenu.style.top = `${y}px`;
116-
} else if (e.which == 2) {
131+
} else if (e.button == 1) {
117132
} // Check if it's middle click since you don't need to remove it if it is
118133
else rcMenu.classList.remove('open');
119134
});

js/embedMenu.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
"use strict";
15+
"use strict";
16+
17+
function buildEmbedMenu() {
18+
19+
}

0 commit comments

Comments
 (0)