main.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Imports
  2. import {createVariable, deleteAllVariable} from './modules/variables/variables';
  3. import {createOperation, deleteAllOperation} from './modules/operations/operations';
  4. import {runCode} from "./compiler";
  5. // Imports
  6. // Html references
  7. export const htmlOlCommandsVariables = document.getElementById('htmlOlCommandsVariablesVariables');
  8. export const htmlOlCommandsOperations = document.getElementById('htmlOlCommandsVariablesOperations');
  9. export const terminal = document.getElementById('terminal');
  10. // ***********************************************************************
  11. // Init Accessible UI
  12. // ***********************************************************************
  13. // Accessible UI buttons references
  14. const createVariableButton = document.getElementById('createVariableButton');
  15. const assignVariableButton = document.getElementById('assignVariableButton');
  16. const runCodeButton = document.getElementById('runCodeButton');
  17. const cleanCommands = document.getElementById('cleanCommands');
  18. export function initAccessibleUI () {
  19. // Initializing dropdown menus
  20. $(".dropdown-submenu a.test").on("click", function (e) {
  21. $(this).next("ul").toggle();
  22. e.stopPropagation();
  23. e.preventDefault();
  24. });
  25. $('#goToCommands').click(ev => {
  26. $('#commands').click();
  27. });
  28. // Adding listeners
  29. createVariableButton.addEventListener('click', ev => {
  30. createVariable();
  31. });
  32. assignVariableButton.addEventListener('click', ev => {
  33. createOperation();
  34. });
  35. runCodeButton.addEventListener('click', ev => {
  36. runCode();
  37. });
  38. cleanCommands.addEventListener('click', ev => {
  39. deleteAllVariable();
  40. deleteAllOperation();
  41. });
  42. }
  43. // ***********************************************************************
  44. // Reference: https://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid
  45. export function generateUUID () {
  46. return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
  47. (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
  48. );
  49. }
  50. // ***********************************************************************