main.js 2.7 KB

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