forked from iluwatar/java-design-patterns
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
89 lines (77 loc) · 2.76 KB
/
index.js
File metadata and controls
89 lines (77 loc) · 2.76 KB
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
$(document).ready(function() {
categoryAndTagDisplay();
generateContent();
backToTop();
});
function fixFooterInit() {
var footerHeight = $('footer').outerHeight();
var footerMarginTop = getFooterMarginTop() - 0;
fixFooter(footerHeight, footerMarginTop); //fix footer at the beginning
$(window).resize(function() { //when resize window, footer can auto get the postion
fixFooter(footerHeight, footerMarginTop);
});
}
function fixFooter(footerHeight, footerMarginTop) {
var windowHeight = $(window).height();
var contentHeight = $('body>.container').outerHeight() + $('body>.container').offset().top + footerHeight + footerMarginTop;
console.log(contentHeight);
if (contentHeight < windowHeight) {
$('footer').addClass('navbar-fixed-bottom');
} else {
$('footer').removeClass('navbar-fixed-bottom');
}
$('footer').show(400);
}
function getFooterMarginTop() {
var margintop = $('footer').css('marginTop');
var patt = new RegExp("[0-9]*");
var re = patt.exec(margintop);
// console.log(re[0]);
return re[0];
}
function categoryAndTagDisplay() {
/*
$('.post-list-body>div[post-category!=All]').hide();
$('.post-list-body>div[post-tag!=All]').hide();
*/
/*show category when click categories list*/
$('.sidebar-list-item.category').click(function() {
var category = $(this).attr('category'); //get category's name
$('.post-list-item').not('[cats*=\'' + category + '\']').slideUp(200)
$('.post-list-item[cats*=\'' + category + '\']').slideDown()
});
/*show category when click tags list*/
$('.sidebar-list-item.tag').click(function() {
var tag = $(this).attr('tag'); //get tag's name
$('.post-list-item').not('[tags*=\'' + tag + '\']').slideUp(200)
$('.post-list-item[tags*=\'' + tag + '\']').slideDown()
});
}
function backToTop() {
$(window).scroll(function() {
if ($(window).scrollTop() > 100) {
$("#top").fadeIn(500);
} else {
$("#top").fadeOut(500);
}
});
$("#top").click(function() {
window.scrollTo(0, 0);
});
}
function generateContent() {
// console.log($('#markdown-toc').html());
if (typeof $('#markdown-toc').html() === 'undefined') {
// $('#content .content-text').html('<ul><li>文本较短,暂无目录</li></ul>');
$('#content').hide();
$('#myArticle').removeClass('col-sm-9').addClass('col-sm-12');
} else {
$('#content .content-text').html('<ul>' + $('#markdown-toc').html() + '</ul>');
/* //数据加载完成后,加固定边栏
$('#myAffix').attr({
'data-spy': 'affix',
'data-offset': '50'
});*/
}
console.log("myAffix!!!");
}