Skip to content

Commit f01bf88

Browse files
matticoMichael-F-Bryan
authored andcommitted
Fix several theme issues (#648)
* Don't hide page content when displaying search * Decrease sidebar animation time * Fix search key event handler which wasn't completely de-jqueryified. * Avoid reflowing page content on small screens This reduces jank caused by reflowing the page text while animating the sidebar, and it looks nicer. * Don't use HTMLParentNode.prepend() since edge doesn't support it yet * Don't animate menu border bottom color since it's the same color as the background, which isn't animated. * Small CSS improvments - Remove invalid `pointer: cursor` style - Disable transitions for noscript to stop page from spazzing on every load - Add `cursor: pointer` to mark - Disable `cursor: pointer` on noscript menu-title * JS fixes - Load MathJax async - Always use local fontawesome and clipboard.js - Move js class to html element to make theme switching easier * Give the print button a bit more margin
1 parent b5ea84c commit f01bf88

File tree

11 files changed

+159
-180
lines changed

11 files changed

+159
-180
lines changed

src/theme/book.css

+48-43
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,13 @@ table thead td {
8181
box-sizing: border-box;
8282
-webkit-overflow-scrolling: touch;
8383
overscroll-behavior-y: contain;
84-
-webkit-transition: -webkit-transform 0.5s;
85-
-moz-transition: -moz-transform 0.5s;
86-
-o-transition: -o-transform 0.5s;
87-
-ms-transition: -ms-transform 0.5s;
88-
transition: transform 0.5s;
84+
}
85+
.js .sidebar {
86+
-webkit-transition: -webkit-transform 0.3s;
87+
-moz-transition: -moz-transform 0.3s;
88+
-o-transition: -o-transform 0.3s;
89+
-ms-transition: -ms-transform 0.3s;
90+
transition: transform 0.3s;
8991
}
9092
.sidebar code {
9193
line-height: 2em;
@@ -137,42 +139,44 @@ table thead td {
137139
white-space: nowrap;
138140
}
139141
.page-wrapper {
140-
left: 0;
141-
position: absolute;
142-
right: 0;
143-
top: 0;
144-
bottom: 0;
145142
-webkit-box-sizing: border-box;
146143
-moz-box-sizing: border-box;
147144
box-sizing: border-box;
148-
-webkit-transition: padding-left 0.5s, margin-left 0.5s, left 0.5s;
149-
-moz-transition: padding-left 0.5s, margin-left 0.5s, left 0.5s;
150-
-o-transition: padding-left 0.5s, margin-left 0.5s, left 0.5s;
151-
-ms-transition: padding-left 0.5s, margin-left 0.5s, left 0.5s;
152-
transition: padding-left 0.5s, margin-left 0.5s, left 0.5s;
145+
}
146+
.js .page-wrapper {
147+
-webkit-transition: margin-left 0.3s ease, -webkit-transform 0.3s ease;
148+
-moz-transition: margin-left 0.3s ease, -moz-transform 0.3s ease;
149+
-o-transition: margin-left 0.3s ease, -o-transform 0.3s ease;
150+
-ms-transition: margin-left 0.3s ease, -ms-transform 0.3s ease;
151+
transition: margin-left 0.3s ease, transform 0.3s ease;
153152
}
154153
.sidebar-visible .page-wrapper {
155-
left: 300px;
154+
-webkit-transform: translateX(300px);
155+
-moz-transform: translateX(300px);
156+
-o-transform: translateX(300px);
157+
-ms-transform: translateX(300px);
158+
transform: translateX(300px);
159+
}
160+
@media only screen and (min-width: 620px) {
161+
.sidebar-visible .page-wrapper {
162+
-webkit-transform: none;
163+
-moz-transform: none;
164+
-o-transform: none;
165+
-ms-transform: none;
166+
transform: none;
167+
margin-left: 300px;
168+
}
156169
}
157170
.page {
158171
outline: 0;
159172
padding: 0 15px;
160173
}
161174
.content {
162-
position: relative;
163-
top: 0;
164-
bottom: 0;
165175
overflow-y: auto;
166-
right: 0;
167-
left: 0;
168176
padding: 0 15px;
169177
padding-bottom: 50px;
170178
}
171-
.sidebar-visible .content {
172-
position: absolute;
173-
top: 52px;
174-
}
175-
.content > main {
179+
.content main {
176180
margin-left: auto;
177181
margin-right: auto;
178182
max-width: 750px;
@@ -205,27 +209,29 @@ table thead td {
205209
-webkit-flex-wrap: wrap;
206210
-ms-flex-wrap: wrap;
207211
flex-wrap: wrap;
208-
-webkit-transition: -webkit-transform 0.5s, border-bottom-color 0.5s;
209-
-moz-transition: -moz-transform 0.5s, border-bottom-color 0.5s;
210-
-o-transition: -o-transform 0.5s, border-bottom-color 0.5s;
211-
-ms-transition: -ms-transform 0.5s, border-bottom-color 0.5s;
212-
transition: transform 0.5s, border-bottom-color 0.5s;
212+
}
213+
.js #menu-bar > #menu-bar-sticky-container {
214+
-webkit-transition: -webkit-transform 0.3s;
215+
-moz-transition: -moz-transform 0.3s;
216+
-o-transition: -o-transform 0.3s;
217+
-ms-transition: -ms-transform 0.3s;
218+
transition: transform 0.3s;
213219
}
214220
#menu-bar i,
215221
#menu-bar .icon-button {
216222
position: relative;
217223
margin: 0 10px;
218224
z-index: 10;
219225
line-height: 50px;
226+
cursor: pointer;
220227
-webkit-transition: color 0.5s;
221228
-moz-transition: color 0.5s;
222229
-o-transition: color 0.5s;
223230
-ms-transition: color 0.5s;
224231
transition: color 0.5s;
225232
}
226-
#menu-bar i:hover,
227-
#menu-bar .icon-button:hover {
228-
cursor: pointer;
233+
#menu-bar #print-button {
234+
margin: 0 15px;
229235
}
230236
html:not(.sidebar-visible) #menu-bar:not(:hover).folded > #menu-bar-sticky-container {
231237
-webkit-transform: translateY(-60px);
@@ -234,6 +240,9 @@ html:not(.sidebar-visible) #menu-bar:not(:hover).folded > #menu-bar-sticky-conta
234240
-ms-transform: translateY(-60px);
235241
transform: translateY(-60px);
236242
}
243+
.no-js .left-buttons {
244+
display: none;
245+
}
237246
.menu-title {
238247
display: inline-block;
239248
font-weight: 200;
@@ -252,6 +261,8 @@ html:not(.sidebar-visible) #menu-bar:not(:hover).folded > #menu-bar-sticky-conta
252261
overflow: hidden;
253262
-o-text-overflow: ellipsis;
254263
text-overflow: ellipsis;
264+
}
265+
.js .menu-title {
255266
cursor: pointer;
256267
}
257268
.nav-chapters {
@@ -363,7 +374,6 @@ html:not(.sidebar-visible) #menu-bar:not(:hover).folded > #menu-bar-sticky-conta
363374
.light .content .header:link,
364375
.light .content .header:visited {
365376
color: #333;
366-
pointer: cursor;
367377
}
368378
.light .content .header:link:hover,
369379
.light .content .header:visited:hover {
@@ -554,7 +564,6 @@ html:not(.sidebar-visible) #menu-bar:not(:hover).folded > #menu-bar-sticky-conta
554564
.coal .content .header:link,
555565
.coal .content .header:visited {
556566
color: #98a3ad;
557-
pointer: cursor;
558567
}
559568
.coal .content .header:link:hover,
560569
.coal .content .header:visited:hover {
@@ -745,7 +754,6 @@ html:not(.sidebar-visible) #menu-bar:not(:hover).folded > #menu-bar-sticky-conta
745754
.navy .content .header:link,
746755
.navy .content .header:visited {
747756
color: #bcbdd0;
748-
pointer: cursor;
749757
}
750758
.navy .content .header:link:hover,
751759
.navy .content .header:visited:hover {
@@ -936,7 +944,6 @@ html:not(.sidebar-visible) #menu-bar:not(:hover).folded > #menu-bar-sticky-conta
936944
.rust .content .header:link,
937945
.rust .content .header:visited {
938946
color: #262625;
939-
pointer: cursor;
940947
}
941948
.rust .content .header:link:hover,
942949
.rust .content .header:visited:hover {
@@ -1127,7 +1134,6 @@ html:not(.sidebar-visible) #menu-bar:not(:hover).folded > #menu-bar-sticky-conta
11271134
.ayu .content .header:link,
11281135
.ayu .content .header:visited {
11291136
color: #c5c5c5;
1130-
pointer: cursor;
11311137
}
11321138
.ayu .content .header:link:hover,
11331139
.ayu .content .header:visited:hover {
@@ -1401,18 +1407,18 @@ mark {
14011407
-o-transition: background-color 300ms linear;
14021408
-ms-transition: background-color 300ms linear;
14031409
transition: background-color 300ms linear;
1410+
cursor: pointer;
14041411
}
1405-
.fade-out {
1412+
mark.fade-out {
14061413
background-color: rgba(0,0,0,0) !important;
1414+
cursor: auto;
14071415
}
14081416
.searchbar-outer {
1409-
display: none;
14101417
margin-left: auto;
14111418
margin-right: auto;
14121419
max-width: 750px;
14131420
}
14141421
#searchbar {
1415-
display: block;
14161422
width: 100%;
14171423
margin: 5px auto 0px auto;
14181424
padding: 10px 16px;
@@ -1428,7 +1434,6 @@ mark {
14281434
padding: 18px 0 0 5px;
14291435
}
14301436
.searchresults-outer {
1431-
display: none;
14321437
margin-left: auto;
14331438
margin-right: auto;
14341439
max-width: 750px;

src/theme/book.js

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"use strict";
2+
13
// Fix back button cache problem
24
window.onunload = function () { };
35

@@ -55,6 +57,7 @@ function playpen_text(playpen) {
5557
var txt = playpen_text(pre_block);
5658
var re = /extern\s+crate\s+([a-zA-Z_0-9]+)\s*;/g;
5759
var snippet_crates = [];
60+
var item;
5861
while (item = re.exec(txt)) {
5962
snippet_crates.push(item[1]);
6063
}
@@ -175,7 +178,7 @@ function playpen_text(playpen) {
175178
buttons.innerHTML = "<button class=\"fa fa-expand\" title=\"Show hidden lines\" aria-label=\"Show hidden lines\"></button>";
176179

177180
// add expand button
178-
pre_block.prepend(buttons);
181+
pre_block.insertBefore(buttons, pre_block.firstChild);
179182

180183
pre_block.querySelector('.buttons').addEventListener('click', function (e) {
181184
if (e.target.classList.contains('fa-expand')) {
@@ -213,7 +216,7 @@ function playpen_text(playpen) {
213216
if (!buttons) {
214217
buttons = document.createElement('div');
215218
buttons.className = 'buttons';
216-
pre_block.prepend(buttons);
219+
pre_block.insertBefore(buttons, pre_block.firstChild);
217220
}
218221

219222
var clipButton = document.createElement('button');
@@ -222,7 +225,7 @@ function playpen_text(playpen) {
222225
clipButton.setAttribute('aria-label', clipButton.title);
223226
clipButton.innerHTML = '<i class=\"tooltiptext\"></i>';
224227

225-
buttons.prepend(clipButton);
228+
buttons.insertBefore(clipButton, buttons.firstChild);
226229
}
227230
});
228231

@@ -233,7 +236,7 @@ function playpen_text(playpen) {
233236
if (!buttons) {
234237
buttons = document.createElement('div');
235238
buttons.className = 'buttons';
236-
pre_block.prepend(buttons);
239+
pre_block.insertBefore(buttons, pre_block.firstChild);
237240
}
238241

239242
var runCodeButton = document.createElement('button');
@@ -248,8 +251,8 @@ function playpen_text(playpen) {
248251
copyCodeClipboardButton.title = 'Copy to clipboard';
249252
copyCodeClipboardButton.setAttribute('aria-label', copyCodeClipboardButton.title);
250253

251-
buttons.prepend(runCodeButton);
252-
buttons.prepend(copyCodeClipboardButton);
254+
buttons.insertBefore(runCodeButton, buttons.firstChild);
255+
buttons.insertBefore(copyCodeClipboardButton, buttons.firstChild);
253256

254257
runCodeButton.addEventListener('click', function (e) {
255258
run_rust_code(pre_block);
@@ -262,7 +265,7 @@ function playpen_text(playpen) {
262265
undoChangesButton.title = 'Undo changes';
263266
undoChangesButton.setAttribute('aria-label', undoChangesButton.title);
264267

265-
buttons.prepend(undoChangesButton);
268+
buttons.insertBefore(undoChangesButton, buttons.firstChild);
266269

267270
undoChangesButton.addEventListener('click', function () {
268271
let editor = window.ace.edit(code_block);

0 commit comments

Comments
 (0)