-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaccordion-toc-2.js
125 lines (123 loc) · 3.79 KB
/
accordion-toc-2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*!
* BLOGGER TOC WITH ACCORDION EFFECT (SORT BY DATE PUBLISHED)
* ---------------------------------------------------
* by Taufik Nurrohman
* URL: http://gplus.to/tovic
* ---------------------------------------------------
*/
/*
var toc_config = {
url: 'http://dte-feed.blogspot.com',
containerId: 'table-of-content',
monthNames: [
'Januari',
'Februari',
'Maret',
'April',
'Mei',
'Juni',
'Juli',
'Agustus',
'September',
'Oktober',
'November',
'Desember'
],
oldestFirst: false,
maxResults: 9999,
activePanel: 1,
slideSpeed: {
down: 400,
up: 400
},
slideEasing: {
down: null,
up: null
},
slideCallback: {
down: function() {},
up: function() {}
},
clickCallback: function() {},
jsonCallback: '_toc',
delayLoading: 0
};
*/
(function(w, d) {
var tocContainer = d.getElementById(toc_config.containerId),
head = d.getElementsByTagName('head')[0],
postTitle = [],
postUrl = [],
postDate = [],
postMonth = [],
postYearMonth = [],
postDateNum = [],
postISODate = [],
monthArray = toc_config.monthNames,
title, link;
w[toc_config.jsonCallback] = function(json) {
if ("entry" in json.feed) {
var entry = (toc_config.oldestFirst) ? json.feed.entry.reverse() : json.feed.entry;
for (var i = 0, ien = entry.length; i < ien; ++i) {
title = entry[i].title.$t,
isoDate = entry[i].published.$t,
a = isoDate.substring(0,10),
b = isoDate.substring(5,7),
c = isoDate.substring(8,10),
pub = monthArray[parseInt(b,10) - 1] + " " + isoDate.substring(0,4),
date = "/" + isoDate.substring(0,4) + "_" + b + "_01_archive.html";
for (var j = 0, jen = entry[i].link.length; j < jen; ++j) {
if (entry[i].link[j].rel == "alternate") {
link = entry[i].link[j].href;
break;
}
}
postTitle.push(title);
postDate.push(a);
postISODate.push(isoDate);
postUrl.push(link);
postYearMonth.push(pub);
postDateNum.push(c);
}
}
displayToc();
};
function displayToc() {
var a = 0, b = 0, skeleton = "";
while (b < postTitle.length) {
temp = postYearMonth[b].replace(/\'/g,"'").replace(/\"/g,""");
skeleton += '<h3 class="toc-header">' + temp + '</h3>';
skeleton += '<div class="toc-content"><ol>';
do {
skeleton += '<li>';
skeleton += '<time title="' + postISODate[a] + '" datetime="' + postISODate[a] + '">' + postDateNum[a] + ' ' + temp + '</time> :: <a title="' + postTitle[a] + '" href="' + postUrl[a] + '" >' + postTitle[a] + '</a>';
skeleton += '</li>';
a = a + 1;
} while (postYearMonth[a] == temp);
b = a;
skeleton += '</ol></div>';
if (b > postTitle.length) break;
}
tocContainer.innerHTML = skeleton;
if (typeof jQuery != 'undefined') {
$('#' + toc_config.containerId + ' .toc-content').hide();
$('#' + toc_config.containerId + ' .toc-header').click(function() {
if ($(this).hasClass('active')) return;
toc_config.clickCallback(this);
$('#' + toc_config.containerId + ' .toc-header').removeClass('active').next().slideUp(toc_config.slideSpeed.up, toc_config.slideEasing.up, toc_config.slideCallback.up);
$(this).addClass('active').next().slideDown(toc_config.slideSpeed.down, toc_config.slideEasing.down, toc_config.slideCallback.down);
}).eq(toc_config.activePanel - 1).addClass('active').next().slideDown(toc_config.slideSpeed.down, toc_config.slideEasing.down, toc_config.slideCallback.down);
}
}
var s = d.createElement('script');
s.src = toc_config.url.replace(/\/$/, "") + '/feeds/posts/summary/?alt=json-in-script&orderby=published&max-results=' + toc_config.maxResults + '&callback=' + toc_config.jsonCallback;
if (toc_config.delayLoading == "onload") {
w.onload = function() {
head.appendChild(s);
};
} else {
w.setTimeout(function() {
head.appendChild(s);
}, toc_config.delayLoading);
}
})(window, document);