diff --git a/js/index.js b/js/index.js
index 2c3ed4d..dde115d 100644
--- a/js/index.js
+++ b/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($('
').append(response[i]['title']));
- }
+
+ listContent(response);
- if (response[lastIndex]['hasCode'] == true)
+ 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);
}
});
}
diff --git a/js/initialize.js b/js/initialize.js
index d7b81d6..dd7ffad 100644
--- a/js/initialize.js
+++ b/js/initialize.js
@@ -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');
+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.head.appendChild(script);
- if(callback)
- callback();
+ 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.append(content);
$('.content-border').prepend(div);
}
+function listContent(json){
+ var i, sidebar = $('.sidebar');
+ for(i in json){
+ sidebar.append($('
').append($('
').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,
diff --git a/js/view.js b/js/view.js
new file mode 100644
index 0000000..e6fda6d
--- /dev/null
+++ b/js/view.js
@@ -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);
+ }
+ });
+ }
+ });
+})();
\ No newline at end of file
diff --git a/view.html b/view.html
new file mode 100644
index 0000000..ceef362
--- /dev/null
+++ b/view.html
@@ -0,0 +1,53 @@
+
+
+
+
+
+
+
+
+
+
+ LAOZHONGYI BLOG
+
+
+
+
+
AHPU 老中医的博客
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file