var MATERIAL_CATEGORY; (function (MATERIAL_CATEGORY) { MATERIAL_CATEGORY["MATERIAL"] = "\u043C\u0430\u0442\u0435\u0440\u0438\u0430\u043B"; MATERIAL_CATEGORY["NEWS"] = "\u043D\u043E\u0432\u043E\u0441\u0442\u044C"; MATERIAL_CATEGORY["NOTICE"] = "\u043E\u0431\u044A\u044F\u0432\u043B\u0435\u043D\u0438\u0435"; })(MATERIAL_CATEGORY || (MATERIAL_CATEGORY = {})); var MENU_CATEGORY; (function (MENU_CATEGORY) { MENU_CATEGORY["MAIN"] = "__main"; MENU_CATEGORY["TOP"] = "__top"; })(MENU_CATEGORY || (MENU_CATEGORY = {})); var CLIENT_PLATFORM; (function (CLIENT_PLATFORM) { CLIENT_PLATFORM[CLIENT_PLATFORM["DESKTOP"] = 9999] = "DESKTOP"; CLIENT_PLATFORM[CLIENT_PLATFORM["OLD_DESKTOP"] = 1280] = "OLD_DESKTOP"; CLIENT_PLATFORM[CLIENT_PLATFORM["TABLET"] = 1024] = "TABLET"; CLIENT_PLATFORM[CLIENT_PLATFORM["MOBILE"] = 560] = "MOBILE"; })(CLIENT_PLATFORM || (CLIENT_PLATFORM = {})); var VKKO; (function (VKKO) { var Setting; (function (Setting) { var __BlockingScrollCount = 0; Setting.Platform = CLIENT_PLATFORM.DESKTOP; function BlockScroll() { document.documentElement.style.marginRight = window.innerWidth - document.documentElement.clientWidth + "px"; document.documentElement.style.overflow = "hidden"; __BlockingScrollCount++; } Setting.BlockScroll = BlockScroll; ; function UnblockScroll() { __BlockingScrollCount--; if (__BlockingScrollCount <= 0) { document.documentElement.style.overflow = ""; document.documentElement.style.marginRight = null; __BlockingScrollCount = 0; } } Setting.UnblockScroll = UnblockScroll; ; })(Setting = VKKO.Setting || (VKKO.Setting = {})); })(VKKO || (VKKO = {})); var VKKO; (function (VKKO) { var Utils; (function (Utils) { function logError(message) { console.log("%c ERROR ", "background-color: red; color: white; font-weight: 700;", message); } Utils.logError = logError; function logWarning(message) { console.log("%c WARNING ", "background-color: orange; color: white; font-weight: 700;", message); } Utils.logWarning = logWarning; function logInfo(message) { console.log("%c INFO ", "background-color: green; color: white; font-weight: 700;", message); } Utils.logInfo = logInfo; function GenerateHash256(uppercase) { if (uppercase === void 0) { uppercase = false; } var randomValue = crypto.getRandomValues(new Uint32Array(4)); var randomHash = ""; for (var i = 0; i < randomValue.length; i++) { randomHash += randomValue[i].toString(16); } if (uppercase === true) { return randomHash.toUpperCase(); } return randomHash; } Utils.GenerateHash256 = GenerateHash256; ; function GenerateHashDashed(group) { if (group === void 0) { group = 4; } var randomValue = crypto.getRandomValues(new Uint32Array(group)); var randomHash = ""; for (var i = 0; i < randomValue.length; i++) { randomHash += randomValue[i].toString(16) + "-"; } return randomHash.slice(0, randomHash.length - 1).toUpperCase(); } Utils.GenerateHashDashed = GenerateHashDashed; ; })(Utils = VKKO.Utils || (VKKO.Utils = {})); })(VKKO || (VKKO = {})); var VKKO; (function (VKKO) { var Messenger = (function () { function Messenger() { this.HARDREMOVE_TIME = 100; this.AUTOREMOVE_TIME = 2000; this.REMOVING_SHORT = "short"; this.REMOVING_LONG = "long"; this.MESSAGE_COUNTER = -1; this.__MessageContainer = document.querySelector("#MessengerBox"); if (!this.__MessageContainer) { this.__MessageContainer = document.createElement("div"); this.__MessageContainer.classList.add("messenger"); this.__MessageContainer.id = "MessengerBox"; document.body.append(this.__MessageContainer); } } Messenger.prototype.removeMessage = function (time, transition) { if (time === void 0) { time = this.HARDREMOVE_TIME; } if (transition === void 0) { transition = this.REMOVING_SHORT; } if (this instanceof HTMLElement) { this.classList.add("removing", transition); setTimeout(function (element) { element.remove(); }, time, this); } else { 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"); } }; Messenger.prototype.autoRemoveMessage = function (element) { this.removeMessage.call(element, this.AUTOREMOVE_TIME, this.REMOVING_SHORT); }; Messenger.prototype.Show = function (msg, time) { if (time === void 0) { time = 10000; } var message = document.createElement("div"); message.id = "MessageTick" + ++this.MESSAGE_COUNTER; message.classList.add("in"); var content = document.createElement("div"); content.textContent = msg; var close = document.createElement("span"); close.classList.add("close"); close.onclick = this.removeMessage.bind(message); message.append(close, content); this.__MessageContainer.append(message); setTimeout(function () { message.classList.remove("in"); }, 100); setTimeout(this.autoRemoveMessage.bind(this, message), time); }; return Messenger; }()); VKKO.Messenger = Messenger; })(VKKO || (VKKO = {})); var VKKOWork; (function (VKKOWork) { VKKOWork.Messenger = new VKKO.Messenger(); })(VKKOWork || (VKKOWork = {})); var VKKO; (function (VKKO) { var XHR = (function () { function XHR() { this.__QueryCounter = 0; this.__LoadAnimationElement = document.querySelector("#LoadingAnimation"); if (!this.__LoadAnimationElement) { this.__LoadAnimationElement = document.createElement("div"); this.__LoadAnimationElement.id = "LoadingAnimation"; this.__LoadAnimationElement.className = "loading hidden"; for (var i = 0; i < 7; i++) { var element = document.createElement("div"); element.className = "glob"; element.setAttribute("style", "--i:" + (i + 1)); this.__LoadAnimationElement.append(element); } document.body.append(this.__LoadAnimationElement); } } XHR.prototype.onStartRequest = function (event) { if (this.__QueryCounter === 0) { this.__LoadAnimationElement.classList.remove("hidden"); } this.__QueryCounter++; }; XHR.prototype.onStopRequest = function (event) { this.__QueryCounter--; if (this.__QueryCounter <= 0) { this.__LoadAnimationElement.classList.add("hidden"); this.__QueryCounter = 0; } }; XHR.prototype.POST = function (callback, uri, params, callbackParams, isAsinc, multipart) { if (isAsinc === void 0) { isAsinc = true; } if (multipart === void 0) { multipart = false; } if (!uri) { VKKO.Utils.logError("URI не был передан"); return; } if (!params) { params = {}; } var xhr = new XMLHttpRequest(); xhr.onloadstart = this.onStartRequest; xhr.onloadend = this.onStopRequest; xhr.onabort = function (event) { VKKO.Utils.logWarning(uri + " => Выполнение запроса было прервано..."); VKKOWork.Messenger.Show("Выполнение запроса было прервано..."); }; xhr.onerror = function (event) { VKKO.Utils.logError(uri + " => " + this.statusText + " " + this.status); VKKOWork.Messenger.Show("Выполнение запроса завершилось неудачей. Перезагрузите страницу и повторите попытку. Если проблема сохраняется, пожалуйста, сообщите об этом администратору admin@ktk-45.ru"); }; xhr.ontimeout = function (event) { VKKO.Utils.logError(uri + " => Время ожидания запроса истекло... Проверьте соединение с интернетом"); VKKOWork.Messenger.Show("Время ожидания запроса истекло... Проверьте соединение с интернетом"); }; xhr.onload = function (event) { VKKO.Utils.logInfo(uri + " => " + this.statusText + " " + this.status.toString()); var data; try { data = JSON.parse(this.response); } catch (error) { VKKO.Utils.logError(error); data = null; } if (data === null) { return; } if ("Error" in data) { if (typeof data.Error === "boolean") { VKKOWork.Messenger.Show(data.Error); return; } } callback(data, callbackParams); }; xhr.open("POST", uri, isAsinc); if (!multipart) { xhr.setRequestHeader("Content-Type", "application/json; charset=utf-8"); xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest"); xhr.send(JSON.stringify(params)); } else { xhr.send(params); } }; return XHR; }()); VKKO.XHR = XHR; })(VKKO || (VKKO = {})); var VKKOWork; (function (VKKOWork) { VKKOWork.XHR = new VKKO.XHR(); })(VKKOWork || (VKKOWork = {})); var VKKO; (function (VKKO) { var Control; (function (Control) { function CreateCheckbox(text, id, dataset, onchange) { if (dataset === void 0) { dataset = null; } if (onchange === void 0) { onchange = null; } var label = document.createElement("label"), input = document.createElement("input"), spanCheck = document.createElement("span"), spanText = document.createElement("span"); label.className = "checkbox"; label.append(input, spanCheck, spanText); spanText.className = "text"; spanText.textContent = text; spanCheck.className = "checked"; input.type = "checkbox"; if (id) { var ifExists = document.querySelector("#" + id); if (ifExists) { VKKOWork.Messenger.Show("Нельзя создать элемент с повторяющимся идентификатором"); return; } input.id = id; } if (dataset) { for (var key in dataset) { if (dataset.hasOwnProperty(key)) { input.dataset[key] = dataset[key]; } } } if (onchange) { input.onchange = onchange; } return label; } Control.CreateCheckbox = CreateCheckbox; })(Control = VKKO.Control || (VKKO.Control = {})); })(VKKO || (VKKO = {})); var VKKO; (function (VKKO) { var Modal; (function (Modal) { var __ModalCounter = 0; function Create(head, body, callback) { var backdropContainer; if (__ModalCounter === 0) { backdropContainer = document.createElement("div"); backdropContainer.className = "backdrop-container"; document.body.append(backdropContainer); VKKO.Setting.BlockScroll(); } else { backdropContainer = document.querySelector(".backdrop-container"); } if (backdropContainer == undefined) { VKKOWork.Messenger.Show("Ой, что-то пошло не так..."); return; } var emodal = document.createElement("div"), ehead = document.createElement("div"), ebody = document.createElement("div"), eclose = document.createElement("div"), backdrop = document.createElement("div"); backdrop.className = "backdrop"; emodal.className = "modal"; ehead.className = "head"; ebody.className = "body"; eclose.className = "close fas fa-times"; eclose.onclick = destroy.bind(eclose, callback); emodal.append(eclose, ehead, ebody); backdrop.append(emodal); backdropContainer.append(backdrop); backdrop.style.zIndex = (__ModalCounter++).toString(); if (typeof head === "string" || head instanceof HTMLElement) { ehead.append(head); } if (body instanceof HTMLElement) { while (body.children.length > 0) { ebody.append(body.children[0]); } } } Modal.Create = Create; function destroy(callback, event) { var backdrop = this.closest(".backdrop"); if (backdrop) { backdrop.remove(); __ModalCounter--; } if (__ModalCounter < 1) { var backdropContainer = document.querySelector(".backdrop-container"); if (backdropContainer) { backdropContainer.remove(); __ModalCounter = 0; VKKO.Setting.UnblockScroll(); } } if (callback) { callback(); } } })(Modal = VKKO.Modal || (VKKO.Modal = {})); })(VKKO || (VKKO = {})); var VKKO; (function (VKKO) { var Slider = (function () { function Slider(containerSelector, swipeSpeed, swipeInterval) { if (swipeSpeed === void 0) { swipeSpeed = 250; } if (swipeInterval === void 0) { swipeInterval = 5000; } this.__SlideCount = 0; this.__WidthOneSlide = 0; this.__CarouselRoot = document.querySelector(containerSelector); if (!this.__CarouselRoot) { VKKO.Utils.logWarning("Отмена создания слайдера. Нет корневого контейнера."); return; } this.__Carousel = this.__CarouselRoot.querySelector(".carousel"); if (!this.__Carousel) { VKKO.Utils.logWarning("Отмена создания слайдера. Отсутствует бокс."); this.__CarouselRoot.remove(); return; } this.__Slider = this.__Carousel.querySelector(".slider"); if (!this.__Slider) { this.__CarouselRoot.remove(); return; } this.__NavigationDots = this.__Carousel.querySelector(".navigation-dots"); this.__SlideCount = this.__Slider.children.length; if (this.__SlideCount == 0) { this.__CarouselRoot.remove(); return; } switch (VKKO.Setting.Platform) { case CLIENT_PLATFORM.DESKTOP: this.__WidthOneSlide = this.__CarouselRoot.getBoundingClientRect().width; break; case CLIENT_PLATFORM.TABLET: break; case CLIENT_PLATFORM.MOBILE: this.__WidthOneSlide = document.documentElement.clientWidth; break; default: this.__WidthOneSlide = this.__CarouselRoot.getBoundingClientRect().width; } this.buildNavigationDots(); this.buildButtonEvent(); if (this.__SlideCount == 1) { this.__Slider.style.width = this.__WidthOneSlide + "px"; this.outForeground(); return; } if (this.__SlideCount > 1) { this.__Slider.prepend(this.__Slider.lastElementChild); } this.__SwipeInterval = swipeInterval; this.__SwipeSpeed = swipeSpeed; this.__Slider.style.width = (this.__SlideCount * this.__WidthOneSlide) + "px"; this.__Slider.style.left = "-" + this.__WidthOneSlide + "px"; this.__Slider.onmouseover = this.stopSlider.bind(this); this.__Slider.onmouseout = this.startSlider.bind(this); this.outForeground(); this.startSlider(); } Slider.prototype.buildNavigationDots = function () { if (this.__NavigationDots) { while (this.__NavigationDots.children.length > 0) { this.__NavigationDots.children[0].remove(); } for (var i = 0; i < this.__SlideCount; i++) { var element = document.createElement("div"); element.dataset.slide = i.toString(); element.onclick = this.goToSlide.bind(this, element); this.__NavigationDots.append(element); } if (this.__NavigationDots.children.length > 0) { this.__NavigationDots.children[0].classList.add("active"); } } }; Slider.prototype.buildButtonEvent = function () { for (var i = 0; i < this.__Slider.children.length; i++) { var button = this.__Slider.children[i].querySelector(".gradient-button"); if (button) { button.onclick = this.toggleSlide.bind(this, button); } } }; Slider.prototype.outForeground = function () { this.__Carousel.classList.add("out"); this.__Carousel.ontransitionend = function (event) { event.target.classList.remove("hide", "out"); }; }; Slider.prototype.goToSlide = function (element) { this.stopSlider(); this.__Slider.style.transition = "left " + this.__SwipeSpeed + "ms cubic-bezier(.18,.89,.32,1.28)"; var currentSlide = this.__Slider.children[1]; var currentSlideID = currentSlide.dataset.slide; var toSlideID = element.dataset.slide; while (toSlideID != currentSlideID) { this.__Slider.append(this.__Slider.firstElementChild); currentSlide = this.__Slider.children[1]; currentSlideID = currentSlide.dataset.slide; } this.__Slider.style.left = "-" + this.__WidthOneSlide * 2 + "px"; this.__Slider.ontransitionend = this.nextEndAlt.bind(this); this.switchNavigationDot(); }; Slider.prototype.switchNavigationDot = function () { var currentSlide = this.__Slider.children[1]; var slide = Number(currentSlide.dataset.slide); var activeDots = this.__NavigationDots.querySelectorAll(".active"); activeDots.forEach(function (element) { element.classList.remove("active"); }); this.__NavigationDots.children[slide].classList.add("active"); }; Slider.prototype.stopSlider = function () { clearInterval(this.__SwipeIntervalHandle); this.__SwipeIntervalHandle = undefined; this.__Slider.ontransitionend = undefined; }; Slider.prototype.startSlider = function () { if (this.__SwipeIntervalHandle) { clearInterval(this.__SwipeIntervalHandle); } this.__SwipeIntervalHandle = setInterval(this.nextSlide.bind(this), this.__SwipeInterval); this.__Slider.ontransitionend = this.nextEnd.bind(this); }; Slider.prototype.nextSlide = function () { this.__Slider.style.transition = "left " + this.__SwipeSpeed + "ms cubic-bezier(.6,-0.28,.74,.05)"; this.__Slider.style.left = "-" + this.__WidthOneSlide * 2 + "px"; }; Slider.prototype.nextEnd = function () { this.__Slider.style.transition = null; this.__Slider.append(this.__Slider.firstElementChild); this.__Slider.style.left = "-" + this.__WidthOneSlide + "px"; this.switchNavigationDot(); }; Slider.prototype.nextEndAlt = function () { this.__Slider.style.transition = null; this.__Slider.style.left = "-" + this.__WidthOneSlide + "px"; this.startSlider(); }; Slider.prototype.toggleSlide = function (element) { if (element) { var slide = element.closest(".slide"); if (slide) { if (slide.classList.contains("expand")) { slide.classList.remove("expand"); element.textContent = "Развернуть"; this.__NavigationDots.style.display = null; VKKO.Setting.UnblockScroll(); } else { slide.classList.add("expand"); element.textContent = "Свернуть"; this.__NavigationDots.style.display = "none"; VKKO.Setting.BlockScroll(); } } } }; Slider.prototype.Rebuild = function () { switch (VKKO.Setting.Platform) { case CLIENT_PLATFORM.DESKTOP: this.__WidthOneSlide = this.__CarouselRoot.getBoundingClientRect().width; break; case CLIENT_PLATFORM.TABLET: break; case CLIENT_PLATFORM.MOBILE: this.__WidthOneSlide = document.documentElement.clientWidth; break; default: this.__WidthOneSlide = this.__CarouselRoot.getBoundingClientRect().width; } this.__Slider.style.width = (this.__SlideCount * this.__WidthOneSlide) + "px"; this.__Slider.style.left = "-" + this.__WidthOneSlide + "px"; }; return Slider; }()); VKKO.Slider = Slider; })(VKKO || (VKKO = {})); var VKKOWork; (function (VKKOWork) { VKKOWork.NoticeSlider = null; })(VKKOWork || (VKKOWork = {})); var VKKO; (function (VKKO) { var Search; (function (Search) { function search() { } function Init(selector) { if (selector != null) { var inputSearch = document.querySelector(selector); if (inputSearch) { if (inputSearch.parentElement.nextElementSibling && inputSearch.parentElement.nextElementSibling.classList.contains("search-list")) { } inputSearch.oninput = search; } } } Search.Init = Init; })(Search = VKKO.Search || (VKKO.Search = {})); })(VKKO || (VKKO = {})); var VKKO; (function (VKKO) { var Main; (function (Main) { var __RootMenuItemOpen = false; function switchMenu(event) { if (this.classList.contains("open")) { this.classList.remove("open"); VKKO.Setting.UnblockScroll(); } else { this.classList.add("open"); VKKO.Setting.BlockScroll(); } } var __ResizeTimeout; var __LastClientPlatform; function resize(event) { clearTimeout(__ResizeTimeout); __ResizeTimeout = setTimeout(function () { if (document.documentElement.clientWidth > CLIENT_PLATFORM.MOBILE) { if (document.documentElement.clientWidth > CLIENT_PLATFORM.TABLET) { if (document.documentElement.clientWidth > CLIENT_PLATFORM.OLD_DESKTOP) { VKKO.Setting.Platform = CLIENT_PLATFORM.OLD_DESKTOP; } else { VKKO.Setting.Platform = CLIENT_PLATFORM.DESKTOP; } } else { VKKO.Setting.Platform = CLIENT_PLATFORM.TABLET; } } else { VKKO.Setting.Platform = CLIENT_PLATFORM.MOBILE; } }, 250); } function login(login, password) { var data = { Login: login.value, Password: password.value }; VKKOWork.XHR.POST(function (result) { if (result) { if (result.Error) { VKKOWork.Messenger.Show(result.Error); } else { VKKOWork.Messenger.Show("Привет, " + result.Name); window.location.reload(); } } else { VKKOWork.Messenger.Show("Сервер ничего не вернул :("); } }, "/login", data); this.closest(".modal").querySelector(".close").click(); } function Init() { resize(); setTimeout(window.FsLightbox, 250); setTimeout(function () { document.body.onresize = resize; }, 500); } Main.Init = Init; function SignIn() { var body = document.createElement("div"), inputLogin = document.createElement("input"), inputPass = document.createElement("input"), button = document.createElement("button"); var tabIndex = 1; inputLogin.type = "text"; inputLogin.placeholder = "Логин"; inputLogin.tabIndex = tabIndex++; inputPass.type = "password"; inputPass.placeholder = "Пароль"; inputPass.tabIndex = tabIndex++; inputPass.onkeypress = function (event) { if (event.keyCode == 13) { login.call(button, inputLogin, inputPass); } }; button.textContent = "Войти"; button.onclick = login.bind(button, inputLogin, inputPass); button.tabIndex = tabIndex++; body.append(inputLogin, inputPass, button); VKKO.Modal.Create("Авторизация", body); } Main.SignIn = SignIn; function SignOut() { VKKOWork.XHR.POST(function (data) { if (data.Error == null) { window.location.reload(); } }, "/logout"); } Main.SignOut = SignOut; })(Main = VKKO.Main || (VKKO.Main = {})); })(VKKO || (VKKO = {})); var VKKO; (function (VKKO) { var Tree = (function () { function Tree() { this.__Root = document.createElement("div"); this.__Root.classList.add("tree"); } Tree.prototype.onClickBranch = function (event) { if (this instanceof HTMLElement) { var root = this.closest(".tree"); var selected = root.querySelectorAll(".selected"); var thisParent_1 = this.parentElement; selected.forEach(function (value) { if (value !== thisParent_1) { value.classList.remove("selected"); } }); thisParent_1.classList.toggle("selected"); } }; Tree.prototype.AddBranch = function (caption, dataset, root) { var branch = document.createElement("div"), body = document.createElement("div"), head = document.createElement("div"); if (dataset) { for (var key in dataset) { if (dataset.hasOwnProperty(key)) { branch.dataset[key] = dataset[key]; } } } branch.classList.add("branch"); body.classList.add("body"); head.classList.add("head"); head.textContent = caption; head.onclick = this.onClickBranch; branch.append(head, body); if (root) { root.append(branch); } else { this.__Root.append(branch); } return body; }; Tree.prototype.CreateBranch = function (caption, dataset) { return this.AddBranch(caption, dataset).parentElement; }; Tree.prototype.InsertInto = function (index, caption, dataset, root) { if (!root) { root = this.__Root; } var l = root.children.length; for (var i = 0; i < l; i++) { var element = root.children[i]; if (element.classList.contains("branch")) { if (element.dataset.id && element.dataset.id === index.toString()) { if (element.children[1] && element.children[1].classList.contains("body")) { element.children[1].append(this.CreateBranch(caption, dataset)); return; } } else { if (element.children[1] && element.children[1].classList.contains("body")) { this.InsertInto(index, caption, dataset, element.children[1]); } } } } }; Tree.prototype.SetTo = function (element) { if (element) { while (element.children.length > 0) { element.children[0].remove(); } while (this.__Root.children.length > 0) { element.append(this.__Root.children[0]); } element.classList.add("tree"); } }; return Tree; }()); VKKO.Tree = Tree; })(VKKO || (VKKO = {})); var VKKO; (function (VKKO) { var MaterialEditor; (function (MaterialEditor) { var __CreateNewsButton = document.querySelector("#CreateNewsButton"); if (__CreateNewsButton) { __CreateNewsButton.onclick = openModal; } var __CreateNoticeButton = document.querySelector("#CreateNoticeButton"); if (__CreateNoticeButton) { __CreateNoticeButton.onclick = openModal; } var __CreateMaterialButton = document.querySelector("#CreateMaterialButton"); if (__CreateMaterialButton) { __CreateMaterialButton.onclick = openModal; } var __EditMaterialButton = document.querySelector("#EditMaterialButton"); if (__EditMaterialButton) { __EditMaterialButton.onclick = getMaterialSource; } var __DeleteMaterialButton = document.querySelector("#DeleteMaterialButton"); if (__DeleteMaterialButton) { __DeleteMaterialButton.onclick = deleteMaterial; } var __CurrentCategory = undefined; function deleteMaterial() { if (this.dataset.active == "true") { VKKOWork.XHR.POST(function () { }, "/material-delete/" + this.dataset.link); } else { VKKOWork.XHR.POST(function () { }, "/material-restore/" + this.dataset.link); } } function openModal() { switch (this.dataset.category) { case MATERIAL_CATEGORY.MATERIAL: __CurrentCategory = MATERIAL_CATEGORY.MATERIAL; break; case MATERIAL_CATEGORY.NEWS: __CurrentCategory = MATERIAL_CATEGORY.NEWS; break; case MATERIAL_CATEGORY.NOTICE: __CurrentCategory = MATERIAL_CATEGORY.NOTICE; break; default: return; } 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"); label.append(file, fileButton); label.className = "select-file"; fileButton.className = "button"; fileButton.textContent = "Выбрать изображениия"; file.type = "file"; if (__CurrentCategory === MATERIAL_CATEGORY.NOTICE) { file.multiple = false; } else { file.multiple = true; } file.accept = "image/*"; file.onchange = changeImages; inputCaption.type = "text"; inputCaption.placeholder = "Заголовок/название (обязательно)"; inputLink.type = "text"; inputLink.placeholder = "Ссылка на " + __CurrentCategory + " (не обязательно)"; buttonSend.textContent = "Создать"; preview.className = "preview-images"; contentBlock.id = "editorjs"; contentBlock.className = "content-editor"; if (__CurrentCategory !== MATERIAL_CATEGORY.MATERIAL) { body.append(inputCaption, inputLink, contentBlock, previewBlock, label, preview, buttonSend); } else { body.append(inputCaption, inputLink, contentBlock, previewBlock, buttonSend); } var tools = { header: { "class": Header, inlineToolbar: true, shortcut: "CMD+SHIFT+H" }, list: { "class": List, inlineToolbar: true, shortcut: "CMD+SHIFT+L" }, marker: { "class": Marker, shortcut: "CMD+SHIFT+M" }, delimiter: Delimiter, inlineCode: { "class": InlineCode, shortcut: "CMD+SHIFT+C" }, linkTool: LinkTool, code: CodeTool, table: { "class": Table, inlineToolbar: true, shortcut: "CMD+ALT+T" }, onReady: function () { console.log("ready"); }, onChange: function () { console.log("changed"); } }; if (__CurrentCategory === MATERIAL_CATEGORY.MATERIAL) { tools.image = { "class": SimpleImage, inlineCode: true }; tools.embed = { "class": Embed, inlineToolbar: false, config: { services: { youtube: true } } }; } var editor = new EditorJS({ holder: contentBlock, tools: tools, data: null }); buttonSend.addEventListener("click", function () { editor.save().then(function (savedData) { create.call(buttonSend, inputCaption, inputLink, savedData, preview, file); }); }); VKKO.Modal.Create("Создать " + __CurrentCategory, body); } function getMaterialSource() { VKKOWork.XHR.POST(openModalToEdit, "/material-get-source/" + this.dataset.link); } function openModalToEdit(data) { if (!__EditMaterialButton) { return; } var source = {}; try { source.Caption = data.Data.Caption; source.Category = data.Data.Category; source.Link = data.Data.Link; source.Source = JSON.parse(data.Data.Source); source.SourceImages = JSON.parse(data.Data.SourceImages); } catch (error) { VKKO.Utils.logError(error); VKKOWork.Messenger.Show("Ошибка загрузки исходных данных материала: " + error); return; } switch (source.Category) { case MATERIAL_CATEGORY.MATERIAL: __CurrentCategory = MATERIAL_CATEGORY.MATERIAL; break; case MATERIAL_CATEGORY.NEWS: __CurrentCategory = MATERIAL_CATEGORY.NEWS; break; case MATERIAL_CATEGORY.NOTICE: __CurrentCategory = MATERIAL_CATEGORY.NOTICE; break; default: VKKOWork.Messenger.Show("Неизвестная категория материала: " + source.Category); return; } 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"); inputCaption.type = "text"; inputCaption.placeholder = "Заголовок/название (обязательно)"; inputCaption.value = source.Caption; inputLink.disabled = true; inputLink.type = "text"; inputLink.value = source.Link; buttonSend.textContent = "Сохранить изменения"; preview.className = "preview-images"; contentBlock.id = "editorjs"; contentBlock.className = "content-editor"; createPreviewImagesFromSource(preview, source.SourceImages); if (__CurrentCategory !== MATERIAL_CATEGORY.MATERIAL) { body.append(inputCaption, inputLink, contentBlock, previewBlock, preview, buttonSend); } else { body.append(inputCaption, inputLink, contentBlock, previewBlock, buttonSend); } var tools = { header: { "class": Header, inlineToolbar: true, shortcut: "CMD+SHIFT+H" }, list: { "class": List, inlineToolbar: true, shortcut: "CMD+SHIFT+L" }, marker: { "class": Marker, shortcut: "CMD+SHIFT+M" }, delimiter: Delimiter, inlineCode: { "class": InlineCode, shortcut: "CMD+SHIFT+C" }, linkTool: LinkTool, table: { "class": Table, inlineToolbar: true, shortcut: "CMD+ALT+T" }, onReady: function () { console.log("ready"); }, onChange: function () { console.log("changed"); } }; if (__CurrentCategory === MATERIAL_CATEGORY.MATERIAL) { tools.image = { "class": SimpleImage, inlineCode: true }; tools.embed = { "class": Embed, inlineToolbar: false, config: { services: { youtube: true } } }; } var editor = new EditorJS({ holder: contentBlock, tools: tools, data: JSON.parse(data.Data.Source) }); buttonSend.addEventListener("click", function () { editor.save().then(function (savedData) { update.call(buttonSend, inputCaption, inputLink, savedData, preview, source.SourceImages); }); }); VKKO.Modal.Create("Редактировать " + __CurrentCategory, body); } function changeImages() { var preview = document.querySelector(".preview-images"); if (!preview) { VKKO.Utils.logWarning("Элемент [.preview-images] не найден"); return; } for (var _i = 0, _a = this.files; _i < _a.length; _i++) { var file = _a[_i]; var div = document.createElement("div"); div.className = "image"; var img = document.createElement("img"); img.src = window.URL.createObjectURL(file); img.alt = file.name; img.height = 100; var label = document.createElement("label"); var input = document.createElement("input"); input.type = "radio"; input.dataset.image = file.name; input.name = "preview-images"; var span = document.createElement("span"); div.append(img, label); label.append(input, span); preview.append(div); } var firstImage = preview.querySelector("input"); firstImage.click(); } function dataURIToBlob(dataURI) { var splitDataURI = dataURI.split(","); var byteString = splitDataURI[0].indexOf("base64") >= 0 ? atob(splitDataURI[1]) : decodeURI(splitDataURI[1]); var mimeString = splitDataURI[0].split(":")[1].split(";")[0]; var ia = new Uint8Array(byteString.length); for (var i = 0; i < byteString.length; i++) ia[i] = byteString.charCodeAt(i); return new Blob([ia], { type: mimeString }); } function createPreviewImagesFromSource(element, source) { for (var _i = 0, source_1 = source; _i < source_1.length; _i++) { var file = source_1[_i]; var div = document.createElement("div"); div.className = "image"; var img = document.createElement("img"); img.src = file.Thumb; img.height = 100; element.append(div); } } function create(caption, link, content, images, file) { if (!caption || !link || !content || !images) { VKKOWork.Messenger.Show("Некоторые элементы не были найдены, невозможно создать новость!"); return; } if (caption.value.length == 0) { VKKOWork.Messenger.Show("Необходимо заполнить заголовок!"); return; } if (link.value.length == 0) { link.value = VKKO.Utils.GenerateHash256(); } var preview = { Valid: "true", String: "" }; var date = new Date(); var m = ("00" + (date.getMonth() + 1)).slice(-2); var d = ("00" + date.getDate()).slice(-2); var imageFullpath = "image/" + __CurrentCategory + "/" + date.getUTCFullYear().toString() + "-" + m + "-" + d + "/"; var thumbFullpath = "thumb/" + __CurrentCategory + "/" + date.getUTCFullYear().toString() + "-" + m + "-" + m + "/"; var data = new FormData(); var contentHtml = ""; for (var _i = 0, _a = content.blocks; _i < _a.length; _i++) { var c = _a[_i]; switch (c.type) { case "paragraph": contentHtml += "

" + c.data.text + "

"; preview.String += c.data.text; break; case "header": contentHtml += "" + c.data.text + ""; preview.String += c.data.text; break; case "list": if (c.data.style === "ordered") { contentHtml += "
    "; for (var _b = 0, _c = c.data.items; _b < _c.length; _b++) { var li = _c[_b]; contentHtml += "
  1. " + li + "
  2. "; preview.String += li; } contentHtml += "
"; } else { contentHtml += ""; } break; case "delimiter": contentHtml += "
"; break; case "table": contentHtml += ""; for (var _f = 0, _g = c.data.content; _f < _g.length; _f++) { var row = _g[_f]; contentHtml += ""; for (var _h = 0, row_1 = row; _h < row_1.length; _h++) { var col = row_1[_h]; contentHtml += ""; preview.String += col; } contentHtml += ""; } contentHtml += "
" + col + "
"; break; case "image": var filename = VKKO.Utils.GenerateHashDashed(2) + "." + c.data.url.slice(11, c.data.url.indexOf(";")); contentHtml += ''; var div = document.createElement("div"); div.innerHTML = c.data.caption; if (div.textContent.length > 0) { contentHtml += '
' + c.data.caption + "
"; } data.append("Files", dataURIToBlob(c.data.url), filename); break; case "embed": contentHtml += ''; var youtubeCaption = document.createElement("div"); youtubeCaption.innerHTML = c.data.caption; if (youtubeCaption.textContent.length > 0) { contentHtml += '
' + c.data.caption + "
"; } break; } } var clearTags = document.createElement("div"); clearTags.innerHTML = preview.String; preview.String = clearTags.textContent; if (preview.String.length > 260) { preview.String = preview.String.slice(0, 260); } var selectedImage = { Valid: "false", String: "" }; var sourceImages = []; if (__CurrentCategory != MATERIAL_CATEGORY.MATERIAL) { var selectedImageName = ";"; var selectedInput = images.querySelector("input:checked"); if (selectedInput) { var img = selectedInput.closest(".image").querySelector("img"); if (img) { selectedImageName = img.alt; selectedImage.String = thumbFullpath + selectedImageName.toLowerCase(); selectedImage.Valid = "true"; } } if (file.files.length > 0) { if (__CurrentCategory != MATERIAL_CATEGORY.NOTICE) { contentHtml += '
'; } for (var i = 0; i < file.files.length; i++) { var f = file.files.item(i); var filename = f.name.toLowerCase(); filename = VKKO.Utils.GenerateHashDashed(2) + filename.slice(filename.lastIndexOf(".")); if (selectedImageName === f.name) { selectedImage.String = thumbFullpath + filename; } if (__CurrentCategory != MATERIAL_CATEGORY.NOTICE) { contentHtml += '' +
                                    filename +
                                    ''; } data.append("Files", f, filename); sourceImages.push({ Image: "/" + imageFullpath + filename, Thumb: "/" + thumbFullpath + filename }); } if (__CurrentCategory != MATERIAL_CATEGORY.NOTICE) { contentHtml += "
"; } } } data.set("Caption", caption.value); data.set("Link", link.value); data.set("Content", contentHtml); data.set("Source", JSON.stringify(content)); data.set("SourceImages", JSON.stringify(sourceImages)); data.set("PreviewValid", preview.Valid); data.set("PreviewString", preview.String); data.set("ImageValid", selectedImage.Valid); data.set("ImageString", selectedImage.String); data.set("ImagePath", imageFullpath); data.set("ThumbPath", thumbFullpath); var closeModal = this.closest(".modal").querySelector(".close"); VKKOWork.XHR.POST(function (result) { if (result && "Error" in result) { if (result.Error === null) { VKKOWork.Messenger.Show(__CurrentCategory + " успешно добавлена"); closeModal.click(); } else { VKKOWork.Messenger.Show("Возникла ошибка добавления новости." + result.Error); } } }, "/material-insert/" + __CurrentCategory, data, null, true, true); } function update(caption, link, content, images, source) { if (!caption || !link || !content || !images) { VKKOWork.Messenger.Show("Некоторые элементы не были найдены, невозможно создать новость!"); return; } if (caption.value.length == 0) { VKKOWork.Messenger.Show("Необходимо заполнить заголовок!"); return; } if (link.value.length == 0) { link.value = VKKO.Utils.GenerateHash256(); } var preview = { Valid: "true", String: "" }; var date = new Date(); var m = ("00" + (date.getMonth() + 1)).slice(-2); var d = ("00" + date.getDate()).slice(-2); var imageFullpath = ""; var thumbFullpath = ""; if (__CurrentCategory != MATERIAL_CATEGORY.MATERIAL) { if (source.length > 0) { imageFullpath = source[0].Image.slice(1, source[0].Image.lastIndexOf("/") + 1); thumbFullpath = source[0].Thumb.slice(1, source[0].Thumb.lastIndexOf("/") + 1); } } else { imageFullpath = "image/" + __CurrentCategory + "/" + date.getUTCFullYear().toString() + "-" + m + "-" + d + "/"; thumbFullpath = "thumb/" + __CurrentCategory + "/" + date.getUTCFullYear().toString() + "-" + m + "-" + m + "/"; } var data = new FormData(); var contentHtml = ""; for (var _i = 0, _a = content.blocks; _i < _a.length; _i++) { var c = _a[_i]; switch (c.type) { case "paragraph": contentHtml += "

" + c.data.text + "

"; preview.String += c.data.text; break; case "header": contentHtml += "" + c.data.text + ""; preview.String += c.data.text; break; case "list": if (c.data.style === "ordered") { contentHtml += "
    "; for (var _b = 0, _c = c.data.items; _b < _c.length; _b++) { var li = _c[_b]; contentHtml += "
  1. " + li + "
  2. "; preview.String += li; } contentHtml += "
"; } else { contentHtml += ""; } break; case "delimiter": contentHtml += "
"; break; case "table": contentHtml += ""; for (var _f = 0, _g = c.data.content; _f < _g.length; _f++) { var row = _g[_f]; contentHtml += ""; for (var _h = 0, row_2 = row; _h < row_2.length; _h++) { var col = row_2[_h]; contentHtml += ""; preview.String += col; } contentHtml += ""; } contentHtml += "
" + col + "
"; break; case "image": var filename = VKKO.Utils.GenerateHashDashed(2) + "." + c.data.url.slice(11, c.data.url.indexOf(";")); contentHtml += ''; var div = document.createElement("div"); div.innerHTML = c.data.caption; if (div.textContent.length > 0) { contentHtml += '
' + c.data.caption + "
"; } data.append("Files", dataURIToBlob(c.data.url), filename); break; case "embed": contentHtml += ''; var youtubeCaption = document.createElement("div"); youtubeCaption.innerHTML = c.data.caption; if (youtubeCaption.textContent.length > 0) { contentHtml += '
' + c.data.caption + "
"; } break; } } var clearTags = document.createElement("div"); clearTags.innerHTML = preview.String; preview.String = clearTags.textContent; if (preview.String.length > 260) { preview.String = preview.String.slice(0, 260); } if (__CurrentCategory != MATERIAL_CATEGORY.MATERIAL) { if (source.length > 0) { if (__CurrentCategory != MATERIAL_CATEGORY.NOTICE) { contentHtml += '
'; } for (var i = 0; i < source.length; i++) { if (__CurrentCategory != MATERIAL_CATEGORY.NOTICE) { contentHtml += '' +
                                    source[i].Image.slice(source[i].Image.lastIndexOf('; } } if (__CurrentCategory != MATERIAL_CATEGORY.NOTICE) { contentHtml += "
"; } } } data.set("Link", __EditMaterialButton.dataset.link); data.set("Caption", caption.value); data.set("Content", contentHtml); data.set("Source", JSON.stringify(content)); data.set("PreviewValid", preview.Valid); data.set("PreviewString", preview.String); data.set("ImagePath", imageFullpath); data.set("ThumbPath", thumbFullpath); var closeModal = this.closest(".modal").querySelector(".close"); VKKOWork.XHR.POST(function (result) { if (result && "Error" in result) { if (result.Error === null) { VKKOWork.Messenger.Show(__CurrentCategory + " успешно добавлена"); closeModal.click(); } else { VKKOWork.Messenger.Show("Возникла ошибка добавления новости." + result.Error); } } }, "/material-update/" + __CurrentCategory, data, null, true, true); } })(MaterialEditor = VKKO.MaterialEditor || (VKKO.MaterialEditor = {})); })(VKKO || (VKKO = {})); var VKKO;