|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- /*
- *
- * Скачиваемый файл / Downloaded file
- *
- */
-
- муром.файл = {};
- муром.файл.начало =
- `
- <!DOCTYPE html>
- <html>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <body>
- <script>
- var муром = {};
- var murom = муром;
- муром.модули = [
- `;
- муром.файл.конец =
- `
- ];
-
- Object.defineProperty(murom, "modules", {
- get: function()
- {
- return муром.модули;
- },
- set: function(значения)
- {
- муром.модули = значения;
- }
- });
-
- var загрузочныйМодуль = муром.модули[0];
- var код = atob(загрузочныйМодуль[1]);
- eval(код);
- </script>
- </body>
- </html>
- `;
-
- /*
- *
- * 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.
- function ReporterSubscription(id, callback, reporter)
- {
- this.id = id;
- this.callback = callback;
- this.reporter = reporter;
- }
-
- // Reporter class.
- function Reporter(name)
- {
- this.name =
- (typeof name !== "undefined") ?
- name :
- "";
- this.subscriptions = [];
- }
- Reporter.prototype.report = function()
- {
- for (var id in this.subscriptions)
- {
- var subscription = this.subscriptions[id];
- subscription.callback();
- }
- }
- Reporter.prototype.subscribe = function(callback)
- {
- var id = murom.uuid();
- var subscription = new ReporterSubscription(id, callback, this);
- this.subscriptions.push(subscription);
- return subscription;
- }
- Reporter.prototype.subscribeMany = function(funcs)
- {
- for (var i = 0; i < funcs.length; ++i)
- {
- var func = funcs[i];
- this.subscribe(func);
- }
- }
-
- var Уведомитель = Reporter;
- Reporter.prototype.уведомить = function()
- {
- this.report();
- };
- Reporter.prototype.подписать = function(функция)
- {
- this.subscribe(функция);
- };
- Reporter.prototype.подписатьМного = function(funcs)
- {
- this.subscribeMany(funcs);
- };
-
- /*
- *
- * Пуск / Start
- *
- */
-
- муром.пуск = new Уведомитель();
- // Can also be accessed as 'murom.run'.
- Object.defineProperty(murom, "run", {
- get: function()
- {
- return муром.пуск;
- }
- });
- murom.start = function()
- {
- муром.пуск.уведомить();
- };
-
- /*
- *
- * Левая и правая области / Left and right regions
- *
- */
-
- муром.создатьЛевуюПравуюОбласти = 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 [ло, по];
- };
|