This commit is contained in:
kornerr committed 2021-08-31 15:30:03 +03:00
1 parent 9b29d56786
commit dc85b0571f
10 files changed
+86 -7

No files matched your search

@@ -3,6 +3,7 @@ function Редактор(имяОбласти)
this.создать = function()
{
this.установитьAce();
this.улавливатьРедактирование();
};
this.установитьAce = function()
@@ -12,6 +13,63 @@ function Редактор(имяОбласти)
this.ace.session.setMode("ace/mode/javascript");
}
this.улавливатьРедактирование = function()
{
var тут = this;
this.ace.session.on("change", function(дельта) {
const билет = тут.uuid();
тут.билет = билет;
setTimeout(
function()
{
if (билет == тут.билет)
{
тут.проверитьКорректностьКода();
}
},
1000
);
});
};
this.проверитьКорректностьКода = function()
{
try
{
eval(this.ace.session.getValue());
/**/console.debug("ИГР Редактор.проверитьКК OK");
}
catch (ошибка)
{
/**/console.debug("ИГР Редактор.проверитьКК ОШИБКА: ", ошибка);
}
};
this.в64 = function(строка)
{
var байты = new TextEncoder("utf-8").encode(строка);
return base64js.fromByteArray(байты);
};
this.из64 = function(строка)
{
var байты = base64js.toByteArray(строка);
return new TextDecoder("utf-8").decode(байты);
};
this.uuid = function()
{
// https://stackoverflow.com/a/2117523
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(
/[xy]/g,
function(c)
{
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
}
);
};
// Конструктор.
this.создать();
}