-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
126 lines (113 loc) · 4.17 KB
/
main.js
File metadata and controls
126 lines (113 loc) · 4.17 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
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
126
(function ($) {
// To top button
$("#back-to-top").on('click', function () {
$('body, html').animate({ scrollTop: 0 }, 600);
});
// Nav bar toggle
$('#main-nav-toggle').on('click', function () {
$('.nav-container-inner').slideToggle();
});
// Caption
$('.article-entry').each(function (i) {
$(this).find('img').each(function () {
if ($(this).parent().hasClass('fancybox')) {
return;
}
var alt = this.alt;
if (alt) {
$(this).after('<span class="caption">' + alt + '</span>');
}
$(this).wrap('<a href="' + this.src + '" title="' + alt + '" class="fancybox"></a>');
});
$(this).find('.fancybox').each(function(){
$(this).attr('rel', 'article' + i);
});
});
if ($.fancybox) {
$('.fancybox').fancybox();
}
// Sidebar expend
$('#sidebar .sidebar-toggle').click(function () {
if($('#sidebar').hasClass('expend')) {
$('#sidebar').removeClass('expend');
} else {
$('#sidebar').addClass('expend');
}
});
// Remove extra main nav wrap
$('.main-nav-list > li').unwrap();
// Highlight current nav item
$('#main-nav > li > .main-nav-list-link').each(function () {
if($('.page-title-link').length > 0){
if ($(this).html().toUpperCase() == $('.page-title-link').html().toUpperCase()) {
$(this).addClass('current');
} else if ($(this).attr('href') == $('.page-title-link').attr('data-url')) {
$(this).addClass('current');
}
}
});
// Auto hide main nav menus
function autoHideMenus(){
var max_width = $('.nav-container-inner').width() - 10;
var main_nav_width = $('#main-nav').width();
var sub_nav_width = $('#sub-nav').width();
if (main_nav_width + sub_nav_width > max_width) {
// If more link not exists
if ($('.main-nav-more').length == 0) {
$(['<li class="main-nav-list-item top-level-menu main-nav-more">',
'<a class="main-nav-list-link" href="javascript:;">More</a>',
'<ul class="main-nav-list-child">',
'</ul></li>'].join('')).appendTo($('#main-nav'));
// Bind hover event
$('.main-nav-more').hover(function () {
if($(window).width() < 480) {
return;
}
$(this).children('.main-nav-list-child').slideDown('fast');
}, function () {
if($(window).width() < 480) {
return;
}
$(this).children('.main-nav-list-child').slideUp('fast');
});
}
var child_count = $('#main-nav').children().length;
for (var i = child_count - 2; i >= 0; i--) {
var element = $('#main-nav').children().eq(i);
if (main_nav_width + sub_nav_width > max_width) {
element.prependTo($('.main-nav-more > ul'));
main_nav_width = $('#main-nav').width();
} else {
return;
}
}
}
// Nav bar is wide enough
if ($('.main-nav-more').length > 0) {
$('.main-nav-more > ul').children().appendTo($('#main-nav'));
$('.main-nav-more').remove();
}
}
autoHideMenus();
$(window).resize(function () {
autoHideMenus();
});
// Fold second-level menu
$('.main-nav-list-item').hover(function () {
if ($(window).width() < 480) {
return;
}
$(this).children('.main-nav-list-child').slideDown('fast');
}, function () {
if ($(window).width() < 480) {
return;
}
$(this).children('.main-nav-list-child').slideUp('fast');
});
// Add second-level menu mark
$('.main-nav-list-item').each(function () {
if ($(this).find('.main-nav-list-child').length > 0) {
$(this).addClass('top-level-menu');
}
});
})(jQuery);