add index
This commit is contained in:
parent
ae7cafb1d6
commit
22081a5279
12
js/index.js
12
js/index.js
@ -17,19 +17,17 @@ $.ajax({
|
||||
dataType: "json",
|
||||
success: function (response) {
|
||||
var lastIndex = response.length - 1;
|
||||
var i;
|
||||
for(i in response){
|
||||
$('.sidebar').append($('<div>').append(response[i]['title']));
|
||||
}
|
||||
|
||||
if (response[lastIndex]['hasCode'] == true)
|
||||
listContent(response);
|
||||
|
||||
if (response[lastIndex]['hasCode'])
|
||||
loadScript('content/js/' + response[lastIndex]['date'] + '.js');
|
||||
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: 'content/html/' + response[lastIndex]['date'] + '.html',
|
||||
success: function (response) {
|
||||
appendContent(response);
|
||||
success: function (res) {
|
||||
appendContent(res);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -42,7 +42,8 @@ var message = new function () {
|
||||
return;
|
||||
}
|
||||
|
||||
var arg1 = arguments[0], arg2 = arguments[1];
|
||||
var arg1 = arguments[0],
|
||||
arg2 = arguments[1];
|
||||
|
||||
if (arguments.length <= 1) {
|
||||
header = '提示';
|
||||
@ -78,29 +79,56 @@ var message = new function () {
|
||||
}
|
||||
}
|
||||
|
||||
function loadScript(url, callback){
|
||||
var script = document.createElement('script');
|
||||
script.src = url;
|
||||
document.head.appendChild(script);
|
||||
function loadScript(url, callback) {
|
||||
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;
|
||||
document.getElementsByTagName("head")[0].appendChild(script);
|
||||
}
|
||||
|
||||
function loadCss(url, callback){
|
||||
function loadCss(url, callback) {
|
||||
var css = document.createElement('link');
|
||||
css.rel = 'stylesheet';
|
||||
css.href = url;
|
||||
document.head.appendChild(css);
|
||||
if(callback)
|
||||
if (callback)
|
||||
callback();
|
||||
}
|
||||
|
||||
function appendContent(content){
|
||||
function appendContent(content) {
|
||||
var div = $('<div class="content">');
|
||||
div.append(content);
|
||||
$('.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() {
|
||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
||||
var r = Math.random() * 16 | 0,
|
||||
|
23
js/view.js
Normal file
23
js/view.js
Normal 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
53
view.html
Normal 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>
|
Loading…
Reference in New Issue
Block a user