Skip to content

Commit

Permalink
拆分 JavaScript 文件
Browse files Browse the repository at this point in the history
  • Loading branch information
Frost-ZX committed Sep 9, 2020
1 parent 86b2572 commit 0faebe0
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 180 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@

### 自定义

- [下载](https://github.com/Frost-ZX/frost-navigation/archive/master.zip) 后打开 `index.html``js/script.js` 根据需要进行修改。
- 修改完毕后,请根据需要在 `index.html` 中把 `<script src="js/index.min.js"></script>` 改为 `<script src="js/index.js"></script>` 或把 `js/script.js` 压缩为 `js/script.min.js`
- [下载](https://github.com/Frost-ZX/frost-navigation/archive/master.zip) 后打开 `index.html``assets/js/nav-links.js` 根据需要进行修改。

## 第三方资源

Expand Down
19 changes: 19 additions & 0 deletions assets/js/nav-functions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 查找字符 tChar 在 str 中第 num 次出现的位置

function findChar(str, tChar, num) {
var charPos = str.indexOf(tChar);
num = num - 1;
if (num > 0) {
for (var i = 0; i < num; i++) {
charPos = str.indexOf(tChar, charPos + 1);
}
}
return charPos;
}

// 返回顶部

function toTop() {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
}
65 changes: 0 additions & 65 deletions assets/js/nav-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,6 @@
/* 变量 */
/* ---- */

// Slinky 插件的设置 //
var SlinkyOption = {
title: true,
speed: 200
};

var ListID = "#list_"; // 列表 ID 前缀
var ListCount = 0;
var ListCountMax = 17; // 列表总数
var FullsSreenText = document.querySelector(".fullscreen-text"); // 全屏文字

// main 中的 A 标签的对象的集合(链接列表)//
var LinkList = document.querySelectorAll("main a");

Expand All @@ -38,60 +27,6 @@ var ToolPanel = document.querySelector(".tool-panel");
/* 函数 */
/* ---- */

// 查找字符 tChar 在 str 中第 num 次出现的位置 //
function findChar(str, tChar, num) {
var charPos = str.indexOf(tChar);
num = num - 1;
if (num > 0) {
for (var i = 0; i < num; i++) {
charPos = str.indexOf(tChar, charPos + 1);
}
}
return charPos;
}

/* 链接列表 */

// 设置 target = "_blank" //
function setTarget() {
for (var i = 0; i < LinkList.length; i++) {
if (LinkList[i].href.endsWith("#") == false) {
LinkList[i].target = "_blank";
/* 自动加图标(暂不使用)
var slashPos = findChar(LinkList[i].href, '/', 3);
getFavicon = "https://www.google.cn/s2/favicons?domain=" + LinkList[i].href.substring(0, slashPos);
var imgTag = "<img src='" + getFavicon + "' />";
LinkList[i].insertAdjacentHTML("beforeBegin", imgTag);
*/
}
}
}

// 显示列表 //
function displayList() {
document.querySelector("main").style.opacity = "1";
FullsSreenText.style.opacity = "0";
setTimeout(function () {
document.querySelector(".fullscreen-text").style.display = "none";
}, 1000);
}

// 加载列表 //
function loadList() {
ListCount = ListCount + 1;
ListID = "#list_" + ListCount;
$(ListID).slinky(SlinkyOption);
FullsSreenText.innerHTML = "已加载 " + ListCount + " 个分类"; // 全屏文字
// 加载完毕 //
if (ListCount == ListCountMax) {
clearInterval(I_LoadList); // 停止定时执行
FullsSreenText.innerHTML = "加载完毕"; // 全屏文字
setTarget(); // 设置 target
displayList(); // 显示列表
}
}
var I_LoadList = setInterval("loadList()", 100); // 加载列表,间隔 100 毫秒

/* 链接查找 */

function searchLink() {
Expand Down
13 changes: 1 addition & 12 deletions assets/js/nav-index.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 52 additions & 0 deletions assets/js/nav-links.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Slinky 插件的设置 //
var SlinkyOption = {
title: true,
speed: 400
};

var ListIDPrefix = '#list_'; // 列表 ID 前缀(自定义)
var ListCount = 0;
var ListCountMax = 17; // 列表总数(自定义)
var FullsSreenText = document.querySelector('.fullscreen-text');

// 链接 //
var Links = {};

// 设置 target = '_blank' //
function setTarget() {
for (var i = 0; i < LinkList.length; i++) {
if (LinkList[i].href.endsWith('#') == false) {
LinkList[i].target = '_blank';
/* 自动加图标(暂不使用;可使用 LazyLoad)
var slashPos = findChar(LinkList[i].href, '/', 3);
getFavicon = 'https://www.google.cn/s2/favicons?domain=' + LinkList[i].href.substring(0, slashPos);
var imgTag = '<img src="' + getFavicon + '" />';
LinkList[i].insertAdjacentHTML('beforeBegin', imgTag);
*/
}
}
}

// 显示列表 //
function displayList() {
document.querySelector('main').style.opacity = '1';
FullsSreenText.style.opacity = '0';
setTimeout(function () {
document.querySelector('.fullscreen-text').style.display = 'none';
}, 1000);
}

// 加载列表 //
function loadList() {
ListCount = ListCount + 1;
$(ListIDPrefix + ListCount).slinky(SlinkyOption);
FullsSreenText.innerHTML = '已加载 ' + ListCount + ' 个分类';
// 加载完毕 //
if (ListCount == ListCountMax) {
clearInterval(iLoadList);
FullsSreenText.innerHTML = '加载完毕';
setTarget();
displayList();
}
}
var iLoadList = setInterval('loadList()', 100);
7 changes: 0 additions & 7 deletions assets/js/nav-tool.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@ var Settings = {
/* 函数 */
/* ---- */

/* 返回顶部 */

function toTop() {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
}

/* 设置 */

// 字体大小 //
Expand Down
Loading

0 comments on commit 0faebe0

Please sign in to comment.