Выгрузить модули
This commit is contained in:
1 parent
0fc9d3020e
commit
0bb9e77495
9 files changed
+911
-77
No files matched your search
@@ -1,13 +0,0 @@
|
|||||||
// Create GUID / UUID in JavaScript?
|
|
||||||
// https://stackoverflow.com/a/2117523
|
|
||||||
муром.uuid = function()
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@@ -1,3 +1,29 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* UUID
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Create GUID / UUID in JavaScript?
|
||||||
|
// https://stackoverflow.com/a/2117523
|
||||||
|
муром.uuid = function()
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Уведомитель / Reporter
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
// ReporterSubscription class.
|
// ReporterSubscription class.
|
||||||
function ReporterSubscription(id, callback, reporter)
|
function ReporterSubscription(id, callback, reporter)
|
||||||
{
|
{
|
||||||
@@ -52,3 +78,22 @@ Reporter.prototype.подписатьМного = function(funcs)
|
|||||||
{
|
{
|
||||||
this.subscribeMany(funcs);
|
this.subscribeMany(funcs);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Пуск / Start
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
муром.пуск = new Уведомитель();
|
||||||
|
// Can also be accessed as 'murom.run'.
|
||||||
|
Object.defineProperty(murom, "run", {
|
||||||
|
get: function()
|
||||||
|
{
|
||||||
|
return муром.пуск;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
murom.start = function()
|
||||||
|
{
|
||||||
|
муром.пуск.уведомить();
|
||||||
|
};
|
||||||
@@ -1,3 +1,12 @@
|
|||||||
|
/*
|
||||||
|
* NOTE Only ASCII is allowed in this loading module
|
||||||
|
* NOTE because it's deciphered with btoa() call,
|
||||||
|
* NOTE which can't handle Unicode.
|
||||||
|
* NOTE However, murom.atob/btoa functions (defined here)
|
||||||
|
* NOTE work fine with Unicode, so you are free
|
||||||
|
* NOTE to use Unicode in other modules
|
||||||
|
*/
|
||||||
|
|
||||||
murom.installLocalForage = function()
|
murom.installLocalForage = function()
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
@@ -36,10 +45,27 @@ function TextEncoderLite(){}function TextDecoderLite(){}(function(){"use strict"
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
murom.moduleProperties = function(id)
|
||||||
|
{
|
||||||
|
var m = murom.modules[id];
|
||||||
|
return (typeof m[2] != "undefined") ? m[2] : {};
|
||||||
|
};
|
||||||
|
|
||||||
|
murom.moduleStatus = function(id)
|
||||||
|
{
|
||||||
|
var prop = murom.moduleProperties(id);
|
||||||
|
if ("status" in prop)
|
||||||
|
{
|
||||||
|
return prop["status"];
|
||||||
|
}
|
||||||
|
// Status == true if explicit record is absent.
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
murom.start = function()
|
murom.start = function()
|
||||||
{
|
{
|
||||||
console.log("Override 'murom.start()' in any of the modules to be notified when all modules are loaded");
|
console.debug("Override murom.start() function to be notified when all modules were loaded");
|
||||||
};
|
}
|
||||||
|
|
||||||
murom.loadModules = function()
|
murom.loadModules = function()
|
||||||
{
|
{
|
||||||
@@ -49,10 +75,9 @@ murom.loadModules = function()
|
|||||||
var module = murom.modules[i];
|
var module = murom.modules[i];
|
||||||
var name = module[0];
|
var name = module[0];
|
||||||
var code = murom.atob(module[1]);
|
var code = murom.atob(module[1]);
|
||||||
var state = module[2];
|
if (murom.moduleStatus(i) == false)
|
||||||
if (state == false)
|
|
||||||
{
|
{
|
||||||
console.log("WARNING Skip loading '" + name + "' module because it's turned off");
|
console.warn("Skip loading '" + name + "' module because it's turned off");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -62,7 +87,7 @@ murom.loadModules = function()
|
|||||||
}
|
}
|
||||||
catch (e)
|
catch (e)
|
||||||
{
|
{
|
||||||
console.log("ERROR Could not load '" + name + "' module: '" + e + "'");
|
console.error("Could not load '" + name + "' module: '" + e + "'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -79,11 +104,11 @@ murom.loadIndexedDBModules = function(completionHandler)
|
|||||||
if (modules)
|
if (modules)
|
||||||
{
|
{
|
||||||
murom.modules = modules;
|
murom.modules = modules;
|
||||||
console.log("Modules have been loaded from IndexedDB");
|
console.debug("Modules have been loaded from IndexedDB");
|
||||||
}
|
}
|
||||||
if (error)
|
if (error)
|
||||||
{
|
{
|
||||||
console.log("ERROR Getting modules from IndexedDB: '" + error + "'");
|
console.error("Could not get modules from IndexedDB: '" + error + "'");
|
||||||
}
|
}
|
||||||
// Continue.
|
// Continue.
|
||||||
completionHandler();
|
completionHandler();
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
муром.создатьЛевуюПравуюОбласти = function()
|
||||||
|
{
|
||||||
|
// Левая область.
|
||||||
|
var ло = document.createElement("div");
|
||||||
|
ло.id="левая-область";
|
||||||
|
ло.style.cssText =
|
||||||
|
"position: fixed; left: 0; top: 0; bottom: 0; width: 50%;";
|
||||||
|
document.body.appendChild(ло);
|
||||||
|
|
||||||
|
// Правая область.
|
||||||
|
var по = document.createElement("div");
|
||||||
|
по.id="правая-область";
|
||||||
|
по.style.cssText =
|
||||||
|
"position: fixed; right: 0; top: 0; bottom: 0; width: 50%;";
|
||||||
|
document.body.appendChild(по);
|
||||||
|
|
||||||
|
return [ло, по];
|
||||||
|
};
|
||||||
@@ -0,0 +1,765 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Внешний вид
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
function задатьВнешнийВид()
|
||||||
|
{
|
||||||
|
var вид = document.createElement("style");
|
||||||
|
document.head.appendChild(вид);
|
||||||
|
вид.innerHTML =
|
||||||
|
`
|
||||||
|
.муром-кнопка
|
||||||
|
{
|
||||||
|
padding: 0.5em 2em 0.5em 2em;
|
||||||
|
margin-right: 0.5em;
|
||||||
|
float: right;
|
||||||
|
color: #222;
|
||||||
|
font-family: sans-serif;
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
background-color: transparent;
|
||||||
|
cursor: pointer;
|
||||||
|
text-transform: uppercase;
|
||||||
|
-webkit-transition-duration: 0.2s; /* Safari */
|
||||||
|
transition-duration: 0.2s;
|
||||||
|
}
|
||||||
|
.муром-кнопка:hover
|
||||||
|
{
|
||||||
|
border: 1px solid #222;
|
||||||
|
}
|
||||||
|
.муром-отступ-по-сторонам
|
||||||
|
{
|
||||||
|
margin-left: 0.5em;
|
||||||
|
margin-right: 0.5em;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Список модулей
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
function СписокМодулей()
|
||||||
|
{
|
||||||
|
var я = this;
|
||||||
|
|
||||||
|
this.создатьИнтерфейс();
|
||||||
|
this.задатьВид();
|
||||||
|
this.выбрали = new Уведомитель();
|
||||||
|
this.выбрали.подписать(function(){
|
||||||
|
я.отобразитьВыбор();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
СписокМодулей.prototype.создатьИнтерфейс = function()
|
||||||
|
{
|
||||||
|
// Помещаем таблицу в div для реализации промотки.
|
||||||
|
this.иф = document.createElement("div");
|
||||||
|
this.таблица = document.createElement("table");
|
||||||
|
this.иф.appendChild(this.таблица);
|
||||||
|
};
|
||||||
|
СписокМодулей.prototype.задатьВид = function()
|
||||||
|
{
|
||||||
|
this.иф.style.cssText =
|
||||||
|
`
|
||||||
|
overflow: auto;
|
||||||
|
height: 18.5em;
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
/*
|
||||||
|
padding: 0.5em;
|
||||||
|
margin: 0.5em;
|
||||||
|
*/
|
||||||
|
`;
|
||||||
|
this.таблица.style.cssText =
|
||||||
|
`
|
||||||
|
color: #666666;
|
||||||
|
font-family: sans-serif;
|
||||||
|
cursor: default;
|
||||||
|
border-collapse: collapse;
|
||||||
|
`;
|
||||||
|
};
|
||||||
|
СписокМодулей.prototype.очистить = function()
|
||||||
|
{
|
||||||
|
while (this.таблица.rows.length)
|
||||||
|
{
|
||||||
|
this.таблица.deleteRow(0);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
СписокМодулей.prototype.добавитьЭлемент = function(статус, имя)
|
||||||
|
{
|
||||||
|
var статусHTML = "";
|
||||||
|
if (статус)
|
||||||
|
{
|
||||||
|
статусHTML = "checked";
|
||||||
|
}
|
||||||
|
|
||||||
|
var ряд = this.таблица.insertRow();
|
||||||
|
var ячейка = 0;
|
||||||
|
|
||||||
|
var номер = ряд.insertCell(ячейка++);
|
||||||
|
номер.innerHTML = this.таблица.rows.length - 1;
|
||||||
|
номер.style.cssText = "padding: 0.5em;";
|
||||||
|
|
||||||
|
var вкл = ряд.insertCell(ячейка++);
|
||||||
|
вкл.innerHTML = `<input type="checkbox" disabled ` + статусHTML + `></input>`;
|
||||||
|
|
||||||
|
var название = ряд.insertCell(ячейка++);
|
||||||
|
название.innerHTML = имя;
|
||||||
|
название.style.cssText = "padding: 0.5em; width: 100%;";
|
||||||
|
};
|
||||||
|
СписокМодулей.prototype.отобразитьСписок = function(список)
|
||||||
|
{
|
||||||
|
this.очистить();
|
||||||
|
for (var номер in список)
|
||||||
|
{
|
||||||
|
var элемент = список[номер];
|
||||||
|
var статус = элемент[0];
|
||||||
|
var имя = элемент[1];
|
||||||
|
this.добавитьЭлемент(статус, имя);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
СписокМодулей.prototype.улавливатьВыборЭлемента = function(номер)
|
||||||
|
{
|
||||||
|
var я = this;
|
||||||
|
|
||||||
|
var ряд = this.таблица.rows[номер]
|
||||||
|
ряд.onclick = function()
|
||||||
|
{
|
||||||
|
я.выборРанее = я.выбор;
|
||||||
|
я.выбор = номер;
|
||||||
|
я.выбрали.уведомить();
|
||||||
|
};
|
||||||
|
};
|
||||||
|
СписокМодулей.prototype.улавливатьВыбор = function()
|
||||||
|
{
|
||||||
|
this.выборРанее = null;
|
||||||
|
this.выбор = null;
|
||||||
|
for (var номер = 0; номер < this.таблица.rows.length; ++номер)
|
||||||
|
{
|
||||||
|
this.улавливатьВыборЭлемента(номер);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
СписокМодулей.prototype.отобразитьВыбор = function()
|
||||||
|
{
|
||||||
|
if (this.выборРанее != null)
|
||||||
|
{
|
||||||
|
var ряд = this.таблица.rows[this.выборРанее];
|
||||||
|
ряд.style.backgroundColor = null;
|
||||||
|
}
|
||||||
|
var ряд = this.таблица.rows[this.выбор];
|
||||||
|
ряд.style.backgroundColor = "#eee";
|
||||||
|
};
|
||||||
|
СписокМодулей.prototype.задатьСписок = function(список)
|
||||||
|
{
|
||||||
|
this.отобразитьСписок(список);
|
||||||
|
this.улавливатьВыбор();
|
||||||
|
};
|
||||||
|
СписокМодулей.prototype.выбрать = function(номер)
|
||||||
|
{
|
||||||
|
var ряд = this.таблица.rows[номер];
|
||||||
|
ряд.scrollIntoView();
|
||||||
|
ряд.onclick();
|
||||||
|
};
|
||||||
|
СписокМодулей.prototype.обновитьЭлемент = function(номер, статус, имя)
|
||||||
|
{
|
||||||
|
var ряд = this.таблица.rows[номер];
|
||||||
|
ряд.cells[1].childNodes[0].checked = статус;
|
||||||
|
ряд.cells[2].innerHTML = имя;
|
||||||
|
};
|
||||||
|
СписокМодулей.prototype.удалитьЭлемент = function(номер)
|
||||||
|
{
|
||||||
|
var ряд = this.таблица.rows[номер];
|
||||||
|
ряд.parentNode.removeChild(ряд);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Тест списка модулей
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
function ТестСпискаМодулей()
|
||||||
|
{
|
||||||
|
this.создатьИнтерфейс();
|
||||||
|
}
|
||||||
|
ТестСпискаМодулей.prototype.создатьИнтерфейс = function()
|
||||||
|
{
|
||||||
|
var я = this;
|
||||||
|
|
||||||
|
this.иф = document.createElement("div");
|
||||||
|
this.список = new СписокМодулей();
|
||||||
|
this.иф.appendChild(this.список.иф);
|
||||||
|
|
||||||
|
var модули = [
|
||||||
|
[true, "муром.загрузка_1.0.0"],
|
||||||
|
[true, "муром.uuid_1.0.0"],
|
||||||
|
[true, "Уведомитель_1.0.0"],
|
||||||
|
[false, "uikit_3.2.0.css"],
|
||||||
|
[false, "uikit_3.2.0.js"],
|
||||||
|
[false, "ПанельУправления.UIKit"],
|
||||||
|
[false, "ПанельУправления_1.0.0"],
|
||||||
|
];
|
||||||
|
|
||||||
|
this.список.задатьСписок(модули);
|
||||||
|
this.список.выбрать(0);
|
||||||
|
|
||||||
|
this.создатьКнопку("Выбрать последний", function(){
|
||||||
|
console.log("выбрать");
|
||||||
|
я.список.выбрать(модули.length - 1);
|
||||||
|
});
|
||||||
|
this.создатьКнопку("Обновить последний", function(){
|
||||||
|
я.список.обновитьЭлемент(модули.length - 1, true, "Новое имя");
|
||||||
|
});
|
||||||
|
this.создатьКнопку("Удалить последний", function(){
|
||||||
|
я.список.удалитьЭлемент(модули.length - 1);
|
||||||
|
});
|
||||||
|
this.создатьКнопку("Добавить", function(){
|
||||||
|
я.список.добавитьЭлемент(true, "Новый-599");
|
||||||
|
var номер = я.список.таблица.rows.length - 1;
|
||||||
|
я.список.улавливатьВыборЭлемента(номер);
|
||||||
|
я.список.выбрать(номер);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
ТестСпискаМодулей.prototype.создатьКнопку = function(имя, реакция)
|
||||||
|
{
|
||||||
|
var кнопка = document.createElement("button");
|
||||||
|
кнопка.innerHTML = имя;
|
||||||
|
this.иф.appendChild(кнопка);
|
||||||
|
кнопка.onclick = реакция;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Свойства модуля
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
function СвойстваМодуля()
|
||||||
|
{
|
||||||
|
this.создатьИнтерфейс();
|
||||||
|
this.изменилиНомер = new Уведомитель();
|
||||||
|
this.настроитьНомер();
|
||||||
|
this.изменилиИмя = new Уведомитель();
|
||||||
|
this.настроитьИмя();
|
||||||
|
this.изменилиСтатус = new Уведомитель();
|
||||||
|
this.настроитьСтатус();
|
||||||
|
this.удалить = new Уведомитель();
|
||||||
|
this.настроитьУдаление();
|
||||||
|
}
|
||||||
|
СвойстваМодуля.prototype.создатьИнтерфейс = function()
|
||||||
|
{
|
||||||
|
this.иф = document.createElement("div");
|
||||||
|
this.иф.style.cssText =
|
||||||
|
`
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
/*
|
||||||
|
padding: 0.5em;
|
||||||
|
margin: 0.5em;
|
||||||
|
*/
|
||||||
|
color: #666666;
|
||||||
|
font-family: sans-serif;
|
||||||
|
`;
|
||||||
|
this.таблица = document.createElement("table");
|
||||||
|
this.иф.appendChild(this.таблица);
|
||||||
|
};
|
||||||
|
Object.defineProperty(СвойстваМодуля.prototype, "номер", {
|
||||||
|
get: function()
|
||||||
|
{
|
||||||
|
return Number(this.полеНомер.value);
|
||||||
|
},
|
||||||
|
set: function(значение)
|
||||||
|
{
|
||||||
|
this.полеНомер.value = значение;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
СвойстваМодуля.prototype.настроитьНомер = function()
|
||||||
|
{
|
||||||
|
var я = this;
|
||||||
|
|
||||||
|
var ряд = this.таблица.insertRow();
|
||||||
|
var ячейка = 0;
|
||||||
|
|
||||||
|
var ключ = ряд.insertCell(ячейка++);
|
||||||
|
ключ.innerHTML = "Номер:";
|
||||||
|
ключ.style.cssText = "padding: 0.5em;";
|
||||||
|
|
||||||
|
var значение = ряд.insertCell(ячейка++);
|
||||||
|
this.полеНомер = document.createElement("input");
|
||||||
|
this.полеНомер.type = "number";
|
||||||
|
this.полеНомер.min = 0;
|
||||||
|
значение.style.cssText = "width: 100%; padding: 0.5em;";
|
||||||
|
this.полеНомер.style.cssText = "width: 100%;";
|
||||||
|
значение.appendChild(this.полеНомер);
|
||||||
|
|
||||||
|
this.полеНомер.oninput = function()
|
||||||
|
{
|
||||||
|
я.изменилиНомер.уведомить();
|
||||||
|
};
|
||||||
|
};
|
||||||
|
Object.defineProperty(СвойстваМодуля.prototype, "имя", {
|
||||||
|
get: function()
|
||||||
|
{
|
||||||
|
return this.полеИмя.value;
|
||||||
|
},
|
||||||
|
set: function(значение)
|
||||||
|
{
|
||||||
|
this.полеИмя.value = значение;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
СвойстваМодуля.prototype.настроитьИмя = function()
|
||||||
|
{
|
||||||
|
var я = this;
|
||||||
|
|
||||||
|
var ряд = this.таблица.insertRow();
|
||||||
|
var ячейка = 0;
|
||||||
|
|
||||||
|
var ключ = ряд.insertCell(ячейка++);
|
||||||
|
ключ.innerHTML = "Имя:";
|
||||||
|
ключ.style.cssText = "padding: 0.5em;";
|
||||||
|
|
||||||
|
var значение = ряд.insertCell(ячейка++);
|
||||||
|
this.полеИмя = document.createElement("input");
|
||||||
|
значение.style.cssText = "width: 100%; padding: 0.5em;";
|
||||||
|
this.полеИмя.style.cssText = "width: 100%;";
|
||||||
|
значение.appendChild(this.полеИмя);
|
||||||
|
|
||||||
|
this.полеИмя.oninput = function()
|
||||||
|
{
|
||||||
|
я.изменилиИмя.уведомить();
|
||||||
|
};
|
||||||
|
};
|
||||||
|
Object.defineProperty(СвойстваМодуля.prototype, "статус", {
|
||||||
|
get: function()
|
||||||
|
{
|
||||||
|
return this.переключатель.checked;
|
||||||
|
},
|
||||||
|
set: function(значение)
|
||||||
|
{
|
||||||
|
this.переключатель.checked = значение;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
СвойстваМодуля.prototype.настроитьСтатус = function()
|
||||||
|
{
|
||||||
|
var я = this;
|
||||||
|
|
||||||
|
var ряд = this.таблица.insertRow();
|
||||||
|
var ячейка = 0;
|
||||||
|
|
||||||
|
var ключ = ряд.insertCell(ячейка++);
|
||||||
|
ключ.innerHTML = "Исполнять:";
|
||||||
|
ключ.style.cssText = "padding: 0.5em;";
|
||||||
|
|
||||||
|
var значение = ряд.insertCell(ячейка++);
|
||||||
|
this.переключатель = document.createElement("input");
|
||||||
|
this.переключатель.type = "checkbox";
|
||||||
|
this.переключатель.style.cssText = "padding: 0.5em;";
|
||||||
|
значение.appendChild(this.переключатель);
|
||||||
|
|
||||||
|
this.переключатель.onchange = function()
|
||||||
|
{
|
||||||
|
я.изменилиСтатус.уведомить();
|
||||||
|
};
|
||||||
|
ключ.onclick = function()
|
||||||
|
{
|
||||||
|
я.переключатель.checked = !я.переключатель.checked;
|
||||||
|
я.изменилиСтатус.уведомить();
|
||||||
|
};
|
||||||
|
};
|
||||||
|
СвойстваМодуля.prototype.настроитьУдаление = function()
|
||||||
|
{
|
||||||
|
var я = this;
|
||||||
|
|
||||||
|
var ряд = this.таблица.insertRow();
|
||||||
|
var ячейка = 0;
|
||||||
|
|
||||||
|
ряд.insertCell(ячейка++);
|
||||||
|
var значение = ряд.insertCell(ячейка++);
|
||||||
|
|
||||||
|
this.кнопкаУдалить = document.createElement("button");
|
||||||
|
this.кнопкаУдалить.innerHTML = "Удалить";
|
||||||
|
this.кнопкаУдалить.classList.add("муром-кнопка");
|
||||||
|
значение.appendChild(this.кнопкаУдалить);
|
||||||
|
|
||||||
|
this.кнопкаУдалить.onclick = function()
|
||||||
|
{
|
||||||
|
я.удалить.уведомить();
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Тест свойства модуля
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
function ТестСвойстваМодуля()
|
||||||
|
{
|
||||||
|
this.создатьИнтерфейс();
|
||||||
|
}
|
||||||
|
ТестСвойстваМодуля.prototype.создатьИнтерфейс = function()
|
||||||
|
{
|
||||||
|
var я = this;
|
||||||
|
|
||||||
|
this.иф = document.createElement("div");
|
||||||
|
this.свойства = new СвойстваМодуля();
|
||||||
|
this.иф.appendChild(this.свойства.иф);
|
||||||
|
|
||||||
|
this.свойства.изменилиНомер.подписать(function(){
|
||||||
|
console.log("номер: '" + я.свойства.номер + "'");
|
||||||
|
});
|
||||||
|
this.свойства.изменилиИмя.подписать(function(){
|
||||||
|
console.log("имя: '" + я.свойства.имя + "'");
|
||||||
|
});
|
||||||
|
this.свойства.изменилиСтатус.подписать(function(){
|
||||||
|
console.log("статус: '" + я.свойства.статус + "'");
|
||||||
|
});
|
||||||
|
this.свойства.удалить.подписать(function(){
|
||||||
|
console.log("удалить модуль '" + я.свойства.имя + "'");
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Модули
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
function Модули()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
Модули.prototype.свойства = function(номер)
|
||||||
|
{
|
||||||
|
return murom.moduleProperties(номер);
|
||||||
|
};
|
||||||
|
Модули.prototype.задатьСвойства = function(номер, свойства)
|
||||||
|
{
|
||||||
|
var м = муром.модули[номер];
|
||||||
|
м[2] = свойства;
|
||||||
|
};
|
||||||
|
Модули.prototype.статус = function(номер)
|
||||||
|
{
|
||||||
|
return murom.moduleStatus(номер);
|
||||||
|
};
|
||||||
|
Модули.prototype.задатьСтатус = function(номер, статус)
|
||||||
|
{
|
||||||
|
var св = this.свойства(номер);
|
||||||
|
св["status"] = статус;
|
||||||
|
this.задатьСвойства(номер, св);
|
||||||
|
};
|
||||||
|
Модули.prototype.задатьИмя = function(номер, имя)
|
||||||
|
{
|
||||||
|
var м = муром.модули[номер];
|
||||||
|
м[0] = имя;
|
||||||
|
};
|
||||||
|
Модули.prototype.задатьНомер = function(старый, новый)
|
||||||
|
{
|
||||||
|
//console.log("задать номер. '" + старый + "' -> '" + новый + "'");
|
||||||
|
var модуль = муром.модули[старый];
|
||||||
|
// Удаляем старую запись.
|
||||||
|
муром.модули.splice(старый, 1);
|
||||||
|
// Добавляем модуль в новую позицию.
|
||||||
|
муром.модули.splice(новый, 0, модуль);
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Панель управления
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
function ПанельУправления()
|
||||||
|
{
|
||||||
|
this.модули = new Модули();
|
||||||
|
this.создатьОснову();
|
||||||
|
this.создатьСохранениеСкачиваниеДобавление();
|
||||||
|
this.создатьСписокМодулей();
|
||||||
|
this.создатьСвойстваМодуля();
|
||||||
|
}
|
||||||
|
ПанельУправления.prototype.создатьОбёрткуЯчейку = function()
|
||||||
|
{
|
||||||
|
var обёртка = document.createElement("table");
|
||||||
|
обёртка.style.cssText = "width: 100%;";
|
||||||
|
var ряд = обёртка.insertRow();
|
||||||
|
var ячейка = ряд.insertCell();
|
||||||
|
return [обёртка, ячейка];
|
||||||
|
};
|
||||||
|
ПанельУправления.prototype.создатьОснову = function()
|
||||||
|
{
|
||||||
|
this.иф = document.createElement("table");
|
||||||
|
this.иф.style.cssText = "width: 100%;";
|
||||||
|
var ряд = this.иф.insertRow();
|
||||||
|
this.лево = ряд.insertCell();
|
||||||
|
this.лево.style.cssText = "width: 100%;";
|
||||||
|
var право = ряд.insertCell();
|
||||||
|
право.style.cssText = "height: 100%;";
|
||||||
|
this.кнопки = document.createElement("table");
|
||||||
|
this.кнопки.style.cssText = "height: 100%;";
|
||||||
|
право.appendChild(this.кнопки);
|
||||||
|
ряд = this.иф.insertRow();
|
||||||
|
this.низ = ряд.insertCell();
|
||||||
|
this.низ.colSpan = 2;
|
||||||
|
};
|
||||||
|
ПанельУправления.prototype.создатьСписокМодулей = function()
|
||||||
|
{
|
||||||
|
this.список = new СписокМодулей();
|
||||||
|
this.список.задатьСписок(this.списокМодулей());
|
||||||
|
var оя = this.создатьОбёрткуЯчейку();
|
||||||
|
this.лево.appendChild(оя[0]);
|
||||||
|
оя[1].appendChild(this.список.иф);
|
||||||
|
};
|
||||||
|
ПанельУправления.prototype.создатьСвойстваМодуля = function()
|
||||||
|
{
|
||||||
|
this.свойства = new СвойстваМодуля();
|
||||||
|
оя = this.создатьОбёрткуЯчейку();
|
||||||
|
this.низ.appendChild(оя[0]);
|
||||||
|
оя[1].appendChild(this.свойства.иф);
|
||||||
|
};
|
||||||
|
ПанельУправления.prototype.списокМодулей = function()
|
||||||
|
{
|
||||||
|
var список = [];
|
||||||
|
for (var номер in муром.модули)
|
||||||
|
{
|
||||||
|
var м = муром.модули[номер];
|
||||||
|
var статус = this.модули.статус(номер);
|
||||||
|
var имя = м[0];
|
||||||
|
var элемент = [статус, имя];
|
||||||
|
список.push(элемент);
|
||||||
|
}
|
||||||
|
|
||||||
|
return список;
|
||||||
|
};
|
||||||
|
ПанельУправления.prototype.создатьКнопку = function(имя, уведомитель)
|
||||||
|
{
|
||||||
|
var кнопка = document.createElement("button");
|
||||||
|
кнопка.innerHTML = имя;
|
||||||
|
кнопка.style.cssText = "width: 100%;";
|
||||||
|
кнопка.classList.add("муром-кнопка");
|
||||||
|
кнопка.onclick = function()
|
||||||
|
{
|
||||||
|
уведомитель.уведомить();
|
||||||
|
};
|
||||||
|
|
||||||
|
return кнопка;
|
||||||
|
};
|
||||||
|
ПанельУправления.prototype.создатьСохранениеСкачиваниеДобавление = function()
|
||||||
|
{
|
||||||
|
var я = this;
|
||||||
|
|
||||||
|
var ряд = this.кнопки.insertRow();
|
||||||
|
var ячейка = ряд.insertCell();
|
||||||
|
this.сохранить = new Уведомитель();
|
||||||
|
this.кнопкаСохранить = this.создатьКнопку("Сохранить", this.сохранить);
|
||||||
|
ячейка.appendChild(this.кнопкаСохранить);
|
||||||
|
|
||||||
|
ряд = this.кнопки.insertRow();
|
||||||
|
ячейка = ряд.insertCell();
|
||||||
|
this.скачать = new Уведомитель();
|
||||||
|
this.кнопкаСкачать = this.создатьКнопку("Скачать", this.скачать);
|
||||||
|
ячейка.appendChild(this.кнопкаСкачать);
|
||||||
|
|
||||||
|
// Пробел.
|
||||||
|
ряд = this.кнопки.insertRow();
|
||||||
|
ячейка = ряд.insertCell();
|
||||||
|
ячейка.style.cssText = "height: 100%;";
|
||||||
|
|
||||||
|
ряд = this.кнопки.insertRow();
|
||||||
|
ячейка = ряд.insertCell();
|
||||||
|
this.добавить = new Уведомитель();
|
||||||
|
this.кнопкаДобавить = this.создатьКнопку("Добавить", this.добавить);
|
||||||
|
ячейка.appendChild(this.кнопкаДобавить);
|
||||||
|
};
|
||||||
|
ПанельУправления.prototype.имяФайла = function()
|
||||||
|
{
|
||||||
|
var путь = window.location.pathname;
|
||||||
|
var имя = путь.split("/").pop();
|
||||||
|
return decodeURI(имя);
|
||||||
|
};
|
||||||
|
|
||||||
|
function запуститьПУ()
|
||||||
|
{
|
||||||
|
var пу = new ПанельУправления();
|
||||||
|
муром.пу = пу;
|
||||||
|
var области = муром.создатьЛевуюПравуюОбласти();
|
||||||
|
var по = области[1];
|
||||||
|
по.appendChild(пу.иф);
|
||||||
|
муром.создатьРедакторВЛевойОбласти();
|
||||||
|
var список = пу.список;
|
||||||
|
var свойства = пу.свойства;
|
||||||
|
var модули = пу.модули;
|
||||||
|
|
||||||
|
function отобразитьКодВыбранногоМодуля()
|
||||||
|
{
|
||||||
|
var модуль = муром.модули[список.выбор];
|
||||||
|
var код = муром.atob(модуль[1]);
|
||||||
|
муром.редактор.session.setValue(код);
|
||||||
|
}
|
||||||
|
function отобразитьСвойстваВыбранногоМодуля()
|
||||||
|
{
|
||||||
|
var модуль = муром.модули[список.выбор];
|
||||||
|
|
||||||
|
свойства.номер = список.выбор;
|
||||||
|
свойства.имя = модуль[0];
|
||||||
|
свойства.статус = пу.модули.статус(список.выбор);
|
||||||
|
}
|
||||||
|
список.выбрали.подписатьМного([
|
||||||
|
отобразитьКодВыбранногоМодуля,
|
||||||
|
отобразитьСвойстваВыбранногоМодуля,
|
||||||
|
]);
|
||||||
|
|
||||||
|
function обновитьСтатусМодуля()
|
||||||
|
{
|
||||||
|
var номер = список.выбор;
|
||||||
|
var имя = свойства.имя;
|
||||||
|
var статус = свойства.статус;
|
||||||
|
модули.задатьСтатус(номер, статус);
|
||||||
|
список.обновитьЭлемент(номер, статус, имя);
|
||||||
|
}
|
||||||
|
свойства.изменилиСтатус.подписать(обновитьСтатусМодуля);
|
||||||
|
|
||||||
|
function обновитьИмяМодуля()
|
||||||
|
{
|
||||||
|
var номер = список.выбор;
|
||||||
|
var имя = свойства.имя;
|
||||||
|
var статус = свойства.статус;
|
||||||
|
модули.задатьИмя(номер, имя);
|
||||||
|
список.обновитьЭлемент(номер, статус, имя);
|
||||||
|
}
|
||||||
|
свойства.изменилиИмя.подписать(обновитьИмяМодуля);
|
||||||
|
|
||||||
|
function обновитьНомерМодуля()
|
||||||
|
{
|
||||||
|
var старый = список.выбор;
|
||||||
|
var новый = свойства.номер;
|
||||||
|
if (старый == новый)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (новый > муром.модули.length - 1)
|
||||||
|
{
|
||||||
|
новый = муром.модули.length - 1;
|
||||||
|
}
|
||||||
|
модули.задатьНомер(старый, новый);
|
||||||
|
список.задатьСписок(пу.списокМодулей());
|
||||||
|
список.выбрать(новый);
|
||||||
|
}
|
||||||
|
свойства.изменилиНомер.подписать(обновитьНомерМодуля);
|
||||||
|
|
||||||
|
function добавитьМодуль()
|
||||||
|
{
|
||||||
|
var число = Math.floor(Math.random() * Math.floor(1000));
|
||||||
|
var имя = "новый-" + число;
|
||||||
|
var код = `console.log("НАДО Добавить код в модуль '` + имя + `'");`;
|
||||||
|
var модуль = [имя, муром.btoa(код)];
|
||||||
|
муром.модули.push(модуль);
|
||||||
|
var модули = пу.списокМодулей();
|
||||||
|
список.задатьСписок(модули);
|
||||||
|
список.выбрать(модули.length - 1);
|
||||||
|
}
|
||||||
|
пу.добавить.подписать(добавитьМодуль);
|
||||||
|
|
||||||
|
function удалитьМодуль()
|
||||||
|
{
|
||||||
|
var номер = список.выбор;
|
||||||
|
|
||||||
|
var статус = пу.модули.статус(номер);
|
||||||
|
if (статус)
|
||||||
|
{
|
||||||
|
alert("ОШИБКА Удалить можно лишь неисполняемый модуль");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Удалить выбранный модуль.
|
||||||
|
муром.модули.splice(номер, 1);
|
||||||
|
--номер;
|
||||||
|
if (номер < 0)
|
||||||
|
{
|
||||||
|
номер = 0;
|
||||||
|
}
|
||||||
|
var модули = пу.списокМодулей();
|
||||||
|
список.задатьСписок(модули);
|
||||||
|
список.выбрать(номер);
|
||||||
|
}
|
||||||
|
свойства.удалить.подписать(удалитьМодуль);
|
||||||
|
|
||||||
|
function сохранитьВыбранныйМодуль()
|
||||||
|
{
|
||||||
|
var модуль = муром.модули[список.выбор];
|
||||||
|
var код = муром.редактор.session.getValue();
|
||||||
|
модуль[1] = муром.btoa(код);
|
||||||
|
}
|
||||||
|
function сохранить()
|
||||||
|
{
|
||||||
|
пу.кнопкаСохранить.disabled = true;
|
||||||
|
localforage.setItem("modules", муром.модули, function(ошибка, значение){
|
||||||
|
пу.кнопкаСохранить.disabled = false;
|
||||||
|
if (ошибка)
|
||||||
|
{
|
||||||
|
console.error("Не удалось сохранить модули: '" + ошибка + "'");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
пу.сохранить.подписатьМного([
|
||||||
|
сохранитьВыбранныйМодуль,
|
||||||
|
сохранить,
|
||||||
|
]);
|
||||||
|
|
||||||
|
// How to create a file in memory for user to download, but not through server?
|
||||||
|
// https://stackoverflow.com/a/18197341
|
||||||
|
function скачать()
|
||||||
|
{
|
||||||
|
var содержимое = муром.файл.начало;
|
||||||
|
for (var номер in муром.модули)
|
||||||
|
{
|
||||||
|
var модуль = муром.модули[номер];
|
||||||
|
var имя = модуль[0];
|
||||||
|
var код64 = модуль[1];
|
||||||
|
var свойства = модули.свойства(номер);
|
||||||
|
содержимое +=
|
||||||
|
`
|
||||||
|
|
||||||
|
[
|
||||||
|
"` + имя + `",
|
||||||
|
"` + код64 + `",
|
||||||
|
`
|
||||||
|
+
|
||||||
|
JSON.stringify(свойства)
|
||||||
|
+
|
||||||
|
`
|
||||||
|
],
|
||||||
|
`
|
||||||
|
;
|
||||||
|
}
|
||||||
|
содержимое += муром.файл.конец;
|
||||||
|
содержимое = муром.btoa(содержимое);
|
||||||
|
|
||||||
|
var ссыль = document.createElement("a");
|
||||||
|
ссыль.setAttribute("href", "data:text/html;charset=utf-8;base64," + содержимое);
|
||||||
|
var имя = пу.имяФайла();
|
||||||
|
ссыль.setAttribute("download", имя);
|
||||||
|
ссыль.style.display = "none";
|
||||||
|
document.body.appendChild(ссыль);
|
||||||
|
ссыль.click();
|
||||||
|
document.body.removeChild(ссыль);
|
||||||
|
}
|
||||||
|
пу.скачать.подписать(скачать);
|
||||||
|
|
||||||
|
// При запуске.
|
||||||
|
список.выбрать(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Пуск
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (window.location.search == "?0")
|
||||||
|
{
|
||||||
|
console.debug("Запуск панели управления");
|
||||||
|
задатьВнешнийВид();
|
||||||
|
запуститьПУ();
|
||||||
|
console.debug("Панель управления запущена")
|
||||||
|
}
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
муром.пуск = new Уведомитель();
|
|
||||||
муром.старт = муром.пуск;
|
|
||||||
murom.start = function()
|
|
||||||
{
|
|
||||||
муром.пуск.уведомить();
|
|
||||||
};
|
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
муром.загрузитьACE = function()
|
||||||
|
{
|
||||||
|
// Редактор кода ACE.
|
||||||
|
// https://github.com/ajaxorg/ace-builds/blob/master/src-min-noconflict/ace.js
|
||||||
|
(function(){function o(n){var i=e;n&&(e[n]||(e[n]={}),i=e[n]);if(!i.define||!i.define.packaged)t.original=i.define,i.define=t,i.define.packaged=!0;if(!i.require||!i.require.packaged)r.original=i.require,i.require=r,i.require.packaged=!0}var ACE_NAMESPACE = "ace",e=function(){return this}();!e&&typeof window!="undefined"&&(e=window);if(!ACE_NAMESPACE&&typeof requirejs!="undefined")return;var t=function(e,n,r){if(typeof e!="string"){t.original?t.original.apply(this,arguments):(console.error("dropping module because define wasn't a string."),console.trace());return}arguments.length==2&&(r=n),t.modules[e]||(t.payloads[e]=r,t.modules[e]=null)};t.modules={},t.payloads={};var n=function(e,t,n){if(typeof t=="string"){var i=s(e,t);if(i!=undefined)return n&&n(),i}else if(Object.prototype.toString.call(t)==="[object Array]"){var o=[];for(var u=0,a=t.length;u<a;++u){var f=s(e,t[u]);if(f==undefined&&r.original)return;o.push(f)}return n&&n.apply(null,o)||!0}},r=function(e,t){var i=n("",e,t);return i==undefined&&r.original?r.original.apply(this,arguments):i},i=function(e,t){if(t.indexOf("!")!==-1){var n=t.split("!");return i(e,n[0])+"!"+i(e,n[1])}if(t.charAt(0)=="."){var r=e.split("/").slice(0,-1).join("/");t=r+"/"+t;while(t.indexOf(".")!==-1&&s!=t){var s=t;t=t.replace(/\/\.\//,"/").replace(/[^\/]+\/\.\.\//,"")}}return t},s=function(e,r){r=i(e,r);var s=t.modules[r];if(!s){s=t.payloads[r];if(typeof s=="function"){var o={},u={id:r,uri:"",exports:o,packaged:!0},a=function(e,t){return n(r,e,t)},f=s(a,o,u);o=f||u.exports,t.modules[r]=o,delete t.payloads[r]}s=t.modules[r]=o||s}return s};o(ACE_NAMESPACE)})(),ace.define("ace/lib/regexp",["require","exports","module"],function(e,t,n){"use strict";function o(e){return(e.global?"g":"")+(e.ignoreCase?"i":"")+(e.multiline?"m":"")+(e.extended?"x":"")+(e.sticky?"y":"")}function u(e,t,n){if(Array.prototype.indexOf)return e.indexOf(t,n);for(var r=n||0;r<e.length;r++)if(e[r]===t)return r;return-1}var r={exec:RegExp.prototype.exec,test:RegExp.prototype.test,match:String.prototype.match,replace:String.prototype.replace,split:String.prototype.split},i=r.exec.call(/()??/,"")[1]===undefined,s=function(){var e=/^/g;return r.test.call(e,""),!e.lastIndex}();if(s&&i)return;RegExp.prototype.exec=function(e){var t=r.exec.apply(this,arguments),n,a;if(typeof e=="string"&&t){!i&&t.length>1&&u(t,"")>-1&&(a=RegExp(this.source,r.replace.call(o(this),"g","")),r.replace.call(e.slice(t.index),a,function(){for(var e=1;e<arguments.length-2;e++)arguments[e]===undefined&&(t[e]=undefined)}));if(this._xregexp&&this._xregexp.captureNames)for(var f=1;f<t.length;f++)n=this._xregexp.captureNames[f-1],n&&(t[n]=t[f]);!s&&this.global&&!t[0].length&&this.lastIndex>t.index&&this.lastIndex--}return t},s||(RegExp.prototype.test=function(e){var t=r.exec.call(this,e);return t&&this.global&&!t[0].length&&this.lastIndex>t.index&&this.lastIndex--,!!t})}),ace.define("ace/lib/es5-shim",["require","exports","module"],function(e,t,n){function r(){}function w(e){try{return Object.defineProperty(e,"sentinel",{}),"sentinel"in e}catch(t){}}function H(e){return e=+e,e!==e?e=0:e!==0&&e!==1/0&&e!==-1/0&&(e=(e>0||-1)*Math.floor(Math.abs(e))),e}function B(e){var t=typeof e;return e===null||t==="undefined"||t==="boolean"||t==="number"||t==="string"}function j(e){var t,n,r;if(B(e))return e;n=e.valueOf;if(typeof n=="function"){t=n.call(e);if(B(t))return t}r=e.toString;if(typeof r=="function"){t=r.call(e);if(B(t))return t}throw new TypeError}Function.prototype.bind||(Function.prototype.bind=function(t){var n=this;if(typeof n!="function")throw new TypeError("Function.prototype.bind called on incompatible "+n);var i=u.call(arguments,1),s=function(){if(this instanceof s){var e=n.apply(this,i.concat(u.call(arguments)));return Object(e)===e?e:this}return n.apply(t,i.concat(u.call(arguments)))};return n.prototype&&(r.prototype=n.prototype,s.prototype=new r,r.prototype=null),s});var i=Function.prototype.call,s=Array.prototype,o=Object.prototype,u=s.slice,a=i.bind(o.toString),f=i.bind(o.hasOwnProperty),l,c,h,p,d;if(d=f(o,"__defineGetter__"))l=i.bind(o.__defineGetter__),c=i.bind(o.__defineSetter__),h=i.bind(o.__lookupGetter__),p=i.bind(o.__lookupSetter__);if([1,2].splice(0).length!=2)if(!function(){function e(e){var t=new Array(e+2);return t[0]=t[1]=0,t}var t=[],n;t.splice.apply(t,e(20)),t.splice.apply(t,e(26)),n=t.length,t.splice(5,0,"XXX"),n+1==t.length;if(n+1==t.length)return!0}())Array.prototype.splice=function(e,t){var n=this.length;e>0?e>n&&(e=n):e==void 0?e=0:e<0&&(e=Math.max(n+e,0)),e+t<n||(t=n-e);var r=this.slice(e,e+t),i=u.call(arguments,2),s=i.length;if(e===n)s&&this.push.apply(this,i);else{var o=Math.min(t,n-e),a=e+o,f=a+s-o,l=n-a,c=n-o;if(f<a)for(var h=0;h<l;++h)this[f+h]=this[a+h];else if(f>a)for(h=l;h--;)this[f+h]=this[a+h];if(s&&e===c)this.length=c,this.push.apply(this,i);else{this.length=c+s;for(h=0;h<s;++h)this[e+h]=i[h]}}return r};else{var v=Array.prototype.splice;Array.prototype.splice=function(e,t){return arguments.length?v.apply(thisLine truncated
|
||||||
|
ace.require(["ace/ace"], function(a) {
|
||||||
|
if (a) {
|
||||||
|
a.config.init(true);
|
||||||
|
a.define = ace.define;
|
||||||
|
}
|
||||||
|
if (!window.ace)
|
||||||
|
window.ace = a;
|
||||||
|
for (var key in a) if (a.hasOwnProperty(key))
|
||||||
|
window.ace[key] = a[key];
|
||||||
|
window.ace["default"] = window.ace;
|
||||||
|
if (typeof module == "object" && typeof exports == "object" && module) {
|
||||||
|
module.exports = window.ace;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
};
|
||||||
|
|
||||||
|
муром.загрузитьРежимACEJS = function()
|
||||||
|
{
|
||||||
|
// Режим JavaScript для ACE.
|
||||||
|
// https://github.com/ajaxorg/ace-builds/blob/master/src-min-noconflict/mode-javascript.js
|
||||||
|
ace.define("ace/mode/doc_comment_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"],function(e,t,n){"use strict";var r=e("../lib/oop"),i=e("./text_highlight_rules").TextHighlightRules,s=function(){this.$rules={start:[{token:"comment.doc.tag",regex:"@[\\w\\d_]+"},s.getTagRule(),{defaultToken:"comment.doc",caseInsensitive:!0}]}};r.inherits(s,i),s.getTagRule=function(e){return{token:"comment.doc.tag.storage.type",regex:"\\b(?:TODO|FIXME|XXX|HACK)\\b"}},s.getStartRule=function(e){return{token:"comment.doc",regex:"\\/\\*(?=\\*)",next:e}},s.getEndRule=function(e){return{token:"comment.doc",regex:"\\*\\/",next:e}},t.DocCommentHighlightRules=s}),ace.define("ace/mode/javascript_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/doc_comment_highlight_rules","ace/mode/text_highlight_rules"],function(e,t,n){"use strict";function a(){var e=o.replace("\\d","\\d\\-"),t={onMatch:function(e,t,n){var r=e.charAt(1)=="/"?2:1;if(r==1)t!=this.nextState?n.unshift(this.next,this.nextState,0):n.unshift(this.next),n[2]++;else if(r==2&&t==this.nextState){n[1]--;if(!n[1]||n[1]<0)n.shift(),n.shift()}return[{type:"meta.tag.punctuation."+(r==1?"":"end-")+"tag-open.xml",value:e.slice(0,r)},{type:"meta.tag.tag-name.xml",value:e.substr(r)}]},regex:"</?"+e+"",next:"jsxAttributes",nextState:"jsx"};this.$rules.start.unshift(t);var n={regex:"{",token:"paren.quasi.start",push:"start"};this.$rules.jsx=[n,t,{include:"reference"},{defaultToken:"string"}],this.$rules.jsxAttributes=[{token:"meta.tag.punctuation.tag-close.xml",regex:"/?>",onMatch:function(e,t,n){return t==n[0]&&n.shift(),e.length==2&&(n[0]==this.nextState&&n[1]--,(!n[1]||n[1]<0)&&n.splice(0,2)),this.next=n[0]||"start",[{type:this.token,value:e}]},nextState:"jsx"},n,f("jsxAttributes"),{token:"entity.other.attribute-name.xml",regex:e},{token:"keyword.operator.attribute-equals.xml",regex:"="},{token:"text.tag-whitespace.xml",regex:"\\s+"},{token:"string.attribute-value.xml",regex:"'",stateName:"jsx_attr_q",push:[{token:"string.attribute-value.xml",regex:"'",next:"pop"},{include:"reference"},{defaultToken:"string.attribute-value.xml"}]},{token:"string.attribute-value.xml",regex:'"',stateName:"jsx_attr_qq",push:[{token:"string.attribute-value.xml",regex:'"',next:"pop"},{include:"reference"},{defaultToken:"string.attribute-value.xml"}]},t],this.$rules.reference=[{token:"constant.language.escape.reference.xml",regex:"(?:&#[0-9]+;)|(?:&#x[0-9a-fA-F]+;)|(?:&[a-zA-Z0-9_:\\.-]+;)"}]}function f(e){return[{token:"comment",regex:/\/\*/,next:[i.getTagRule(),{token:"comment",regex:"\\*\\/",next:e||"pop"},{defaultToken:"comment",caseInsensitive:!0}]},{token:"comment",regex:"\\/\\/",next:[i.getTagRule(),{token:"comment",regex:"$|^",next:e||"pop"},{defaultToken:"comment",caseInsensitive:!0}]}]}var r=e("../lib/oop"),i=e("./doc_comment_highlight_rules").DocCommentHighlightRules,s=e("./text_highlight_rules").TextHighlightRules,o="[a-zA-Z\\$_\u00a1-\uffff][a-zA-Z\\d\\$_\u00a1-\uffff]*",u=function(e){var t=this.createKeywordMapper({"variable.language":"Array|Boolean|Date|Function|Iterator|Number|Object|RegExp|String|Proxy|Namespace|QName|XML|XMLList|ArrayBuffer|Float32Array|Float64Array|Int16Array|Int32Array|Int8Array|Uint16Array|Uint32Array|Uint8Array|Uint8ClampedArray|Error|EvalError|InternalError|RangeError|ReferenceError|StopIteration|SyntaxError|TypeError|URIError|decodeURI|decodeURIComponent|encodeURI|encodeURIComponent|eval|isFinite|isNaN|parseFloat|parseInt|JSON|Math|this|arguments|prototype|window|document",keyword:"const|yield|import|get|set|async|await|break|case|catch|continue|default|delete|do|else|finally|for|function|if|in|of|instanceof|new|return|switch|throw|try|typeof|let|var|while|with|debugger|__parent__|__count__|escape|unescape|with|__proto__|class|enum|extends|super|export|implements|private|public|interface|package|protected|static","storage.type":"const|let|var|function","constant.language":"null|Infinity|NaN|undefined","support.function":"alert","constant.language.boolean":"true|false"},"identifier"),n="case|do|else|finally|in|instanceof|return|throw|try|typeof|yield|void",r="\\\\(?:x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|u{[0-9a-fA-F]{1,6}}|[0-2][0-7]{0,2}|3[0-7][0-7]?|[4-7][0-7]?|.)";this.$rules={no_regex:[i.getStartRule("doc-start"),f("no_regex"),{token:"string",regex:"'(?=.)",next:"qstring"},{token:"string",regex:'"(?=.)',next:"qqstring"},{token:"constant.numeric",regex:/0(?:[xX][0-9a-fA-F]+|[oO][0-7]+|[bB][01]+)\b/},{token:"constant.numeric",regex:/(?:\d\d*(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+\b)?/},{token:["storage.type","punctuation.operator","support.function","punctuation.operator","entity.name.function","text","keyword.operator"],regex:"("+o+")(\\.)(prototype)(\\.)("+o+")(\\s*)(=)",next:"function_arguments"},{token:["storage.type","punctuation.operator","entity.name.function","text","keyword.operator","text","storage.type","text","paren.lparen"],regex:"("+o+")(\\.)("+o+")(\\s*)(=)(\\s*)(function)(\\s*)(\\()",next:"functionLine truncated
|
||||||
|
ace.require(["ace/mode/javascript"], function(m) {
|
||||||
|
if (typeof module == "object" && typeof exports == "object" && module) {
|
||||||
|
module.exports = m;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
};
|
||||||
|
|
||||||
|
муром.создатьРедакторВЛевойОбласти = function()
|
||||||
|
{
|
||||||
|
муром.загрузитьACE();
|
||||||
|
муром.загрузитьРежимACEJS();
|
||||||
|
|
||||||
|
var редактор = document.createElement("div");
|
||||||
|
редактор.id = "редактор";
|
||||||
|
редактор.style.cssText = "height: 100%;";
|
||||||
|
var область = document.getElementById("левая-область");
|
||||||
|
область.appendChild(редактор);
|
||||||
|
муром.редактор = window.ace.edit("редактор");
|
||||||
|
муром.редактор.session.setMode("ace/mode/javascript");
|
||||||
|
};
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
муром.модулевед.сохранить = new Уведомитель();
|
|
||||||
муром.модулевед.сохранили = new Уведомитель();
|
|
||||||
|
|
||||||
муром.модулевед.создатьИнтерфейсСохранения = function()
|
|
||||||
{
|
|
||||||
сохранение = document.createElement("button");
|
|
||||||
муром.модулевед.htmlМодули.appendChild(сохранение);
|
|
||||||
сохранение.innerHTML = "Сохранить всё";
|
|
||||||
сохранение.onclick = function()
|
|
||||||
{
|
|
||||||
муром.модулевед.сохранить.уведомить();
|
|
||||||
};
|
|
||||||
муром.модулевед.htmlСохранение = сохранение;
|
|
||||||
};
|
|
||||||
|
|
||||||
муром.модулевед.сохранитьВыбранныйМодуль = function()
|
|
||||||
{
|
|
||||||
var номер = муром.модулевед.номерМодуля(муром.модулевед.выбранныйМодуль);
|
|
||||||
if (!номер)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var модуль = муром.модули[номер];
|
|
||||||
var код = муром.редактор.session.getValue();
|
|
||||||
модуль[1] = base64Encode(код);
|
|
||||||
};
|
|
||||||
|
|
||||||
муром.модулевед.сохранитьВБазе = function(отклик)
|
|
||||||
{
|
|
||||||
муром.модулевед.htmlСохранение.disabled = true;
|
|
||||||
localforage.setItem("modules", муром.модули, function(ошибка, значение){
|
|
||||||
муром.модулевед.htmlСохранение.disabled = false;
|
|
||||||
if (ошибка)
|
|
||||||
{
|
|
||||||
console.log("ОШИБКА Не удалось сохранить модули: '" + ошибка + "'");
|
|
||||||
}
|
|
||||||
else if (отклик)
|
|
||||||
{
|
|
||||||
отклик();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
муром.модулевед.сохранитьВсё = function()
|
|
||||||
{
|
|
||||||
муром.модулевед.сохранитьВыбранныйМодуль();
|
|
||||||
муром.модулевед.сохранитьВБазе(function(){
|
|
||||||
муром.модулевед.сохранили.уведомить();
|
|
||||||
});
|
|
||||||
};
|
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<body>
|
<body>
|
||||||
<script>
|
<script>
|
||||||
var муром = {};
|
var муром = {};
|
||||||
@@ -32,3 +33,4 @@ eval(код);
|
|||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
Reference in new issue
Block a user