app.js 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362
  1. var MATERIAL_CATEGORY;
  2. (function (MATERIAL_CATEGORY) {
  3. MATERIAL_CATEGORY["MATERIAL"] = "\u043C\u0430\u0442\u0435\u0440\u0438\u0430\u043B";
  4. MATERIAL_CATEGORY["NEWS"] = "\u043D\u043E\u0432\u043E\u0441\u0442\u044C";
  5. MATERIAL_CATEGORY["NOTICE"] = "\u043E\u0431\u044A\u044F\u0432\u043B\u0435\u043D\u0438\u0435";
  6. })(MATERIAL_CATEGORY || (MATERIAL_CATEGORY = {}));
  7. var MENU_CATEGORY;
  8. (function (MENU_CATEGORY) {
  9. MENU_CATEGORY["MAIN"] = "__main";
  10. MENU_CATEGORY["TOP"] = "__top";
  11. })(MENU_CATEGORY || (MENU_CATEGORY = {}));
  12. var CLIENT_PLATFORM;
  13. (function (CLIENT_PLATFORM) {
  14. CLIENT_PLATFORM[CLIENT_PLATFORM["DESKTOP"] = 9999] = "DESKTOP";
  15. CLIENT_PLATFORM[CLIENT_PLATFORM["OLD_DESKTOP"] = 1280] = "OLD_DESKTOP";
  16. CLIENT_PLATFORM[CLIENT_PLATFORM["TABLET"] = 1024] = "TABLET";
  17. CLIENT_PLATFORM[CLIENT_PLATFORM["MOBILE"] = 560] = "MOBILE";
  18. })(CLIENT_PLATFORM || (CLIENT_PLATFORM = {}));
  19. var VKKO;
  20. (function (VKKO) {
  21. var Setting;
  22. (function (Setting) {
  23. var __BlockingScrollCount = 0;
  24. Setting.Platform = CLIENT_PLATFORM.DESKTOP;
  25. function BlockScroll() {
  26. document.documentElement.style.marginRight = window.innerWidth - document.documentElement.clientWidth + "px";
  27. document.documentElement.style.overflow = "hidden";
  28. __BlockingScrollCount++;
  29. }
  30. Setting.BlockScroll = BlockScroll;
  31. ;
  32. function UnblockScroll() {
  33. __BlockingScrollCount--;
  34. if (__BlockingScrollCount <= 0) {
  35. document.documentElement.style.overflow = "";
  36. document.documentElement.style.marginRight = null;
  37. __BlockingScrollCount = 0;
  38. }
  39. }
  40. Setting.UnblockScroll = UnblockScroll;
  41. ;
  42. })(Setting = VKKO.Setting || (VKKO.Setting = {}));
  43. })(VKKO || (VKKO = {}));
  44. var VKKO;
  45. (function (VKKO) {
  46. var Utils;
  47. (function (Utils) {
  48. function logError(message) {
  49. console.log("%c ERROR ", "background-color: red; color: white; font-weight: 700;", message);
  50. }
  51. Utils.logError = logError;
  52. function logWarning(message) {
  53. console.log("%c WARNING ", "background-color: orange; color: white; font-weight: 700;", message);
  54. }
  55. Utils.logWarning = logWarning;
  56. function logInfo(message) {
  57. console.log("%c INFO ", "background-color: green; color: white; font-weight: 700;", message);
  58. }
  59. Utils.logInfo = logInfo;
  60. function GenerateHash256(uppercase) {
  61. if (uppercase === void 0) { uppercase = false; }
  62. var randomValue = crypto.getRandomValues(new Uint32Array(4));
  63. var randomHash = "";
  64. for (var i = 0; i < randomValue.length; i++) {
  65. randomHash += randomValue[i].toString(16);
  66. }
  67. if (uppercase === true) {
  68. return randomHash.toUpperCase();
  69. }
  70. return randomHash;
  71. }
  72. Utils.GenerateHash256 = GenerateHash256;
  73. ;
  74. function GenerateHashDashed(group) {
  75. if (group === void 0) { group = 4; }
  76. var randomValue = crypto.getRandomValues(new Uint32Array(group));
  77. var randomHash = "";
  78. for (var i = 0; i < randomValue.length; i++) {
  79. randomHash += randomValue[i].toString(16) + "-";
  80. }
  81. return randomHash.slice(0, randomHash.length - 1).toUpperCase();
  82. }
  83. Utils.GenerateHashDashed = GenerateHashDashed;
  84. ;
  85. })(Utils = VKKO.Utils || (VKKO.Utils = {}));
  86. })(VKKO || (VKKO = {}));
  87. var VKKO;
  88. (function (VKKO) {
  89. var Messenger = (function () {
  90. function Messenger() {
  91. this.HARDREMOVE_TIME = 100;
  92. this.AUTOREMOVE_TIME = 2000;
  93. this.REMOVING_SHORT = "short";
  94. this.REMOVING_LONG = "long";
  95. this.MESSAGE_COUNTER = -1;
  96. this.__MessageContainer = document.querySelector("#MessengerBox");
  97. if (!this.__MessageContainer) {
  98. this.__MessageContainer = document.createElement("div");
  99. this.__MessageContainer.classList.add("messenger");
  100. this.__MessageContainer.id = "MessengerBox";
  101. document.body.append(this.__MessageContainer);
  102. }
  103. }
  104. Messenger.prototype.removeMessage = function (time, transition) {
  105. if (time === void 0) { time = this.HARDREMOVE_TIME; }
  106. if (transition === void 0) { transition = this.REMOVING_SHORT; }
  107. if (this instanceof HTMLElement) {
  108. this.classList.add("removing", transition);
  109. setTimeout(function (element) {
  110. element.remove();
  111. }, time, this);
  112. }
  113. else {
  114. VKKO.Utils.logError("\u041D\u0435\u0432\u043E\u0437\u043C\u043E\u0436\u043D\u043E \u0443\u0434\u0430\u043B\u0438\u0442\u044C \u0441\u043E\u043E\u0431\u0449\u0435\u043D\u0438\u0435, \u0442.\u043A. \u0435\u0433\u043E \u0442\u0438\u043F \u043D\u0435 HTMLElement");
  115. }
  116. };
  117. Messenger.prototype.autoRemoveMessage = function (element) {
  118. this.removeMessage.call(element, this.AUTOREMOVE_TIME, this.REMOVING_SHORT);
  119. };
  120. Messenger.prototype.Show = function (msg, time) {
  121. if (time === void 0) { time = 10000; }
  122. var message = document.createElement("div");
  123. message.id = "MessageTick" + ++this.MESSAGE_COUNTER;
  124. message.classList.add("in");
  125. var content = document.createElement("div");
  126. content.textContent = msg;
  127. var close = document.createElement("span");
  128. close.classList.add("close");
  129. close.onclick = this.removeMessage.bind(message);
  130. message.append(close, content);
  131. this.__MessageContainer.append(message);
  132. setTimeout(function () {
  133. message.classList.remove("in");
  134. }, 100);
  135. setTimeout(this.autoRemoveMessage.bind(this, message), time);
  136. };
  137. return Messenger;
  138. }());
  139. VKKO.Messenger = Messenger;
  140. })(VKKO || (VKKO = {}));
  141. var VKKOWork;
  142. (function (VKKOWork) {
  143. VKKOWork.Messenger = new VKKO.Messenger();
  144. })(VKKOWork || (VKKOWork = {}));
  145. var VKKO;
  146. (function (VKKO) {
  147. var XHR = (function () {
  148. function XHR() {
  149. this.__QueryCounter = 0;
  150. this.__LoadAnimationElement = document.querySelector("#LoadingAnimation");
  151. if (!this.__LoadAnimationElement) {
  152. this.__LoadAnimationElement = document.createElement("div");
  153. this.__LoadAnimationElement.id = "LoadingAnimation";
  154. this.__LoadAnimationElement.className = "loading hidden";
  155. for (var i = 0; i < 7; i++) {
  156. var element = document.createElement("div");
  157. element.className = "glob";
  158. element.setAttribute("style", "--i:" + (i + 1));
  159. this.__LoadAnimationElement.append(element);
  160. }
  161. document.body.append(this.__LoadAnimationElement);
  162. }
  163. }
  164. XHR.prototype.onStartRequest = function (event) {
  165. if (this.__QueryCounter === 0) {
  166. this.__LoadAnimationElement.classList.remove("hidden");
  167. }
  168. this.__QueryCounter++;
  169. };
  170. XHR.prototype.onStopRequest = function (event) {
  171. this.__QueryCounter--;
  172. if (this.__QueryCounter <= 0) {
  173. this.__LoadAnimationElement.classList.add("hidden");
  174. this.__QueryCounter = 0;
  175. }
  176. };
  177. XHR.prototype.POST = function (callback, uri, params, callbackParams, isAsinc, multipart) {
  178. if (isAsinc === void 0) { isAsinc = true; }
  179. if (multipart === void 0) { multipart = false; }
  180. if (!uri) {
  181. VKKO.Utils.logError("URI не был передан");
  182. return;
  183. }
  184. if (!params) {
  185. params = {};
  186. }
  187. var xhr = new XMLHttpRequest();
  188. xhr.onloadstart = this.onStartRequest;
  189. xhr.onloadend = this.onStopRequest;
  190. xhr.onabort = function (event) {
  191. VKKO.Utils.logWarning(uri + " => Выполнение запроса было прервано...");
  192. VKKOWork.Messenger.Show("Выполнение запроса было прервано...");
  193. };
  194. xhr.onerror = function (event) {
  195. VKKO.Utils.logError(uri + " => " + this.statusText + " " + this.status);
  196. VKKOWork.Messenger.Show("Выполнение запроса завершилось неудачей. Перезагрузите страницу и повторите попытку. Если проблема сохраняется, пожалуйста, сообщите об этом администратору admin@ktk-45.ru");
  197. };
  198. xhr.ontimeout = function (event) {
  199. VKKO.Utils.logError(uri + " => Время ожидания запроса истекло... Проверьте соединение с интернетом");
  200. VKKOWork.Messenger.Show("Время ожидания запроса истекло... Проверьте соединение с интернетом");
  201. };
  202. xhr.onload = function (event) {
  203. VKKO.Utils.logInfo(uri + " => " + this.statusText + " " + this.status.toString());
  204. var data;
  205. try {
  206. data = JSON.parse(this.response);
  207. }
  208. catch (error) {
  209. VKKO.Utils.logError(error);
  210. data = null;
  211. }
  212. if (data === null) {
  213. return;
  214. }
  215. if ("Error" in data) {
  216. if (typeof data.Error === "boolean") {
  217. VKKOWork.Messenger.Show(data.Error);
  218. return;
  219. }
  220. }
  221. callback(data, callbackParams);
  222. };
  223. xhr.open("POST", uri, isAsinc);
  224. if (!multipart) {
  225. xhr.setRequestHeader("Content-Type", "application/json; charset=utf-8");
  226. xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
  227. xhr.send(JSON.stringify(params));
  228. }
  229. else {
  230. xhr.send(params);
  231. }
  232. };
  233. return XHR;
  234. }());
  235. VKKO.XHR = XHR;
  236. })(VKKO || (VKKO = {}));
  237. var VKKOWork;
  238. (function (VKKOWork) {
  239. VKKOWork.XHR = new VKKO.XHR();
  240. })(VKKOWork || (VKKOWork = {}));
  241. var VKKO;
  242. (function (VKKO) {
  243. var Control;
  244. (function (Control) {
  245. function CreateCheckbox(text, id, dataset, onchange) {
  246. if (dataset === void 0) { dataset = null; }
  247. if (onchange === void 0) { onchange = null; }
  248. var label = document.createElement("label"), input = document.createElement("input"), spanCheck = document.createElement("span"), spanText = document.createElement("span");
  249. label.className = "checkbox";
  250. label.append(input, spanCheck, spanText);
  251. spanText.className = "text";
  252. spanText.textContent = text;
  253. spanCheck.className = "checked";
  254. input.type = "checkbox";
  255. if (id) {
  256. var ifExists = document.querySelector("#" + id);
  257. if (ifExists) {
  258. VKKOWork.Messenger.Show("Нельзя создать элемент с повторяющимся идентификатором");
  259. return;
  260. }
  261. input.id = id;
  262. }
  263. if (dataset) {
  264. for (var key in dataset) {
  265. if (dataset.hasOwnProperty(key)) {
  266. input.dataset[key] = dataset[key];
  267. }
  268. }
  269. }
  270. if (onchange) {
  271. input.onchange = onchange;
  272. }
  273. return label;
  274. }
  275. Control.CreateCheckbox = CreateCheckbox;
  276. })(Control = VKKO.Control || (VKKO.Control = {}));
  277. })(VKKO || (VKKO = {}));
  278. var VKKO;
  279. (function (VKKO) {
  280. var Modal;
  281. (function (Modal) {
  282. var __ModalCounter = 0;
  283. function Create(head, body, callback) {
  284. var backdropContainer;
  285. if (__ModalCounter === 0) {
  286. backdropContainer = document.createElement("div");
  287. backdropContainer.className = "backdrop-container";
  288. document.body.append(backdropContainer);
  289. VKKO.Setting.BlockScroll();
  290. }
  291. else {
  292. backdropContainer = document.querySelector(".backdrop-container");
  293. }
  294. if (backdropContainer == undefined) {
  295. VKKOWork.Messenger.Show("Ой, что-то пошло не так...");
  296. return;
  297. }
  298. var emodal = document.createElement("div"), ehead = document.createElement("div"), ebody = document.createElement("div"), eclose = document.createElement("div"), backdrop = document.createElement("div");
  299. backdrop.className = "backdrop";
  300. emodal.className = "modal";
  301. ehead.className = "head";
  302. ebody.className = "body";
  303. eclose.className = "close fas fa-times";
  304. eclose.onclick = destroy.bind(eclose, callback);
  305. emodal.append(eclose, ehead, ebody);
  306. backdrop.append(emodal);
  307. backdropContainer.append(backdrop);
  308. backdrop.style.zIndex = (__ModalCounter++).toString();
  309. if (typeof head === "string" || head instanceof HTMLElement) {
  310. ehead.append(head);
  311. }
  312. if (body instanceof HTMLElement) {
  313. while (body.children.length > 0) {
  314. ebody.append(body.children[0]);
  315. }
  316. }
  317. }
  318. Modal.Create = Create;
  319. function destroy(callback, event) {
  320. var backdrop = this.closest(".backdrop");
  321. if (backdrop) {
  322. backdrop.remove();
  323. __ModalCounter--;
  324. }
  325. if (__ModalCounter < 1) {
  326. var backdropContainer = document.querySelector(".backdrop-container");
  327. if (backdropContainer) {
  328. backdropContainer.remove();
  329. __ModalCounter = 0;
  330. VKKO.Setting.UnblockScroll();
  331. }
  332. }
  333. if (callback) {
  334. callback();
  335. }
  336. }
  337. })(Modal = VKKO.Modal || (VKKO.Modal = {}));
  338. })(VKKO || (VKKO = {}));
  339. var VKKO;
  340. (function (VKKO) {
  341. var Slider = (function () {
  342. function Slider(containerSelector, swipeSpeed, swipeInterval) {
  343. if (swipeSpeed === void 0) { swipeSpeed = 250; }
  344. if (swipeInterval === void 0) { swipeInterval = 5000; }
  345. this.__SlideCount = 0;
  346. this.__WidthOneSlide = 0;
  347. this.__CarouselRoot = document.querySelector(containerSelector);
  348. if (!this.__CarouselRoot) {
  349. VKKO.Utils.logWarning("Отмена создания слайдера. Нет корневого контейнера.");
  350. return;
  351. }
  352. this.__Carousel = this.__CarouselRoot.querySelector(".carousel");
  353. if (!this.__Carousel) {
  354. VKKO.Utils.logWarning("Отмена создания слайдера. Отсутствует бокс.");
  355. this.__CarouselRoot.remove();
  356. return;
  357. }
  358. this.__Slider = this.__Carousel.querySelector(".slider");
  359. if (!this.__Slider) {
  360. this.__CarouselRoot.remove();
  361. return;
  362. }
  363. this.__NavigationDots = this.__Carousel.querySelector(".navigation-dots");
  364. this.__SlideCount = this.__Slider.children.length;
  365. if (this.__SlideCount == 0) {
  366. this.__CarouselRoot.remove();
  367. return;
  368. }
  369. switch (VKKO.Setting.Platform) {
  370. case CLIENT_PLATFORM.DESKTOP:
  371. this.__WidthOneSlide = this.__CarouselRoot.getBoundingClientRect().width;
  372. break;
  373. case CLIENT_PLATFORM.TABLET:
  374. break;
  375. case CLIENT_PLATFORM.MOBILE:
  376. this.__WidthOneSlide = document.documentElement.clientWidth;
  377. break;
  378. default:
  379. this.__WidthOneSlide = this.__CarouselRoot.getBoundingClientRect().width;
  380. }
  381. this.buildNavigationDots();
  382. this.buildButtonEvent();
  383. if (this.__SlideCount == 1) {
  384. this.__Slider.style.width = this.__WidthOneSlide + "px";
  385. this.outForeground();
  386. return;
  387. }
  388. if (this.__SlideCount > 1) {
  389. this.__Slider.prepend(this.__Slider.lastElementChild);
  390. }
  391. this.__SwipeInterval = swipeInterval;
  392. this.__SwipeSpeed = swipeSpeed;
  393. this.__Slider.style.width = (this.__SlideCount * this.__WidthOneSlide) + "px";
  394. this.__Slider.style.left = "-" + this.__WidthOneSlide + "px";
  395. this.__Slider.onmouseover = this.stopSlider.bind(this);
  396. this.__Slider.onmouseout = this.startSlider.bind(this);
  397. this.outForeground();
  398. this.startSlider();
  399. }
  400. Slider.prototype.buildNavigationDots = function () {
  401. if (this.__NavigationDots) {
  402. while (this.__NavigationDots.children.length > 0) {
  403. this.__NavigationDots.children[0].remove();
  404. }
  405. for (var i = 0; i < this.__SlideCount; i++) {
  406. var element = document.createElement("div");
  407. element.dataset.slide = i.toString();
  408. element.onclick = this.goToSlide.bind(this, element);
  409. this.__NavigationDots.append(element);
  410. }
  411. if (this.__NavigationDots.children.length > 0) {
  412. this.__NavigationDots.children[0].classList.add("active");
  413. }
  414. }
  415. };
  416. Slider.prototype.buildButtonEvent = function () {
  417. for (var i = 0; i < this.__Slider.children.length; i++) {
  418. var button = this.__Slider.children[i].querySelector(".gradient-button");
  419. if (button) {
  420. button.onclick = this.toggleSlide.bind(this, button);
  421. }
  422. }
  423. };
  424. Slider.prototype.outForeground = function () {
  425. this.__Carousel.classList.add("out");
  426. this.__Carousel.ontransitionend = function (event) {
  427. event.target.classList.remove("hide", "out");
  428. };
  429. };
  430. Slider.prototype.goToSlide = function (element) {
  431. this.stopSlider();
  432. this.__Slider.style.transition = "left " + this.__SwipeSpeed + "ms cubic-bezier(.18,.89,.32,1.28)";
  433. var currentSlide = this.__Slider.children[1];
  434. var currentSlideID = currentSlide.dataset.slide;
  435. var toSlideID = element.dataset.slide;
  436. while (toSlideID != currentSlideID) {
  437. this.__Slider.append(this.__Slider.firstElementChild);
  438. currentSlide = this.__Slider.children[1];
  439. currentSlideID = currentSlide.dataset.slide;
  440. }
  441. this.__Slider.style.left = "-" + this.__WidthOneSlide * 2 + "px";
  442. this.__Slider.ontransitionend = this.nextEndAlt.bind(this);
  443. this.switchNavigationDot();
  444. };
  445. Slider.prototype.switchNavigationDot = function () {
  446. var currentSlide = this.__Slider.children[1];
  447. var slide = Number(currentSlide.dataset.slide);
  448. var activeDots = this.__NavigationDots.querySelectorAll(".active");
  449. activeDots.forEach(function (element) {
  450. element.classList.remove("active");
  451. });
  452. this.__NavigationDots.children[slide].classList.add("active");
  453. };
  454. Slider.prototype.stopSlider = function () {
  455. clearInterval(this.__SwipeIntervalHandle);
  456. this.__SwipeIntervalHandle = undefined;
  457. this.__Slider.ontransitionend = undefined;
  458. };
  459. Slider.prototype.startSlider = function () {
  460. if (this.__SwipeIntervalHandle) {
  461. clearInterval(this.__SwipeIntervalHandle);
  462. }
  463. this.__SwipeIntervalHandle = setInterval(this.nextSlide.bind(this), this.__SwipeInterval);
  464. this.__Slider.ontransitionend = this.nextEnd.bind(this);
  465. };
  466. Slider.prototype.nextSlide = function () {
  467. this.__Slider.style.transition = "left " + this.__SwipeSpeed + "ms cubic-bezier(.6,-0.28,.74,.05)";
  468. this.__Slider.style.left = "-" + this.__WidthOneSlide * 2 + "px";
  469. };
  470. Slider.prototype.nextEnd = function () {
  471. this.__Slider.style.transition = null;
  472. this.__Slider.append(this.__Slider.firstElementChild);
  473. this.__Slider.style.left = "-" + this.__WidthOneSlide + "px";
  474. this.switchNavigationDot();
  475. };
  476. Slider.prototype.nextEndAlt = function () {
  477. this.__Slider.style.transition = null;
  478. this.__Slider.style.left = "-" + this.__WidthOneSlide + "px";
  479. this.startSlider();
  480. };
  481. Slider.prototype.toggleSlide = function (element) {
  482. if (element) {
  483. var slide = element.closest(".slide");
  484. if (slide) {
  485. if (slide.classList.contains("expand")) {
  486. slide.classList.remove("expand");
  487. element.textContent = "Развернуть";
  488. this.__NavigationDots.style.display = null;
  489. VKKO.Setting.UnblockScroll();
  490. }
  491. else {
  492. slide.classList.add("expand");
  493. element.textContent = "Свернуть";
  494. this.__NavigationDots.style.display = "none";
  495. VKKO.Setting.BlockScroll();
  496. }
  497. }
  498. }
  499. };
  500. Slider.prototype.Rebuild = function () {
  501. switch (VKKO.Setting.Platform) {
  502. case CLIENT_PLATFORM.DESKTOP:
  503. this.__WidthOneSlide = this.__CarouselRoot.getBoundingClientRect().width;
  504. break;
  505. case CLIENT_PLATFORM.TABLET:
  506. break;
  507. case CLIENT_PLATFORM.MOBILE:
  508. this.__WidthOneSlide = document.documentElement.clientWidth;
  509. break;
  510. default:
  511. this.__WidthOneSlide = this.__CarouselRoot.getBoundingClientRect().width;
  512. }
  513. this.__Slider.style.width = (this.__SlideCount * this.__WidthOneSlide) + "px";
  514. this.__Slider.style.left = "-" + this.__WidthOneSlide + "px";
  515. };
  516. return Slider;
  517. }());
  518. VKKO.Slider = Slider;
  519. })(VKKO || (VKKO = {}));
  520. var VKKOWork;
  521. (function (VKKOWork) {
  522. VKKOWork.NoticeSlider = null;
  523. })(VKKOWork || (VKKOWork = {}));
  524. var VKKO;
  525. (function (VKKO) {
  526. var Search;
  527. (function (Search) {
  528. function search() {
  529. }
  530. function Init(selector) {
  531. if (selector != null) {
  532. var inputSearch = document.querySelector(selector);
  533. if (inputSearch) {
  534. if (inputSearch.parentElement.nextElementSibling && inputSearch.parentElement.nextElementSibling.classList.contains("search-list")) {
  535. }
  536. inputSearch.oninput = search;
  537. }
  538. }
  539. }
  540. Search.Init = Init;
  541. })(Search = VKKO.Search || (VKKO.Search = {}));
  542. })(VKKO || (VKKO = {}));
  543. var VKKO;
  544. (function (VKKO) {
  545. var Main;
  546. (function (Main) {
  547. var __RootMenuItemOpen = false;
  548. function switchMenu(event) {
  549. if (this.classList.contains("open")) {
  550. this.classList.remove("open");
  551. VKKO.Setting.UnblockScroll();
  552. }
  553. else {
  554. this.classList.add("open");
  555. VKKO.Setting.BlockScroll();
  556. }
  557. }
  558. var __ResizeTimeout;
  559. var __LastClientPlatform;
  560. function resize(event) {
  561. clearTimeout(__ResizeTimeout);
  562. __ResizeTimeout = setTimeout(function () {
  563. if (document.documentElement.clientWidth > CLIENT_PLATFORM.MOBILE) {
  564. if (document.documentElement.clientWidth > CLIENT_PLATFORM.TABLET) {
  565. if (document.documentElement.clientWidth > CLIENT_PLATFORM.OLD_DESKTOP) {
  566. VKKO.Setting.Platform = CLIENT_PLATFORM.OLD_DESKTOP;
  567. }
  568. else {
  569. VKKO.Setting.Platform = CLIENT_PLATFORM.DESKTOP;
  570. }
  571. }
  572. else {
  573. VKKO.Setting.Platform = CLIENT_PLATFORM.TABLET;
  574. }
  575. }
  576. else {
  577. VKKO.Setting.Platform = CLIENT_PLATFORM.MOBILE;
  578. }
  579. }, 250);
  580. }
  581. function login(login, password) {
  582. var data = {
  583. Login: login.value,
  584. Password: password.value
  585. };
  586. VKKOWork.XHR.POST(function (result) {
  587. if (result) {
  588. if (result.Error) {
  589. VKKOWork.Messenger.Show(result.Error);
  590. }
  591. else {
  592. VKKOWork.Messenger.Show("Привет, " + result.Name);
  593. window.location.reload();
  594. }
  595. }
  596. else {
  597. VKKOWork.Messenger.Show("Сервер ничего не вернул :(");
  598. }
  599. }, "/login", data);
  600. this.closest(".modal").querySelector(".close").click();
  601. }
  602. function Init() {
  603. resize();
  604. setTimeout(window.FsLightbox, 250);
  605. setTimeout(function () {
  606. document.body.onresize = resize;
  607. }, 500);
  608. }
  609. Main.Init = Init;
  610. function SignIn() {
  611. var body = document.createElement("div"), inputLogin = document.createElement("input"), inputPass = document.createElement("input"), button = document.createElement("button");
  612. var tabIndex = 1;
  613. inputLogin.type = "text";
  614. inputLogin.placeholder = "Логин";
  615. inputLogin.tabIndex = tabIndex++;
  616. inputPass.type = "password";
  617. inputPass.placeholder = "Пароль";
  618. inputPass.tabIndex = tabIndex++;
  619. inputPass.onkeypress = function (event) {
  620. if (event.keyCode == 13) {
  621. login.call(button, inputLogin, inputPass);
  622. }
  623. };
  624. button.textContent = "Войти";
  625. button.onclick = login.bind(button, inputLogin, inputPass);
  626. button.tabIndex = tabIndex++;
  627. body.append(inputLogin, inputPass, button);
  628. VKKO.Modal.Create("Авторизация", body);
  629. }
  630. Main.SignIn = SignIn;
  631. function SignOut() {
  632. VKKOWork.XHR.POST(function (data) { if (data.Error == null) {
  633. window.location.reload();
  634. } }, "/logout");
  635. }
  636. Main.SignOut = SignOut;
  637. })(Main = VKKO.Main || (VKKO.Main = {}));
  638. })(VKKO || (VKKO = {}));
  639. var VKKO;
  640. (function (VKKO) {
  641. var Tree = (function () {
  642. function Tree() {
  643. this.__Root = document.createElement("div");
  644. this.__Root.classList.add("tree");
  645. }
  646. Tree.prototype.onClickBranch = function (event) {
  647. if (this instanceof HTMLElement) {
  648. var root = this.closest(".tree");
  649. var selected = root.querySelectorAll(".selected");
  650. var thisParent_1 = this.parentElement;
  651. selected.forEach(function (value) {
  652. if (value !== thisParent_1) {
  653. value.classList.remove("selected");
  654. }
  655. });
  656. thisParent_1.classList.toggle("selected");
  657. }
  658. };
  659. Tree.prototype.AddBranch = function (caption, dataset, root) {
  660. var branch = document.createElement("div"), body = document.createElement("div"), head = document.createElement("div");
  661. if (dataset) {
  662. for (var key in dataset) {
  663. if (dataset.hasOwnProperty(key)) {
  664. branch.dataset[key] = dataset[key];
  665. }
  666. }
  667. }
  668. branch.classList.add("branch");
  669. body.classList.add("body");
  670. head.classList.add("head");
  671. head.textContent = caption;
  672. head.onclick = this.onClickBranch;
  673. branch.append(head, body);
  674. if (root) {
  675. root.append(branch);
  676. }
  677. else {
  678. this.__Root.append(branch);
  679. }
  680. return body;
  681. };
  682. Tree.prototype.CreateBranch = function (caption, dataset) {
  683. return this.AddBranch(caption, dataset).parentElement;
  684. };
  685. Tree.prototype.InsertInto = function (index, caption, dataset, root) {
  686. if (!root) {
  687. root = this.__Root;
  688. }
  689. var l = root.children.length;
  690. for (var i = 0; i < l; i++) {
  691. var element = root.children[i];
  692. if (element.classList.contains("branch")) {
  693. if (element.dataset.id && element.dataset.id === index.toString()) {
  694. if (element.children[1] && element.children[1].classList.contains("body")) {
  695. element.children[1].append(this.CreateBranch(caption, dataset));
  696. return;
  697. }
  698. }
  699. else {
  700. if (element.children[1] && element.children[1].classList.contains("body")) {
  701. this.InsertInto(index, caption, dataset, element.children[1]);
  702. }
  703. }
  704. }
  705. }
  706. };
  707. Tree.prototype.SetTo = function (element) {
  708. if (element) {
  709. while (element.children.length > 0) {
  710. element.children[0].remove();
  711. }
  712. while (this.__Root.children.length > 0) {
  713. element.append(this.__Root.children[0]);
  714. }
  715. element.classList.add("tree");
  716. }
  717. };
  718. return Tree;
  719. }());
  720. VKKO.Tree = Tree;
  721. })(VKKO || (VKKO = {}));
  722. var VKKO;
  723. (function (VKKO) {
  724. var MaterialEditor;
  725. (function (MaterialEditor) {
  726. var __CreateNewsButton = document.querySelector("#CreateNewsButton");
  727. if (__CreateNewsButton) {
  728. __CreateNewsButton.onclick = openModal;
  729. }
  730. var __CreateNoticeButton = document.querySelector("#CreateNoticeButton");
  731. if (__CreateNoticeButton) {
  732. __CreateNoticeButton.onclick = openModal;
  733. }
  734. var __CreateMaterialButton = document.querySelector("#CreateMaterialButton");
  735. if (__CreateMaterialButton) {
  736. __CreateMaterialButton.onclick = openModal;
  737. }
  738. var __EditMaterialButton = document.querySelector("#EditMaterialButton");
  739. if (__EditMaterialButton) {
  740. __EditMaterialButton.onclick = getMaterialSource;
  741. }
  742. var __DeleteMaterialButton = document.querySelector("#DeleteMaterialButton");
  743. if (__DeleteMaterialButton) {
  744. __DeleteMaterialButton.onclick = deleteMaterial;
  745. }
  746. var __CurrentCategory = undefined;
  747. function deleteMaterial() {
  748. if (this.dataset.active == "true") {
  749. VKKOWork.XHR.POST(function () { }, "/material-delete/" + this.dataset.link);
  750. }
  751. else {
  752. VKKOWork.XHR.POST(function () { }, "/material-restore/" + this.dataset.link);
  753. }
  754. }
  755. function openModal() {
  756. switch (this.dataset.category) {
  757. case MATERIAL_CATEGORY.MATERIAL:
  758. __CurrentCategory = MATERIAL_CATEGORY.MATERIAL;
  759. break;
  760. case MATERIAL_CATEGORY.NEWS:
  761. __CurrentCategory = MATERIAL_CATEGORY.NEWS;
  762. break;
  763. case MATERIAL_CATEGORY.NOTICE:
  764. __CurrentCategory = MATERIAL_CATEGORY.NOTICE;
  765. break;
  766. default:
  767. return;
  768. }
  769. var body = document.createElement("div"), inputCaption = document.createElement("input"), inputLink = document.createElement("input"), contentBlock = document.createElement("div"), previewBlock = document.createElement("div"), preview = document.createElement("div"), label = document.createElement("label"), file = document.createElement("input"), fileButton = document.createElement("div"), buttonSend = document.createElement("button");
  770. label.append(file, fileButton);
  771. label.className = "select-file";
  772. fileButton.className = "button";
  773. fileButton.textContent = "Выбрать изображениия";
  774. file.type = "file";
  775. if (__CurrentCategory === MATERIAL_CATEGORY.NOTICE) {
  776. file.multiple = false;
  777. }
  778. else {
  779. file.multiple = true;
  780. }
  781. file.accept = "image/*";
  782. file.onchange = changeImages;
  783. inputCaption.type = "text";
  784. inputCaption.placeholder = "Заголовок/название (обязательно)";
  785. inputLink.type = "text";
  786. inputLink.placeholder = "Ссылка на " + __CurrentCategory + " (не обязательно)";
  787. buttonSend.textContent = "Создать";
  788. preview.className = "preview-images";
  789. contentBlock.id = "editorjs";
  790. contentBlock.className = "content-editor";
  791. if (__CurrentCategory !== MATERIAL_CATEGORY.MATERIAL) {
  792. body.append(inputCaption, inputLink, contentBlock, previewBlock, label, preview, buttonSend);
  793. }
  794. else {
  795. body.append(inputCaption, inputLink, contentBlock, previewBlock, buttonSend);
  796. }
  797. var tools = {
  798. header: {
  799. "class": Header,
  800. inlineToolbar: true,
  801. shortcut: "CMD+SHIFT+H"
  802. },
  803. list: {
  804. "class": List,
  805. inlineToolbar: true,
  806. shortcut: "CMD+SHIFT+L"
  807. },
  808. marker: {
  809. "class": Marker,
  810. shortcut: "CMD+SHIFT+M"
  811. },
  812. delimiter: Delimiter,
  813. inlineCode: {
  814. "class": InlineCode,
  815. shortcut: "CMD+SHIFT+C"
  816. },
  817. linkTool: LinkTool,
  818. code: CodeTool,
  819. table: {
  820. "class": Table,
  821. inlineToolbar: true,
  822. shortcut: "CMD+ALT+T"
  823. },
  824. onReady: function () {
  825. console.log("ready");
  826. },
  827. onChange: function () {
  828. console.log("changed");
  829. }
  830. };
  831. if (__CurrentCategory === MATERIAL_CATEGORY.MATERIAL) {
  832. tools.image = {
  833. "class": SimpleImage,
  834. inlineCode: true
  835. };
  836. tools.embed = {
  837. "class": Embed,
  838. inlineToolbar: false,
  839. config: {
  840. services: {
  841. youtube: true
  842. }
  843. }
  844. };
  845. }
  846. var editor = new EditorJS({
  847. holder: contentBlock,
  848. tools: tools,
  849. data: null
  850. });
  851. buttonSend.addEventListener("click", function () {
  852. editor.save().then(function (savedData) {
  853. create.call(buttonSend, inputCaption, inputLink, savedData, preview, file);
  854. });
  855. });
  856. VKKO.Modal.Create("Создать " + __CurrentCategory, body);
  857. }
  858. function getMaterialSource() {
  859. VKKOWork.XHR.POST(openModalToEdit, "/material-get-source/" + this.dataset.link);
  860. }
  861. function openModalToEdit(data) {
  862. if (!__EditMaterialButton) {
  863. return;
  864. }
  865. var source = {};
  866. try {
  867. source.Caption = data.Data.Caption;
  868. source.Category = data.Data.Category;
  869. source.Link = data.Data.Link;
  870. source.Source = JSON.parse(data.Data.Source);
  871. source.SourceImages = JSON.parse(data.Data.SourceImages);
  872. }
  873. catch (error) {
  874. VKKO.Utils.logError(error);
  875. VKKOWork.Messenger.Show("Ошибка загрузки исходных данных материала: " + error);
  876. return;
  877. }
  878. switch (source.Category) {
  879. case MATERIAL_CATEGORY.MATERIAL:
  880. __CurrentCategory = MATERIAL_CATEGORY.MATERIAL;
  881. break;
  882. case MATERIAL_CATEGORY.NEWS:
  883. __CurrentCategory = MATERIAL_CATEGORY.NEWS;
  884. break;
  885. case MATERIAL_CATEGORY.NOTICE:
  886. __CurrentCategory = MATERIAL_CATEGORY.NOTICE;
  887. break;
  888. default:
  889. VKKOWork.Messenger.Show("Неизвестная категория материала: " + source.Category);
  890. return;
  891. }
  892. var body = document.createElement("div"), inputCaption = document.createElement("input"), inputLink = document.createElement("input"), contentBlock = document.createElement("div"), previewBlock = document.createElement("div"), preview = document.createElement("div"), buttonSend = document.createElement("button");
  893. inputCaption.type = "text";
  894. inputCaption.placeholder = "Заголовок/название (обязательно)";
  895. inputCaption.value = source.Caption;
  896. inputLink.disabled = true;
  897. inputLink.type = "text";
  898. inputLink.value = source.Link;
  899. buttonSend.textContent = "Сохранить изменения";
  900. preview.className = "preview-images";
  901. contentBlock.id = "editorjs";
  902. contentBlock.className = "content-editor";
  903. createPreviewImagesFromSource(preview, source.SourceImages);
  904. if (__CurrentCategory !== MATERIAL_CATEGORY.MATERIAL) {
  905. body.append(inputCaption, inputLink, contentBlock, previewBlock, preview, buttonSend);
  906. }
  907. else {
  908. body.append(inputCaption, inputLink, contentBlock, previewBlock, buttonSend);
  909. }
  910. var tools = {
  911. header: {
  912. "class": Header,
  913. inlineToolbar: true,
  914. shortcut: "CMD+SHIFT+H"
  915. },
  916. list: {
  917. "class": List,
  918. inlineToolbar: true,
  919. shortcut: "CMD+SHIFT+L"
  920. },
  921. marker: {
  922. "class": Marker,
  923. shortcut: "CMD+SHIFT+M"
  924. },
  925. delimiter: Delimiter,
  926. inlineCode: {
  927. "class": InlineCode,
  928. shortcut: "CMD+SHIFT+C"
  929. },
  930. linkTool: LinkTool,
  931. table: {
  932. "class": Table,
  933. inlineToolbar: true,
  934. shortcut: "CMD+ALT+T"
  935. },
  936. onReady: function () {
  937. console.log("ready");
  938. },
  939. onChange: function () {
  940. console.log("changed");
  941. }
  942. };
  943. if (__CurrentCategory === MATERIAL_CATEGORY.MATERIAL) {
  944. tools.image = {
  945. "class": SimpleImage,
  946. inlineCode: true
  947. };
  948. tools.embed = {
  949. "class": Embed,
  950. inlineToolbar: false,
  951. config: {
  952. services: {
  953. youtube: true
  954. }
  955. }
  956. };
  957. }
  958. var editor = new EditorJS({
  959. holder: contentBlock,
  960. tools: tools,
  961. data: JSON.parse(data.Data.Source)
  962. });
  963. buttonSend.addEventListener("click", function () {
  964. editor.save().then(function (savedData) {
  965. update.call(buttonSend, inputCaption, inputLink, savedData, preview, source.SourceImages);
  966. });
  967. });
  968. VKKO.Modal.Create("Редактировать " + __CurrentCategory, body);
  969. }
  970. function changeImages() {
  971. var preview = document.querySelector(".preview-images");
  972. if (!preview) {
  973. VKKO.Utils.logWarning("Элемент [.preview-images] не найден");
  974. return;
  975. }
  976. for (var _i = 0, _a = this.files; _i < _a.length; _i++) {
  977. var file = _a[_i];
  978. var div = document.createElement("div");
  979. div.className = "image";
  980. var img = document.createElement("img");
  981. img.src = window.URL.createObjectURL(file);
  982. img.alt = file.name;
  983. img.height = 100;
  984. var label = document.createElement("label");
  985. var input = document.createElement("input");
  986. input.type = "radio";
  987. input.dataset.image = file.name;
  988. input.name = "preview-images";
  989. var span = document.createElement("span");
  990. div.append(img, label);
  991. label.append(input, span);
  992. preview.append(div);
  993. }
  994. var firstImage = preview.querySelector("input");
  995. firstImage.click();
  996. }
  997. function dataURIToBlob(dataURI) {
  998. var splitDataURI = dataURI.split(",");
  999. var byteString = splitDataURI[0].indexOf("base64") >= 0 ? atob(splitDataURI[1]) : decodeURI(splitDataURI[1]);
  1000. var mimeString = splitDataURI[0].split(":")[1].split(";")[0];
  1001. var ia = new Uint8Array(byteString.length);
  1002. for (var i = 0; i < byteString.length; i++)
  1003. ia[i] = byteString.charCodeAt(i);
  1004. return new Blob([ia], { type: mimeString });
  1005. }
  1006. function createPreviewImagesFromSource(element, source) {
  1007. for (var _i = 0, source_1 = source; _i < source_1.length; _i++) {
  1008. var file = source_1[_i];
  1009. var div = document.createElement("div");
  1010. div.className = "image";
  1011. var img = document.createElement("img");
  1012. img.src = file.Thumb;
  1013. img.height = 100;
  1014. element.append(div);
  1015. }
  1016. }
  1017. function create(caption, link, content, images, file) {
  1018. if (!caption || !link || !content || !images) {
  1019. VKKOWork.Messenger.Show("Некоторые элементы не были найдены, невозможно создать новость!");
  1020. return;
  1021. }
  1022. if (caption.value.length == 0) {
  1023. VKKOWork.Messenger.Show("Необходимо заполнить заголовок!");
  1024. return;
  1025. }
  1026. if (link.value.length == 0) {
  1027. link.value = VKKO.Utils.GenerateHash256();
  1028. }
  1029. var preview = {
  1030. Valid: "true",
  1031. String: ""
  1032. };
  1033. var date = new Date();
  1034. var m = ("00" + (date.getMonth() + 1)).slice(-2);
  1035. var d = ("00" + date.getDate()).slice(-2);
  1036. var imageFullpath = "image/" + __CurrentCategory + "/" + date.getUTCFullYear().toString() + "-" + m + "-" + d + "/";
  1037. var thumbFullpath = "thumb/" + __CurrentCategory + "/" + date.getUTCFullYear().toString() + "-" + m + "-" + m + "/";
  1038. var data = new FormData();
  1039. var contentHtml = "";
  1040. for (var _i = 0, _a = content.blocks; _i < _a.length; _i++) {
  1041. var c = _a[_i];
  1042. switch (c.type) {
  1043. case "paragraph":
  1044. contentHtml += "<p>" + c.data.text + "</p>";
  1045. preview.String += c.data.text;
  1046. break;
  1047. case "header":
  1048. contentHtml += "<h" + c.data.level + ">" + c.data.text + "</h" + c.data.level + ">";
  1049. preview.String += c.data.text;
  1050. break;
  1051. case "list":
  1052. if (c.data.style === "ordered") {
  1053. contentHtml += "<ol>";
  1054. for (var _b = 0, _c = c.data.items; _b < _c.length; _b++) {
  1055. var li = _c[_b];
  1056. contentHtml += "<li>" + li + "</li>";
  1057. preview.String += li;
  1058. }
  1059. contentHtml += "</ol>";
  1060. }
  1061. else {
  1062. contentHtml += "<ul>";
  1063. for (var _d = 0, _e = c.data.items; _d < _e.length; _d++) {
  1064. var li = _e[_d];
  1065. contentHtml += "<li>" + li + "</li>";
  1066. preview.String += li;
  1067. }
  1068. contentHtml += "</ul>";
  1069. }
  1070. break;
  1071. case "delimiter":
  1072. contentHtml += "<hr>";
  1073. break;
  1074. case "table":
  1075. contentHtml += "<table>";
  1076. for (var _f = 0, _g = c.data.content; _f < _g.length; _f++) {
  1077. var row = _g[_f];
  1078. contentHtml += "<tr>";
  1079. for (var _h = 0, row_1 = row; _h < row_1.length; _h++) {
  1080. var col = row_1[_h];
  1081. contentHtml += "<td>" + col + "</td>";
  1082. preview.String += col;
  1083. }
  1084. contentHtml += "</tr>";
  1085. }
  1086. contentHtml += "</table>";
  1087. break;
  1088. case "image":
  1089. var filename = VKKO.Utils.GenerateHashDashed(2) + "." + c.data.url.slice(11, c.data.url.indexOf(";"));
  1090. contentHtml +=
  1091. '<a href="/' +
  1092. imageFullpath +
  1093. filename +
  1094. '" data-fslightbox="' +
  1095. link.value +
  1096. '"><img class="material-image" src="/' +
  1097. thumbFullpath +
  1098. filename +
  1099. '" /></a>';
  1100. var div = document.createElement("div");
  1101. div.innerHTML = c.data.caption;
  1102. if (div.textContent.length > 0) {
  1103. contentHtml += '<div class="material-image-caption">' + c.data.caption + "</div>";
  1104. }
  1105. data.append("Files", dataURIToBlob(c.data.url), filename);
  1106. break;
  1107. case "embed":
  1108. contentHtml += '<iframe src="' + c.data.embed + '" style="width:' + c.data.width + 'px; height:' + c.data.height + 'px;display:block;margin:40px auto;" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen="" frameborder="0"></iframe>';
  1109. var youtubeCaption = document.createElement("div");
  1110. youtubeCaption.innerHTML = c.data.caption;
  1111. if (youtubeCaption.textContent.length > 0) {
  1112. contentHtml += '<div class="material-image-caption">' + c.data.caption + "</div>";
  1113. }
  1114. break;
  1115. }
  1116. }
  1117. var clearTags = document.createElement("div");
  1118. clearTags.innerHTML = preview.String;
  1119. preview.String = clearTags.textContent;
  1120. if (preview.String.length > 260) {
  1121. preview.String = preview.String.slice(0, 260);
  1122. }
  1123. var selectedImage = {
  1124. Valid: "false",
  1125. String: ""
  1126. };
  1127. var sourceImages = [];
  1128. if (__CurrentCategory != MATERIAL_CATEGORY.MATERIAL) {
  1129. var selectedImageName = ";";
  1130. var selectedInput = images.querySelector("input:checked");
  1131. if (selectedInput) {
  1132. var img = selectedInput.closest(".image").querySelector("img");
  1133. if (img) {
  1134. selectedImageName = img.alt;
  1135. selectedImage.String = thumbFullpath + selectedImageName.toLowerCase();
  1136. selectedImage.Valid = "true";
  1137. }
  1138. }
  1139. if (file.files.length > 0) {
  1140. if (__CurrentCategory != MATERIAL_CATEGORY.NOTICE) {
  1141. contentHtml += '<div class="news-images">';
  1142. }
  1143. for (var i = 0; i < file.files.length; i++) {
  1144. var f = file.files.item(i);
  1145. var filename = f.name.toLowerCase();
  1146. filename = VKKO.Utils.GenerateHashDashed(2) + filename.slice(filename.lastIndexOf("."));
  1147. if (selectedImageName === f.name) {
  1148. selectedImage.String = thumbFullpath + filename;
  1149. }
  1150. if (__CurrentCategory != MATERIAL_CATEGORY.NOTICE) {
  1151. contentHtml +=
  1152. '<a href="/' +
  1153. imageFullpath +
  1154. filename +
  1155. '" data-fslightbox="' +
  1156. link.value +
  1157. '"><img src="/' +
  1158. thumbFullpath +
  1159. filename +
  1160. '" alt="' +
  1161. filename +
  1162. '"></a>';
  1163. }
  1164. data.append("Files", f, filename);
  1165. sourceImages.push({
  1166. Image: "/" + imageFullpath + filename,
  1167. Thumb: "/" + thumbFullpath + filename
  1168. });
  1169. }
  1170. if (__CurrentCategory != MATERIAL_CATEGORY.NOTICE) {
  1171. contentHtml += "</div>";
  1172. }
  1173. }
  1174. }
  1175. data.set("Caption", caption.value);
  1176. data.set("Link", link.value);
  1177. data.set("Content", contentHtml);
  1178. data.set("Source", JSON.stringify(content));
  1179. data.set("SourceImages", JSON.stringify(sourceImages));
  1180. data.set("PreviewValid", preview.Valid);
  1181. data.set("PreviewString", preview.String);
  1182. data.set("ImageValid", selectedImage.Valid);
  1183. data.set("ImageString", selectedImage.String);
  1184. data.set("ImagePath", imageFullpath);
  1185. data.set("ThumbPath", thumbFullpath);
  1186. var closeModal = this.closest(".modal").querySelector(".close");
  1187. VKKOWork.XHR.POST(function (result) {
  1188. if (result && "Error" in result) {
  1189. if (result.Error === null) {
  1190. VKKOWork.Messenger.Show(__CurrentCategory + " успешно добавлена");
  1191. closeModal.click();
  1192. }
  1193. else {
  1194. VKKOWork.Messenger.Show("Возникла ошибка добавления новости." + result.Error);
  1195. }
  1196. }
  1197. }, "/material-insert/" + __CurrentCategory, data, null, true, true);
  1198. }
  1199. function update(caption, link, content, images, source) {
  1200. if (!caption || !link || !content || !images) {
  1201. VKKOWork.Messenger.Show("Некоторые элементы не были найдены, невозможно создать новость!");
  1202. return;
  1203. }
  1204. if (caption.value.length == 0) {
  1205. VKKOWork.Messenger.Show("Необходимо заполнить заголовок!");
  1206. return;
  1207. }
  1208. if (link.value.length == 0) {
  1209. link.value = VKKO.Utils.GenerateHash256();
  1210. }
  1211. var preview = {
  1212. Valid: "true",
  1213. String: ""
  1214. };
  1215. var date = new Date();
  1216. var m = ("00" + (date.getMonth() + 1)).slice(-2);
  1217. var d = ("00" + date.getDate()).slice(-2);
  1218. var imageFullpath = "";
  1219. var thumbFullpath = "";
  1220. if (__CurrentCategory != MATERIAL_CATEGORY.MATERIAL) {
  1221. if (source.length > 0) {
  1222. imageFullpath = source[0].Image.slice(1, source[0].Image.lastIndexOf("/") + 1);
  1223. thumbFullpath = source[0].Thumb.slice(1, source[0].Thumb.lastIndexOf("/") + 1);
  1224. }
  1225. }
  1226. else {
  1227. imageFullpath = "image/" + __CurrentCategory + "/" + date.getUTCFullYear().toString() + "-" + m + "-" + d + "/";
  1228. thumbFullpath = "thumb/" + __CurrentCategory + "/" + date.getUTCFullYear().toString() + "-" + m + "-" + m + "/";
  1229. }
  1230. var data = new FormData();
  1231. var contentHtml = "";
  1232. for (var _i = 0, _a = content.blocks; _i < _a.length; _i++) {
  1233. var c = _a[_i];
  1234. switch (c.type) {
  1235. case "paragraph":
  1236. contentHtml += "<p>" + c.data.text + "</p>";
  1237. preview.String += c.data.text;
  1238. break;
  1239. case "header":
  1240. contentHtml += "<h" + c.data.level + ">" + c.data.text + "</h" + c.data.level + ">";
  1241. preview.String += c.data.text;
  1242. break;
  1243. case "list":
  1244. if (c.data.style === "ordered") {
  1245. contentHtml += "<ol>";
  1246. for (var _b = 0, _c = c.data.items; _b < _c.length; _b++) {
  1247. var li = _c[_b];
  1248. contentHtml += "<li>" + li + "</li>";
  1249. preview.String += li;
  1250. }
  1251. contentHtml += "</ol>";
  1252. }
  1253. else {
  1254. contentHtml += "<ul>";
  1255. for (var _d = 0, _e = c.data.items; _d < _e.length; _d++) {
  1256. var li = _e[_d];
  1257. contentHtml += "<li>" + li + "</li>";
  1258. preview.String += li;
  1259. }
  1260. contentHtml += "</ul>";
  1261. }
  1262. break;
  1263. case "delimiter":
  1264. contentHtml += "<hr>";
  1265. break;
  1266. case "table":
  1267. contentHtml += "<table>";
  1268. for (var _f = 0, _g = c.data.content; _f < _g.length; _f++) {
  1269. var row = _g[_f];
  1270. contentHtml += "<tr>";
  1271. for (var _h = 0, row_2 = row; _h < row_2.length; _h++) {
  1272. var col = row_2[_h];
  1273. contentHtml += "<td>" + col + "</td>";
  1274. preview.String += col;
  1275. }
  1276. contentHtml += "</tr>";
  1277. }
  1278. contentHtml += "</table>";
  1279. break;
  1280. case "image":
  1281. var filename = VKKO.Utils.GenerateHashDashed(2) + "." + c.data.url.slice(11, c.data.url.indexOf(";"));
  1282. contentHtml +=
  1283. '<a href="/' +
  1284. imageFullpath +
  1285. filename +
  1286. '" data-fslightbox="' +
  1287. link.value +
  1288. '"><img class="material-image" src="/' +
  1289. thumbFullpath +
  1290. filename +
  1291. '" /></a>';
  1292. var div = document.createElement("div");
  1293. div.innerHTML = c.data.caption;
  1294. if (div.textContent.length > 0) {
  1295. contentHtml += '<div class="material-image-caption">' + c.data.caption + "</div>";
  1296. }
  1297. data.append("Files", dataURIToBlob(c.data.url), filename);
  1298. break;
  1299. case "embed":
  1300. contentHtml += '<iframe src="' + c.data.embed + '" style="width: ' + c.data.width + 'px; height: ' + c.data.height + 'px;" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen="" frameborder="0"></iframe>';
  1301. var youtubeCaption = document.createElement("div");
  1302. youtubeCaption.innerHTML = c.data.caption;
  1303. if (youtubeCaption.textContent.length > 0) {
  1304. contentHtml += '<div class="material-image-caption">' + c.data.caption + "</div>";
  1305. }
  1306. break;
  1307. }
  1308. }
  1309. var clearTags = document.createElement("div");
  1310. clearTags.innerHTML = preview.String;
  1311. preview.String = clearTags.textContent;
  1312. if (preview.String.length > 260) {
  1313. preview.String = preview.String.slice(0, 260);
  1314. }
  1315. if (__CurrentCategory != MATERIAL_CATEGORY.MATERIAL) {
  1316. if (source.length > 0) {
  1317. if (__CurrentCategory != MATERIAL_CATEGORY.NOTICE) {
  1318. contentHtml += '<div class="news-images">';
  1319. }
  1320. for (var i = 0; i < source.length; i++) {
  1321. if (__CurrentCategory != MATERIAL_CATEGORY.NOTICE) {
  1322. contentHtml +=
  1323. '<a href="' + source[i].Image +
  1324. '" data-fslightbox="' +
  1325. link.value +
  1326. '"><img src="' +
  1327. source[i].Thumb +
  1328. '" alt="' +
  1329. source[i].Image.slice(source[i].Image.lastIndexOf("/") + 1) +
  1330. '"></a>';
  1331. }
  1332. }
  1333. if (__CurrentCategory != MATERIAL_CATEGORY.NOTICE) {
  1334. contentHtml += "</div>";
  1335. }
  1336. }
  1337. }
  1338. data.set("Link", __EditMaterialButton.dataset.link);
  1339. data.set("Caption", caption.value);
  1340. data.set("Content", contentHtml);
  1341. data.set("Source", JSON.stringify(content));
  1342. data.set("PreviewValid", preview.Valid);
  1343. data.set("PreviewString", preview.String);
  1344. data.set("ImagePath", imageFullpath);
  1345. data.set("ThumbPath", thumbFullpath);
  1346. var closeModal = this.closest(".modal").querySelector(".close");
  1347. VKKOWork.XHR.POST(function (result) {
  1348. if (result && "Error" in result) {
  1349. if (result.Error === null) {
  1350. VKKOWork.Messenger.Show(__CurrentCategory + " успешно добавлена");
  1351. closeModal.click();
  1352. }
  1353. else {
  1354. VKKOWork.Messenger.Show("Возникла ошибка добавления новости." + result.Error);
  1355. }
  1356. }
  1357. }, "/material-update/" + __CurrentCategory, data, null, true, true);
  1358. }
  1359. })(MaterialEditor = VKKO.MaterialEditor || (VKKO.MaterialEditor = {}));
  1360. })(VKKO || (VKKO = {}));
  1361. var VKKO;