add index

This commit is contained in:
wolegca 2019-09-20 13:32:44 +08:00
parent ae7cafb1d6
commit 22081a5279
4 changed files with 118 additions and 16 deletions

View File

@ -17,19 +17,17 @@ $.ajax({
dataType: "json", dataType: "json",
success: function (response) { success: function (response) {
var lastIndex = response.length - 1; var lastIndex = response.length - 1;
var i;
for(i in response){ listContent(response);
$('.sidebar').append($('<div>').append(response[i]['title']));
}
if (response[lastIndex]['hasCode'] == true) if (response[lastIndex]['hasCode'])
loadScript('content/js/' + response[lastIndex]['date'] + '.js'); loadScript('content/js/' + response[lastIndex]['date'] + '.js');
$.ajax({ $.ajax({
type: "GET", type: "GET",
url: 'content/html/' + response[lastIndex]['date'] + '.html', url: 'content/html/' + response[lastIndex]['date'] + '.html',
success: function (response) { success: function (res) {
appendContent(response); appendContent(res);
} }
}); });
} }

View File

@ -42,7 +42,8 @@ var message = new function () {
return; return;
} }
var arg1 = arguments[0], arg2 = arguments[1]; var arg1 = arguments[0],
arg2 = arguments[1];
if (arguments.length <= 1) { if (arguments.length <= 1) {
header = '提示'; header = '提示';
@ -78,29 +79,56 @@ var message = new function () {
} }
} }
function loadScript(url, callback){ function loadScript(url, callback) {
var script = document.createElement('script'); var script = document.createElement("script")
if (script.readyState) { //IE
script.onreadystatechange = function () {
if (script.readyState == "loaded" || script.readyState == "complete") {
script.onreadystatechange = null;
if(callback)
callback();
}
};
} else { //Others
script.onload = function () {
if(callback)
callback();
};
}
script.src = url; script.src = url;
document.head.appendChild(script); document.getElementsByTagName("head")[0].appendChild(script);
if(callback)
callback();
} }
function loadCss(url, callback){ function loadCss(url, callback) {
var css = document.createElement('link'); var css = document.createElement('link');
css.rel = 'stylesheet'; css.rel = 'stylesheet';
css.href = url; css.href = url;
document.head.appendChild(css); document.head.appendChild(css);
if(callback) if (callback)
callback(); callback();
} }
function appendContent(content){ function appendContent(content) {
var div = $('<div class="content">'); var div = $('<div class="content">');
div.append(content); div.append(content);
$('.content-border').prepend(div); $('.content-border').prepend(div);
} }
function listContent(json){
var i, sidebar = $('.sidebar');
for(i in json){
sidebar.append($('<div>').append($('<a>').attr('href','view.html?i=' + i).append(json[i]['title'])));
}
}
function getQueryString(param) {
var reg = new RegExp("(^|&)" + param + "=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if (r != null)
return decodeURI(r[2]);
return '';
}
function uuid() { function uuid() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
var r = Math.random() * 16 | 0, var r = Math.random() * 16 | 0,

23
js/view.js Normal file
View File

@ -0,0 +1,23 @@
(function () {
var index = getQueryString('i');
$.ajax({
type: "GET",
url: "content.json",
dataType: "json",
success: function (response) {
listContent(response);
if (response[index]['hasCode'])
loadScript('content/js/' + response[index]['date'] + '.js');
$.ajax({
type: "GET",
url: 'content/html/' + response[index]['date'] + '.html',
success: function (res) {
appendContent(res);
}
});
}
});
})();

53
view.html Normal file
View File

@ -0,0 +1,53 @@
<!DOCTYPE html>
<html lang="zh">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<link rel="stylesheet" href="css/index.css">
<link rel="stylesheet" href="css/myui.css">
<link rel="stylesheet" href="css/highlight.css">
<title>LAOZHONGYI BLOG</title>
</head>
<body>
<div class="container clearfix">
<div id="blog-title">AHPU 老中医的博客</div>
<input type="checkbox" id="menu-control">
<div class="menu-container">
<ul>
<li><a href="/">首页</a></li>
<li><span>关于</span></li>
<li><label for="menu-control">返回</label></li>
</ul>
</div>
<label for="menu-control" class="content-mask"></label>
<label for="menu-control" class="menu-button-container">
<div class="menu-button">
<span></span>
<span></span>
<span></span>
</div>
</label>
<div class="content-border">
<!--文章-->
<div class="sidebar-border">
<div class="sidebar">
<div>
往期回顾
</div>
<!--列表-->
</div>
</div>
</div>
</div>
<!-- <div class="mask"></div> -->
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<script src="js/drag.js"></script>
<script src="js/initialize.js"></script>
<script src="js/view.js"></script>
</body>
</html>