-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathaccordion-toc-1.js
102 lines (100 loc) · 3.38 KB
/
accordion-toc-1.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
/**
* BLOGGER TOC WITH ACCORDION EFFECT (SORT BY LABEL)
* ---------------------------------------------------
* by Taufik Nurrohman
* URL: http://gplus.to/tovic
* ---------------------------------------------------
*/
/*
var toc_config = {
url: 'http://dte-feed.blogspot.com',
containerId: 'table-of-content',
showNew: 10,
newText: ' - <strong style="font-weight:bold;font-style:italic;color:red;">Baru!</strong>',
sortAlphabetically: {
thePanel: true,
theList: true
},
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 cont = d.getElementById(toc_config.containerId),
head = d.getElementsByTagName('head')[0],
category = [];
w[toc_config.jsonCallback] = function(json) {
var entry = json.feed.entry,
cat = json.feed.category,
title, link, label, skeleton = "";
for (var h = 0, hen = cat.length; h < hen; ++h) {
category.push(cat[h].term);
}
for (var f = 0, fen = entry.length; f < fen; ++f) {
if (toc_config.showNew || toc_config.showNew > 0) {
if (f < toc_config.showNew + 1) {
entry[f].title.$t += ' %new%';
}
}
}
entry = (toc_config.sortAlphabetically.theList) ? entry.sort(function(a, b) {
return (a.title.$t.localeCompare(b.title.$t));
}) : entry;
if (toc_config.sortAlphabetically.thePanel) category.sort();
for (var g = 0, gen = category.length; g < gen; ++g) {
skeleton += '<h3 class="toc-header">' + category[g] + '</h3>';
skeleton += '<div class="toc-content"><ol>';
for (var i = 0, ien = entry.length; i < ien; ++i) {
title = entry[i].title.$t;
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;
}
}
for (var k = 0, ken = entry[i].category.length; k < ken; ++k) {
if (category[g] == entry[i].category[k].term) {
skeleton += '<li><a href="' + link + '">' + title.replace(/ \%new\%$/, "") + '</a>' + (title.match(/\%new\%/) ? ' ' + toc_config.newText : '') + '</li>';
}
}
}
skeleton += '</ol></div>';
}
cont.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&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);