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
1921function 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 } ) ;
0 commit comments