调整目录结构

This commit is contained in:
fofolee 2020-06-06 09:17:28 +08:00
parent 8e21418bec
commit e6523d6233
13 changed files with 46 additions and 39 deletions

View File

@ -8,7 +8,7 @@ escapeHtml = s => {
// 显示列表 // 显示列表
showList = (text, index, listnum) => { showList = (text, index, listnum) => {
window.infoRows = []; window.manualVars.infoRows = [];
var topRows = [], var topRows = [],
tailRows = []; tailRows = [];
if(text) text = text.toUpperCase() if(text) text = text.toUpperCase()
@ -36,15 +36,15 @@ showList = (text, index, listnum) => {
// 排序规则:置顶全字匹配,优先显示名称匹配 // 排序规则:置顶全字匹配,优先显示名称匹配
topRow && ((upName == text) && topRows.unshift(list) || topRows.push(list)) || (matched && tailRows.push(list)); topRow && ((upName == text) && topRows.unshift(list) || topRows.push(list)) || (matched && tailRows.push(list));
}); });
window.infoRows = topRows.concat(tailRows); window.manualVars.infoRows = topRows.concat(tailRows);
$("#mainlist").html(window.infoRows.slice(0, listnum).join('')); $("#mainlist").html(window.manualVars.infoRows.slice(0, listnum).join(''));
let num = $(".info").length let num = $(".info").length
utools.setExpendHeight(num > 11 ? 550 : 50 * num); utools.setExpendHeight(num > 11 ? 550 : 50 * num);
$(".select").removeClass('select'); $(".select").removeClass('select');
$(".info:first").addClass('select'); $(".info:first").addClass('select');
$('html').getNiceScroll().resize(); $('html').getNiceScroll().resize();
// 鼠标锁,方式鼠标抢占选择条 // 鼠标锁,方式鼠标抢占选择条
window.mouseLockTime = new Date().getTime(); window.manualVars.mouseLockTime = new Date().getTime();
} }
// 列表界面子输入框 // 列表界面子输入框
@ -80,9 +80,9 @@ showManual = path => {
var f = e[1] + '.html'; var f = e[1] + '.html';
var id = '#' + e[3]; var id = '#' + e[3];
} else { } else {
var f = window.dirs.idxFile ? path : path + '.html'; var f = window.manualVars.dirs.idxFile ? path : path + '.html';
} }
var file = `${window.dirs.docPath}/${f}`; var file = `${window.manualVars.dirs.docPath}/${f}`;
$("#mainlist").fadeOut(); $("#mainlist").fadeOut();
$(".load").html('Loading').show(); $(".load").html('Loading').show();
var request = $.ajax({ var request = $.ajax({
@ -96,7 +96,8 @@ showManual = path => {
data = data.replace(/(a.*?)href="(?!http)([^\#].*?)"/g, `$1href="${relPath}$2"`); data = data.replace(/(a.*?)href="(?!http)([^\#].*?)"/g, `$1href="${relPath}$2"`);
// devdocs 语法高亮 // devdocs 语法高亮
data = data.replace(/<pre.*?data-language="(.*?)">([\s\S]*?)<\/pre>/g, '<pre><code class="language-$1">$2</code></pre>') data = data.replace(/<pre.*?data-language="(.*?)">([\s\S]*?)<\/pre>/g, '<pre><code class="language-$1">$2</code></pre>')
$("#manual").html(`<div id="manualBody">${data}</div>`).fadeIn(); $("#manualBody").html(data)
$("#manual").fadeIn()
Prism.highlightAll(); Prism.highlightAll();
location.href = e ? id : '#manualBody'; location.href = e ? id : '#manualBody';
manualSubInput(); manualSubInput();
@ -113,7 +114,7 @@ highlightManual = (selector, text) => {
$(selector).removeHighlight('founds') ; $(selector).removeHighlight('founds') ;
if (text) { if (text) {
$(selector).highlight(text, 'founds'); $(selector).highlight(text, 'founds');
window.findex = 0; window.manualVars.findex = 0;
} }
} }
@ -153,10 +154,10 @@ toggleView = () => {
// 继续加载内容 // 继续加载内容
loadList = addnum => { loadList = addnum => {
if ($('#manual').is(':hidden') && $("#mainlist").is(":visible") && window.infoRows) { if ($('#manual').is(':hidden') && $("#mainlist").is(":visible") && window.manualVars.infoRows) {
var listnum = $(".info").length; var listnum = $(".info").length;
if ($(window).scrollTop() >= (listnum * 50 - 550)) { if ($(window).scrollTop() >= (listnum * 50 - 550)) {
$("#mainlist").append(window.infoRows.slice(listnum, listnum + addnum).join('')); $("#mainlist").append(window.manualVars.infoRows.slice(listnum, listnum + addnum).join(''));
$('html').getNiceScroll().resize(); $('html').getNiceScroll().resize();
} }
} }
@ -166,8 +167,9 @@ loadList = addnum => {
utools.onPluginEnter( async ({ code, type, payload }) => { utools.onPluginEnter( async ({ code, type, payload }) => {
scrollInit(); scrollInit();
// checkUpdate(); // checkUpdate();
window.manualVars = {}
if (code == 'options') { if (code == 'options') {
window.defaultPage = 0; window.manualVars.defaultPage = 0;
showOptions(); showOptions();
utools.setSubInput(({ text }) => { utools.setSubInput(({ text }) => {
highlightManual(".keyword", text); highlightManual(".keyword", text);
@ -175,7 +177,7 @@ utools.onPluginEnter( async ({ code, type, payload }) => {
} else if (code == 'dash') { } else if (code == 'dash') {
utools.setExpendHeight(0); utools.setExpendHeight(0);
utools.setSubInput(({ text }) => { utools.setSubInput(({ text }) => {
window.dashQuery = text; window.manualVars.dashQuery = text;
}, '输入关键词进行查询,例如 nodejs:fs'); }, '输入关键词进行查询,例如 nodejs:fs');
} else { } else {
$("#mainlist").fadeIn(); $("#mainlist").fadeIn();
@ -185,8 +187,8 @@ utools.onPluginEnter( async ({ code, type, payload }) => {
switch (allFts[code].type) { switch (allFts[code].type) {
case "default": case "default":
baseDir = dirname; baseDir = dirname;
assetDir = `${baseDir}/assets/${code}` assetDir = `${baseDir}/assets/styles/${code}`
window.dirs = { window.manualVars.dirs = {
idxFile: `${baseDir}/index/${code}.json`, idxFile: `${baseDir}/index/${code}.json`,
docPath: `${baseDir}/docs`, docPath: `${baseDir}/docs`,
} }
@ -194,14 +196,14 @@ utools.onPluginEnter( async ({ code, type, payload }) => {
case "custom": case "custom":
baseDir = allFts[code].path; baseDir = allFts[code].path;
assetDir = `${baseDir}/assets` assetDir = `${baseDir}/assets`
window.dirs = { window.manualVars.dirs = {
idxFile: `${baseDir}/${code}.json`, idxFile: `${baseDir}/${code}.json`,
docPath: `${baseDir}`, docPath: `${baseDir}`,
} }
break; break;
case "devdocs": case "devdocs":
assetDir = ''; assetDir = '';
window.dirs = { window.manualVars.dirs = {
docPath: allFts[code].url.slice(0, -11), docPath: allFts[code].url.slice(0, -11),
} }
break; break;
@ -213,14 +215,14 @@ utools.onPluginEnter( async ({ code, type, payload }) => {
$('head').append(`<link rel="stylesheet" href="${assetDir}/${file}" name="manual">`) $('head').append(`<link rel="stylesheet" href="${assetDir}/${file}" name="manual">`)
}) })
} else { } else {
$('head').append('<link rel="stylesheet" href="assets/manual.css" name="manual">') $('head').append('<link rel="stylesheet" href="assets/styles/manual.css" name="manual">')
} }
}) })
// 读取目录文件 // 读取目录文件
try { try {
if (window.dirs.idxFile) { if (window.manualVars.dirs.idxFile) {
index = await readFile(window.dirs.idxFile); index = await readFile(window.manualVars.dirs.idxFile);
if (window.dirs.idxFile.includes('payload.json')) { if (window.manualVars.dirs.idxFile.includes('payload.json')) {
index = JSON.parse(rc4(index, 'uTools')) index = JSON.parse(rc4(index, 'uTools'))
} else { } else {
index = JSON.parse(index); index = JSON.parse(index);
@ -256,7 +258,9 @@ utools.onPluginEnter( async ({ code, type, payload }) => {
utools.onPluginOut(() => { utools.onPluginOut(() => {
$("#mainlist").html('').hide(); $("#mainlist").html('').hide();
$("#options").html('').hide(); $("#options").html('').hide();
$("#manual").html('').hide(); $("#manual").hide();
$("#manualBody").html('')
$("#manualNavi").html('')
$(".load").html('').hide(); $(".load").html('').hide();
$("#infopannel").html('').hide();; $("#infopannel").html('').hide();;
$('link[name="manual"]').remove(); $('link[name="manual"]').remove();
@ -278,7 +282,7 @@ $("#mainlist").on('mousedown', '.info', function (e) {
$("#mainlist").on('mousemove', '.info', function () { $("#mainlist").on('mousemove', '.info', function () {
// 鼠标锁 500ms // 鼠标锁 500ms
var mouseUnlockTime = new Date().getTime(); var mouseUnlockTime = new Date().getTime();
if (mouseUnlockTime - window.mouseLockTime > 500) { if (mouseUnlockTime - window.manualVars.mouseLockTime > 500) {
$(".select").removeClass('select'); $(".select").removeClass('select');
$(this).addClass('select'); $(this).addClass('select');
} }
@ -334,21 +338,21 @@ $(document).keydown(e => {
path && showManual(path); path && showManual(path);
// 手册/配置界面搜索下一个 // 手册/配置界面搜索下一个
} else if($('.founds').length){ } else if($('.founds').length){
if (window.findex > 0) { if (window.manualVars.findex > 0) {
$(`.founds:eq(${window.findex - 1})`).removeClass('firstFound'); $(`.founds:eq(${window.manualVars.findex - 1})`).removeClass('firstFound');
} else { } else {
$('.founds:last').removeClass('firstFound'); $('.founds:last').removeClass('firstFound');
} }
$(`.founds:eq(${window.findex})`).addClass('firstFound'); $(`.founds:eq(${window.manualVars.findex})`).addClass('firstFound');
$('.firstFound').get(0).scrollIntoView({ behavior: "smooth", block: "center" }); $('.firstFound').get(0).scrollIntoView({ behavior: "smooth", block: "center" });
if (window.findex == $('.founds').length - 1) { if (window.manualVars.findex == $('.founds').length - 1) {
window.findex = 0; window.manualVars.findex = 0;
} else { } else {
window.findex += 1; window.manualVars.findex += 1;
} }
// 快速启动 dash // 快速启动 dash
} else if (window.dashQuery) { } else if (window.manualVars.dashQuery) {
window.dash(window.dashQuery); window.dash(window.manualVars.dashQuery);
} }
break; break;
// 上 // 上

View File

@ -5,20 +5,23 @@
<meta charset="utf8"> <meta charset="utf8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge"> <meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="assets/style.css"> <link rel="stylesheet" href="assets/styles/style.css">
<link rel="stylesheet" href="assets/options.css"> <link rel="stylesheet" href="assets/styles/options.css">
<link rel="stylesheet" href="assets/prism.css"> <link rel="stylesheet" href="assets/styles/prism.css">
<script src="assets/jquery-3.3.1.min.js"></script> <script src="assets/plugins/jquery-3.3.1.min.js"></script>
<script src="assets/hlsearch.js"></script> <script src="assets/plugins/hlsearch.js"></script>
<script src="assets/jquery.nicescroll.min.js"></script> <script src="assets/plugins/jquery.nicescroll.min.js"></script>
<script src="assets/prism.js"></script> <script src="assets/plugins/prism.js"></script>
<script src="assets/sweetalert2.all.min.js"></script> <script src="assets/plugins/sweetalert2.all.min.js"></script>
<title>Manuals</title> <title>Manuals</title>
</head> </head>
<body> <body>
<div id="mainlist"></div> <div id="mainlist"></div>
<div id="manual"></div> <div id="manual">
<div id="manualNavi"></div>
<div id="manualBody"></div>
</div>
<div id="options"></div> <div id="options"></div>
<div id="infopannel"></div> <div id="infopannel"></div>
<div class="load"></div> <div class="load"></div>