-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
130 lines (115 loc) · 4.2 KB
/
script.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/**
*
* DokuWiki Twenty Fifteen Template
*
* @link https://github.com/lainme/dokuwiki-theme-twentyfifteen
* @author Anika Henke <[email protected]> (upstream)
* @author WordPress.org & Automattic.com (upstream)
* @author lainme <[email protected]>
* @license GPLv2 (http://www.gnu.org/licenses/gpl.html)
*/
(function($) {
var top = false, bottom = false, topOffset = 0, lastWindowPos = 0;
var secondary, sidebar, button;
function chattr() {
if (955 > $(window).width()) {
button.attr('aria-expanded', 'false');
button.attr('aria-controls', 'secondary');
secondary.attr('aria-expanded', 'false');
} else {
button.removeAttr('aria-expanded');
button.removeAttr('aria-controls');
secondary.removeAttr('aria-expanded');
}
}
function resize() {
if (955 > $(window).width()) {
top = bottom = false;
sidebar.removeAttr('style');
}
}
function scroll() {
var windowPos = $(window).scrollTop();
var windowWidth = $(window).width();
var windowHeight = $(window).height();
var bodyHeight = $(document.body).height();
var sidebarHeight = sidebar.height();
if (955 > windowWidth) {
return;
}
if (sidebarHeight > windowHeight) {
if (windowPos > lastWindowPos) {
if (top) {
top = false;
topOffset = (sidebar.offset().top > 0) ? sidebar.offset().top : 0;
sidebar.attr('style', 'top: ' + topOffset + 'px;');
} else if (! bottom && windowPos + windowHeight > sidebarHeight + sidebar.offset().top && sidebarHeight < bodyHeight) {
bottom = true;
sidebar.attr('style', 'position: fixed; bottom: 0;');
}
} else if (windowPos < lastWindowPos) {
if (bottom) {
bottom = false;
topOffset = (sidebar.offset().top > 0) ? sidebar.offset().top : 0;
sidebar.attr('style', 'top: ' + topOffset + 'px;');
} else if (! top && windowPos < sidebar.offset().top) {
top = true;
sidebar.attr('style', 'position: fixed;');
}
} else {
top = bottom = false;
topOffset = (sidebar.offset().top > 0) ? sidebar.offset().top : 0;
sidebar.attr('style', 'top: ' + topOffset + 'px;');
}
} else if (! top) {
top = true;
sidebar.attr('style', 'position: fixed;');
}
lastWindowPos = windowPos;
}
function changeLayout() {
secondary = $('.secondary');
sidebar = $('.sidebar');
button = $('.secondary-toggle');
$(window)
.on('scroll.twentyfifteen', scroll)
.on('load.twentyfifteen', chattr)
.on('resize.twentyfifteen', function() {
setTimeout(function() {resize(); scroll();}, 500);
chattr();
});
sidebar.on('click.twentyfifteen', 'button', function() {resize(); scroll();});
}
function changeMenu() {
var widgets = secondary.find('.widget-area');
if (! secondary.length || ! button.length) {
return;
}
if (! widgets.length) {
button.hide();
return;
}
button.on('click.twentyfifteen', function() {
secondary.toggleClass('toggled-on');
$(this).toggleClass('toggled-on');
if ($(this, secondary).hasClass('toggled-on')) {
$(this).attr('aria-expanded', 'true');
secondary.attr('aria-expanded', 'true');
} else {
$(this).attr('aria-expanded', 'false');
secondary.attr('aria-expanded', 'false');
}
} );
}
function changeToc() {
var $toc = $('#dw__toc .toggle');
if($toc.length) {
$toc[0].setState(-1);
}
}
$(document).ready(function() {
changeLayout();
changeMenu();
changeToc();
} );
})(jQuery);