main.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Imports
  2. import {createVariable, deleteAllVariable} from './modules/variables/variables';
  3. import {createOperation, createPrintOperation, 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 printButton = document.getElementById('printButton');
  17. const runCodeButton = document.getElementById('runCodeButton');
  18. const cleanCommands = document.getElementById('cleanCommands');
  19. const ivprogConsoleClearbtn = document.getElementById('ivprog-console-clearbtn');
  20. export function initAccessibleUI () {
  21. // Initializing dropdown menus
  22. $(".dropdown-submenu a.test").on("click", function (e) {
  23. $(this).next("ul").toggle();
  24. e.stopPropagation();
  25. e.preventDefault();
  26. });
  27. $('#goToCommands').click(ev => {
  28. $('#commands').click();
  29. });
  30. // Adding listeners
  31. createVariableButton.addEventListener('click', ev => {
  32. createVariable();
  33. });
  34. assignVariableButton.addEventListener('click', ev => {
  35. createOperation();
  36. });
  37. printButton.addEventListener('click', ev => {
  38. createPrintOperation();
  39. });
  40. runCodeButton.addEventListener('click', ev => {
  41. ivprogConsoleClearbtn.click();
  42. runCode();
  43. });
  44. cleanCommands.addEventListener('click', ev => {
  45. deleteAllVariable();
  46. deleteAllOperation();
  47. });
  48. }
  49. // ***********************************************************************
  50. // Reference: https://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid
  51. export function generateUUID () {
  52. return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
  53. (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
  54. );
  55. }
  56. // ***********************************************************************