Skip to content

Commit a228192

Browse files
committed
Bug: Site overview tab can't be activated when disable motion. #212
1 parent 88630ca commit a228192

File tree

1 file changed

+58
-37
lines changed

1 file changed

+58
-37
lines changed

layout/_scripts/pages/post-details.swig

+58-37
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@
6969
element.on('mousewheel DOMMouseScroll', function (event) {
7070
var oe = event.originalEvent;
7171
var delta = oe.wheelDelta || -oe.detail;
72-
var self = this;
7372

7473
this.scrollTop += ( delta < 0 ? 1 : -1 ) * 30;
7574
event.preventDefault();
@@ -79,57 +78,79 @@
7978
}
8079

8180
function tocOverflowIndicator (indicator, action) {
82-
$(indicator).velocity('stop').velocity({
83-
opacity: action === 'show' ? 0.4 : 0
84-
}, { duration: 100 });
81+
var $indicator = $(indicator);
82+
var opacity = action === 'show' ? 0.4 : 0;
83+
$indicator.velocity ?
84+
$indicator.velocity('stop').velocity({
85+
opacity: opacity
86+
}, { duration: 100 }) :
87+
$indicator.stop().animate({
88+
opacity: opacity
89+
}, 100);
8590
}
8691

8792
});
8893
</script>
8994

90-
{% if theme.use_motion %}
91-
<script type="text/javascript" id="sidebar.nav">
92-
$(document).ready(function () {
93-
var html = $('html');
94-
95-
$('.sidebar-nav li').on('click', function () {
96-
var item = $(this);
97-
var activeTabClassName = 'sidebar-nav-active';
98-
var activePanelClassName = 'sidebar-panel-active';
99-
if (item.hasClass(activeTabClassName)) {
100-
return;
101-
}
95+
<script type="text/javascript" id="sidebar.nav">
96+
$(document).ready(function () {
97+
var html = $('html');
98+
var TAB_ANIMATE_DURATION = 200;
99+
var hasVelocity = $.isFunction(html.velocity);
100+
101+
$('.sidebar-nav li').on('click', function () {
102+
var item = $(this);
103+
var activeTabClassName = 'sidebar-nav-active';
104+
var activePanelClassName = 'sidebar-panel-active';
105+
if (item.hasClass(activeTabClassName)) {
106+
return;
107+
}
102108

103-
var currentTarget = $('.' + activePanelClassName);
104-
var target = $('.' + item.data('target'));
109+
var currentTarget = $('.' + activePanelClassName);
110+
var target = $('.' + item.data('target'));
105111

106-
currentTarget.velocity('transition.slideUpOut', 200, function () {
112+
hasVelocity ?
113+
currentTarget.velocity('transition.slideUpOut', TAB_ANIMATE_DURATION, function () {
107114
target
108115
.velocity('stop')
109-
.velocity('transition.slideDownIn', 200)
116+
.velocity('transition.slideDownIn', TAB_ANIMATE_DURATION)
110117
.addClass(activePanelClassName);
118+
}) :
119+
currentTarget.animate({ opacity: 0 }, TAB_ANIMATE_DURATION, function () {
120+
currentTarget.hide();
121+
target
122+
.stop()
123+
.css({'opacity': 0, 'display': 'block'})
124+
.animate({ opacity: 1 }, TAB_ANIMATE_DURATION, function () {
125+
currentTarget.removeClass(activePanelClassName);
126+
target.addClass(activePanelClassName);
127+
});
111128
});
112129

113-
item.siblings().removeClass(activeTabClassName);
114-
item.addClass(activeTabClassName);
115-
});
130+
item.siblings().removeClass(activeTabClassName);
131+
item.addClass(activeTabClassName);
132+
});
116133

117-
$('.post-toc a').on('click', function (e) {
118-
e.preventDefault();
119-
var offset = $(escapeSelector(this.getAttribute('href'))).offset().top;
134+
$('.post-toc a').on('click', function (e) {
135+
e.preventDefault();
136+
var targetSelector = escapeSelector(this.getAttribute('href'));
137+
var offset = $(targetSelector).offset().top;
138+
hasVelocity ?
120139
html.velocity('stop').velocity('scroll', {
121140
offset: offset + 'px',
122141
mobileHA: false
123-
});
124-
});
142+
}) :
143+
$('html, body').stop().animate({
144+
scrollTop: offset
145+
}, 500);
146+
});
125147

126-
// Expand sidebar on post detail page by default, when post has a toc.
127-
var $tocContent = $('.post-toc-content');
128-
if (isDesktop() && CONFIG.sidebar === 'post') {
129-
if ($tocContent.length > 0 && $tocContent.html().trim().length > 0) {
130-
displaySidebar();
131-
}
148+
// Expand sidebar on post detail page by default, when post has a toc.
149+
var $tocContent = $('.post-toc-content');
150+
if (isDesktop() && CONFIG.sidebar === 'post') {
151+
if ($tocContent.length > 0 && $tocContent.html().trim().length > 0) {
152+
displaySidebar();
132153
}
133-
});
134-
</script>
135-
{% endif %}
154+
}
155+
});
156+
</script>

0 commit comments

Comments
 (0)