You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
2.1KB

  1. function Редактор(имяОбласти)
  2. {
  3. this.создать = function()
  4. {
  5. this.установитьAce();
  6. this.улавливатьРедактирование();
  7. };
  8. this.установитьAce = function()
  9. {
  10. var область = document.getElementById(имяОбласти);
  11. this.ace = window.ace.edit(имяОбласти);
  12. this.ace.session.setMode("ace/mode/javascript");
  13. }
  14. this.улавливатьРедактирование = function()
  15. {
  16. var тут = this;
  17. this.ace.session.on("change", function(дельта) {
  18. const билет = тут.uuid();
  19. тут.билет = билет;
  20. setTimeout(
  21. function()
  22. {
  23. if (билет == тут.билет)
  24. {
  25. тут.проверитьКорректностьКода();
  26. }
  27. },
  28. 1000
  29. );
  30. });
  31. };
  32. this.проверитьКорректностьКода = function()
  33. {
  34. try
  35. {
  36. eval(this.ace.session.getValue());
  37. /**/console.debug("ИГР Редактор.проверитьКК OK");
  38. }
  39. catch (ошибка)
  40. {
  41. /**/console.debug("ИГР Редактор.проверитьКК ОШИБКА: ", ошибка);
  42. }
  43. };
  44. this.в64 = function(строка)
  45. {
  46. var байты = new TextEncoder("utf-8").encode(строка);
  47. return base64js.fromByteArray(байты);
  48. };
  49. this.из64 = function(строка)
  50. {
  51. var байты = base64js.toByteArray(строка);
  52. return new TextDecoder("utf-8").decode(байты);
  53. };
  54. this.uuid = function()
  55. {
  56. // https://stackoverflow.com/a/2117523
  57. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(
  58. /[xy]/g,
  59. function(c)
  60. {
  61. var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
  62. return v.toString(16);
  63. }
  64. );
  65. };
  66. // Конструктор.
  67. this.создать();
  68. }