Реализовано открытие и закрытие вкладок на нажатие трех полосок, добавлена вкладка структуры страницы с возможностью вставки плагинов, подключена библиотека MarkedJS, исправлены баги, управление центральными блоками через CDATA.
This commit is contained in:
@@ -32,6 +32,7 @@ window.touchY = 0;
|
||||
* @return Promise Разрешается после загрузки всех скриптов плагина
|
||||
*/
|
||||
function includePlugin(plugin) {
|
||||
console.log(plugin)
|
||||
return jsonrpcRequest("includePlugin", { plugin })
|
||||
.then(html => {
|
||||
const div = document.createElement('div');
|
||||
@@ -737,39 +738,82 @@ let cou=1;
|
||||
/**
|
||||
* @brief Показать/скрыть HTML-код страницы в textarea
|
||||
*/
|
||||
function showHtmlCode() {
|
||||
let contents = document.getElementsByClassName("content");
|
||||
if (cou==1) {
|
||||
let combined = "";
|
||||
for (let i=0; i<contents.length; i++) combined += "<![CDATA[" + contents[i].innerHTML + "]]>";
|
||||
document.getElementById("tex").value = combined;
|
||||
document.getElementById("tex").value = decodeHtmlEntities(document.getElementById("tex").value);
|
||||
document.getElementById("tex").value = formatHTML(document.getElementById("tex").value);
|
||||
let sbe=document.getElementsByClassName("sb");
|
||||
for(let i=0; i<sbe.length; i++) {
|
||||
if (sbe[i] != document.getElementById("tex"))
|
||||
sbe[i].style.visibility="hidden";
|
||||
}
|
||||
if (document.getElementById("tex").style.visibility=="hidden") {
|
||||
document.getElementById("tex").style.visibility="visible";
|
||||
} else {
|
||||
document.getElementById("tex").style.visibility="hidden";
|
||||
}
|
||||
cou=2;
|
||||
} else {
|
||||
let text = document.getElementById("tex").value;
|
||||
let split = text.match(/<!\[CDATA\[(.*?)\]\]>/gs);
|
||||
if (split) {
|
||||
for (let i=0; i<contents.length; i++) {
|
||||
if (split[i]) contents[i].innerHTML = split[i].replace(/<!\[CDATA\[|\]\]>/g, '');
|
||||
}
|
||||
}
|
||||
document.getElementById("tex").style.visibility="hidden";
|
||||
cou=1;
|
||||
}
|
||||
let lastType = 'html';
|
||||
function showCode(type) {
|
||||
let contents = document.getElementsByClassName("content");
|
||||
let tex = document.getElementById("tex");
|
||||
if (cou == 1) {
|
||||
let combined = "";
|
||||
for (let i = 0; i < contents.length; i++) {
|
||||
combined += "<![CDATA[" + contents[i].innerHTML + "]]>";
|
||||
}
|
||||
tex.value = combined;
|
||||
tex.value = decodeHtmlEntities(tex.value);
|
||||
if (type === 'html') {
|
||||
tex.value = formatHTML(tex.value);
|
||||
} else if (type === 'marked') {
|
||||
tex.value = marked.parse(tex.value);
|
||||
}
|
||||
let sbe = document.getElementsByClassName("sb");
|
||||
for (let i = 0; i < sbe.length; i++) {
|
||||
if (sbe[i] != tex) sbe[i].style.visibility = "hidden";
|
||||
}
|
||||
tex.style.visibility = tex.style.visibility == "hidden" ? "visible" : "hidden";
|
||||
lastType = type;
|
||||
cou = 2;
|
||||
} else {
|
||||
let text = tex.value;
|
||||
let split = text.match(/<!\[CDATA\[(.*?)\]\]>/gs);
|
||||
const centerFloat = document.querySelector('.center-float');
|
||||
if (!centerFloat) return;
|
||||
let need = split ? split.length : 1;
|
||||
let floats = centerFloat.getElementsByClassName('bfloat');
|
||||
while (floats.length < need) {
|
||||
let bf = document.createElement('div');
|
||||
bf.className = 'bfloat';
|
||||
if (floats.length > 0) bf.style.borderRadius = "10px";
|
||||
let c = document.createElement('div');
|
||||
c.className = 'content';
|
||||
c.contentEditable = 'true';
|
||||
centerFloat.appendChild(bf);
|
||||
bf.appendChild(c);
|
||||
centerFloat.appendChild(document.createElement('br'));
|
||||
floats = centerFloat.getElementsByClassName('bfloat');
|
||||
}
|
||||
while (floats.length > need) {
|
||||
let next = floats[floats.length - 1].nextSibling;
|
||||
if (next && next.tagName === 'BR') centerFloat.removeChild(next);
|
||||
centerFloat.removeChild(floats[floats.length - 1]);
|
||||
floats = centerFloat.getElementsByClassName('bfloat');
|
||||
}
|
||||
contents = centerFloat.getElementsByClassName("content");
|
||||
if (split) {
|
||||
for (let i = 0; i < need; i++) {
|
||||
let val = split[i] ? split[i].replace(/<!\[CDATA\[|\]\]>/g, '') : '';
|
||||
if (lastType === 'marked') val = '<div>' + marked.parse(val.replace(/^\s*<div[^>]*>|<\/div>\s*$/g, '')) + '</div>';
|
||||
contents[i].innerHTML = val;
|
||||
}
|
||||
} else {
|
||||
let val = text;
|
||||
if (lastType === 'marked') val = '<div>' + marked.parse(val.replace(/^\s*<div[^>]*>|<\/div>\s*$/g, '')) + '</div>';
|
||||
contents[0].innerHTML = val;
|
||||
}
|
||||
let children = Array.from(centerFloat.children);
|
||||
for (let i = 0; i < children.length - 1; i++) {
|
||||
let current = children[i];
|
||||
let next = children[i + 1];
|
||||
if (current.id !== 'mainTitle' && current.classList.contains('bfloat')) {
|
||||
if (!(next && next.tagName === 'BR')) {
|
||||
let br = document.createElement('br');
|
||||
centerFloat.insertBefore(br, next);
|
||||
}
|
||||
}
|
||||
}
|
||||
tex.style.visibility = "hidden";
|
||||
cou = 1;
|
||||
}
|
||||
}
|
||||
|
||||
window.showHtmlCode = showHtmlCode;
|
||||
window.showCode = showCode;
|
||||
|
||||
/** @brief Флаг нового состояния страницы при сохранении */
|
||||
window.newPageFunValue = "";
|
||||
@@ -1348,8 +1392,10 @@ function getPage(newPath) {
|
||||
centerFloat.insertBefore(br, placeholder);
|
||||
}
|
||||
const block = document.createElement('div');
|
||||
block.className = 'bfloat' + (i === 0 ? ' content1' : '');
|
||||
block.className = 'bfloat';
|
||||
block.style.fontSize = '1em';
|
||||
if (i !== 0) block.style.borderRadius = '10px';
|
||||
|
||||
const inner = document.createElement('div');
|
||||
inner.className = 'content';
|
||||
inner.innerHTML = c;
|
||||
|
||||
Reference in New Issue
Block a user