-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Expand file tree
/
Copy pathsb-admin-2.js
More file actions
85 lines (78 loc) · 2.29 KB
/
sb-admin-2.js
File metadata and controls
85 lines (78 loc) · 2.29 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
(function ($) {
'use strict';
function debounce(func, wait) {
var timeout;
return function () {
var context = this,
args = arguments;
clearTimeout(timeout);
timeout = setTimeout(function () {
func.apply(context, args);
}, wait);
};
}
$('#sidebarToggle, #sidebarToggleTop').on('click', function (e) {
e.preventDefault();
$('body').toggleClass('sidebar-toggled');
$('.sidebar').toggleClass('toggled');
var isExpanded = !$('.sidebar').hasClass('toggled');
$('#sidebarToggle, #sidebarToggleTop').attr('aria-expanded', isExpanded);
if ($('.sidebar').hasClass('toggled')) {
$('.sidebar .collapse').collapse('hide');
}
});
$(window).resize(
debounce(function () {
var windowWidth = $(window).width();
if (windowWidth < 768) {
$('.sidebar .collapse').collapse('hide');
}
if (windowWidth < 480 && !$('.sidebar').hasClass('toggled')) {
$('body').addClass('sidebar-toggled');
$('.sidebar').addClass('toggled');
$('#sidebarToggle, #sidebarToggleTop').attr('aria-expanded', 'false');
$('.sidebar .collapse').collapse('hide');
}
}, 200),
);
$('body.fixed-nav .sidebar').on('wheel', function (e) {
if ($(window).width() > 768) {
var e0 = e.originalEvent;
var delta = e0.deltaY * -1 || e0.wheelDelta || -e0.detail;
this.scrollTop += (delta < 0 ? 1 : -1) * 30;
e.preventDefault();
}
});
$(document).on(
'scroll',
debounce(function () {
var scrollDistance = $(this).scrollTop();
if (scrollDistance > 100) {
$('.scroll-to-top').fadeIn(200);
} else {
$('.scroll-to-top').fadeOut(200);
}
}, 200),
);
$(document).on('click', 'a.scroll-to-top', function (e) {
var $anchor = $(this);
var $target = $($anchor.attr('href'));
if ($target.length) {
$('html, body').stop().animate(
{
scrollTop: $target.offset().top,
},
1000,
'easeInOutExpo',
);
}
e.preventDefault();
});
$(document).ready(function () {
$('.scroll-to-top').fadeOut(0);
$('#sidebarToggle, #sidebarToggleTop').attr({
'aria-label': '切换侧边栏',
'aria-expanded': !$('.sidebar').hasClass('toggled'),
});
});
})(jQuery);