/** * @file siteSettings.js * @brief Основной файл siteSettings, открытие плагинов */ addEventListener("load", function() { let menu = document.getElementById('siteSettings'); let button = document.getElementById('siteSettingsButton'); menu.onclick = function() { menu.style.display = 'none'; }; function hbodyHref() { let hbody = document.getElementById('hbody'); let links = hbody.querySelectorAll('a[href]'); links.forEach(link => { let originalHref = link.getAttribute('href'); link.removeAttribute('href'); link.onclick = function(event) { event.preventDefault(); hbodyHrefFunction(originalHref); }; }); } async function hbodyHrefFunction(href) { if (document.getElementById('basis3')?.style.visibility === "visible" && window.contentIsEdit == true) { messageQueue.push("{{save_data_question}}"); try { const userConfirmed = await messageCreateQuestion(); if (userConfirmed) { if (window.newPageFunValue == "newPage") { document.getElementById("saveHow").click(); messageFunction("{{save_new_page}}"); return; } else { await saveChanges(); } } } catch (error) { console.log("Ошибка: ", error); } } window.location.href = href; } hbodyHref(); }); /** * @brief Подключает или отключает плагин по ID * @param id ID элемента DOM * @param plugin Название плагина * @param fnName Имя функции инициализации */ async function togglePlugin(id, plugin, fnName) { const exists = !!document.getElementById(id); if (exists) { if (plugin === 'editor') await removePluginDom('pickr'); if (typeof window[fnName] === 'function') window[fnName](); await removePluginDom(plugin); } else { await includePlugin(plugin); await new Promise(res => { const i = setInterval(() => { if (typeof window[fnName] === 'function') { clearInterval(i); window[fnName](); res(); } }); }); if (plugin === 'editor') await includePlugin('pickr'); } } /** @brief Переключает редактор */ function toggleEditor() { return togglePlugin("basis3", "editor", "basisVis"); } /** @brief Переключает дерево сайта */ function toggleSiteTree() { return togglePlugin("treeDiv", "site_tree", "basisVisSiteTree"); } /** @brief Переключает менеджер */ function toggleManager() { return togglePlugin("managerDiv", "manager", "basisVisManager"); }