Advertisement
jargon

Linedancer (LD4) :: "UI/Drop Down Menu/Creation.js"

Jan 9th, 2025 (edited)
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Linedancer (LD4) :: "UI/Drop Down Menu/Creation.js"
  2.  
  3. /**
  4.  * Create the dropdown menu dynamically
  5.  */
  6. createDropdownMenu() {
  7.     const dropdownContainer = document.createElement('div');
  8.     Object.assign(dropdownContainer.style, {
  9.         position: 'fixed',
  10.         top: '10px',
  11.         right: '10px',
  12.         zIndex: '1000',
  13.         backgroundColor: 'rgba(0,0,0,0.85)',
  14.         padding: '10px',
  15.         border: '1px solid #ccc',
  16.         borderRadius: '5px'
  17.     });
  18.  
  19.     const caption = document.createElement('div');
  20.     caption.textContent = 'Menu ▼';
  21.     Object.assign(caption.style, {
  22.         color: 'white',
  23.         fontSize: '16px',
  24.         padding: '5px',
  25.         textAlign: 'center',
  26.         cursor: 'pointer'
  27.     });
  28.  
  29.     const optionsContainer = document.createElement('div');
  30.     Object.assign(optionsContainer.style, {
  31.         display: 'none',
  32.         flexDirection: 'column',
  33.         backgroundColor: 'rgba(0,0,0,0.95)',
  34.         borderRadius: '5px',
  35.         border: '1px solid #ccc',
  36.         marginTop: '5px',
  37.         right: '0px',
  38.         position: 'relative',
  39.         width: '120px',
  40.     });
  41.  
  42.     // Static options
  43.     const options = [
  44.         { value: 'redirect::exit', label: 'Exit' },
  45.         { value: 'redirect::reset', label: 'Reset' }
  46.     ];
  47.    
  48.     this.availableGamepads = [];
  49.    
  50. // Fetch additional gamepad options
  51. fetch(`http://${window.location.hostname}/LD4/Linedancer/scripts/php/UI/Gamepad/Available Gamepads.php`)
  52.     .then(response => {
  53.         if (!response.ok) {
  54.             throw new Error(`Failed to fetch gamepads: ${response.statusText}`);
  55.         }
  56.         return response.json();
  57.     })
  58.     .then(data => {
  59.         //const options = []; // Initialize options array
  60.  
  61.         data.forEach(gamepad => {
  62.             gamepad = gamepad.replace(/\.json$/, ''); // Remove .json extension
  63.             options.push({ value: `gamepad::${gamepad}`, label: gamepad });
  64.            
  65.             this.availableGamepads.push(gamepad);
  66.         });
  67.  
  68.         console.log("Available gamepads:", this.availableGamepads); // Log the modified options array
  69.  
  70.         this.populateDropdownOptions(options, optionsContainer); // Populate fetched options
  71.     })
  72.     .catch(error => {
  73.         console.error("Error fetching available gamepads:", error);
  74.     });
  75.  
  76.     // Populate static options immediately
  77.     this.populateDropdownOptions(options, optionsContainer);
  78.  
  79.     caption.addEventListener('click', () => {
  80.         this.toggleDropdown(optionsContainer, dropdownContainer);
  81.     });
  82.  
  83.     dropdownContainer.appendChild(caption);
  84.     dropdownContainer.appendChild(optionsContainer);
  85.     document.body.appendChild(dropdownContainer);
  86. }
  87.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement