Skip to content

Commit 0edd894

Browse files
authored
DOC-660 | Improve logic for "Show more" (#517)
Don't use conflicting detection of long code blocks (element height vs. number of lines). Ensure we always reveal ~5 lines or don't collapse content. Also don't collapse code blocks already hidden by default ("Show output"). * Fix regression with hash-only links that shouldn't be aliased An anchor link does not contain a slash to split by. The second element is thus undefined and it got spliced in, then turned into an extra slash, breaking the fragment identifier. * Split code for copy to clipboard and adding the Show more button This allows to independently call the latter, which we need to do for tabbed content for which we don't know the height until it is activated. The the event handler at a higher level so that it can handle buttons added after page load Also remove some dead code for copy to clipboard. * Use .on("click", ...) over the deprecated .click(...) * Remove rounding from tab underline * Apply code block styles also independently of copy to clipboard class * CSS: Normalize 0px to 0
1 parent 5f8affb commit 0edd894

File tree

3 files changed

+72
-70
lines changed

3 files changed

+72
-70
lines changed

site/themes/arangodb-docs-theme/static/css/theme.css

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ ul ul, ul ol, ol ul, ol ol {
235235
margin: 0;
236236
padding: 2px;
237237
word-break: break-word;
238-
border-radius: 0px;
238+
border-radius: 0;
239239
background: var(--gray-100);
240240
box-shadow: none;
241241
color: var(--gray-950);
@@ -252,7 +252,6 @@ ul ul, ul ol, ol ul, ol ol {
252252
text-decoration: none;
253253
}
254254

255-
256255
hr {
257256
width: 100%;
258257
height: 4px;
@@ -263,7 +262,6 @@ hr {
263262
border: none;
264263
}
265264

266-
267265
pre {
268266
margin-bottom: 2rem;
269267
background-color: var(--CODEBLOCK-BACKGROUND-COLOR);
@@ -407,11 +405,11 @@ table.fixed code {
407405
}
408406

409407
/* .card:hover {
410-
box-shadow: rgb(149 157 165 / 20%) 0px 8px 24px;
408+
box-shadow: rgb(149 157 165 / 20%) 0 8px 24px;
411409
} */
412410

413411
.cards > a.card-link {
414-
border-bottom: 0px;
412+
border-bottom: 0;
415413
}
416414

417415
@media screen and (max-width: 768px) {
@@ -489,8 +487,8 @@ a.section-link {
489487

490488
.loader{
491489
position: fixed;
492-
left: 0px;
493-
top: 0px;
490+
left: 0;
491+
top: 0;
494492
width: 100%;
495493
height: 100%;
496494
z-index: 9999;
@@ -521,7 +519,8 @@ a.section-link {
521519
position: relative;
522520
max-width: 300px;
523521
background-color: transparent;
524-
border: 0px;
522+
border: 0;
523+
border-radius: 0;
525524
text-decoration: none;
526525
white-space: nowrap;
527526
overflow: hidden;
@@ -537,9 +536,9 @@ a.section-link {
537536
.tab-nav-button.selected::after {
538537
content: "";
539538
position: absolute;
540-
left: 0px;
541-
right: 0px;
542-
bottom: 0px;
539+
left: 0;
540+
right: 0;
541+
bottom: 0;
543542
height: 2px;
544543
background-color: var(--HEADERS-COLOR)
545544
}
@@ -567,7 +566,7 @@ body .page-container {
567566
'header header'
568567
'sidenav contents'
569568
'sidenav footer';
570-
grid-template-columns: minmax(0px, auto) 4fr;
569+
grid-template-columns: minmax(0, auto) 4fr;
571570
grid-template-rows: 4rem 1fr;
572571
background: var(--CONTENT-BACKGROUND-COLOR);
573572
}
@@ -637,7 +636,7 @@ body .page-container {
637636
vertical-align: middle;
638637
font-weight: 900;
639638
font-size: 18px;
640-
padding-top: 0px;
639+
padding-top: 0;
641640
color: var(--gray-100);
642641
}
643642

@@ -702,7 +701,7 @@ body .page-container {
702701
position: relative;
703702
height: 64px;
704703
align-items: center;
705-
padding: 6px 10px 0px 10px;
704+
padding: 6px 10px 0 10px;
706705
}
707706

708707
header .logo {
@@ -980,7 +979,7 @@ header .logo {
980979
vertical-align: middle;
981980
font-weight: 900;
982981
font-size: 10px;
983-
padding-top: 0px;
982+
padding-top: 0;
984983
color: var(--gray-300);
985984
}
986985

@@ -992,7 +991,7 @@ header .logo {
992991
vertical-align: middle;
993992
font-weight: 900;
994993
font-size: 10px;
995-
padding-top: 0px;
994+
padding-top: 0;
996995
color: var(--gray-300);
997996
}
998997

@@ -1081,7 +1080,7 @@ header .logo {
10811080
}
10821081

10831082
#breadcrumbs > ol {
1084-
margin: 5px 0px 0px 80px;
1083+
margin: 5px 0 0 80px;
10851084
white-space: normal;
10861085
}
10871086

@@ -1142,7 +1141,7 @@ header .logo {
11421141
text-decoration: none;
11431142
color: #444;
11441143
background: 0 0;
1145-
border-bottom: 0px;
1144+
border-bottom: 0;
11461145
}
11471146

11481147
.edit-page > .edit-page-icon:after {
@@ -1423,7 +1422,7 @@ article > h3 > code,
14231422
article > h4 > code,
14241423
article > h5 > code,
14251424
article > h6 > code {
1426-
padding-top: 0px;
1425+
padding-top: 0;
14271426
white-space: normal;
14281427
}
14291428

@@ -1456,7 +1455,7 @@ h6:hover .header-link {
14561455

14571456
/* Codeblocks */
14581457
pre {
1459-
border-radius: 0px;
1458+
border-radius: 0;
14601459
background: var(--gray-100);
14611460
box-shadow: none;
14621461
position: relative;
@@ -1470,7 +1469,7 @@ code, p code {
14701469
padding: 2px;
14711470
word-break: break-word;
14721471
white-space: pre-wrap;
1473-
border-radius: 0px;
1472+
border-radius: 0;
14741473
background: var(--gray-100);
14751474
box-shadow: none;
14761475
color: var(--gray-950);
@@ -1529,24 +1528,27 @@ li > code {
15291528
color: var(--green-700);
15301529
}
15311530

1532-
.copy-to-clipboard > .copy-to-clipboard-code {
1531+
pre > code {
15331532
margin: 0;
15341533
word-break: break-word;
15351534
white-space: break-spaces;
15361535
color: var(--CODEBLOCK-TEXT-COLOR);
15371536
font-family: Consolas,liberation mono,Menlo,Courier,monospace;
15381537
padding: 28px;
15391538
font-size: 1rem;
1540-
max-height: calc(17 * 1.8rem);
1539+
}
1540+
1541+
.code-long {
1542+
max-height: calc(15 * 1.8rem);
15411543
overflow: hidden;
15421544
}
15431545

1544-
.copy-to-clipboard:hover > .copy-to-clipboard-button {
1545-
display: flex;
1546+
.code-long.expanded {
1547+
max-height: unset;
15461548
}
15471549

1548-
.copy-to-clipboard > .copy-to-clipboard-code.expanded {
1549-
max-height: 100%;
1550+
.copy-to-clipboard:hover > .copy-to-clipboard-button {
1551+
display: flex;
15501552
}
15511553

15521554
pre > .code-show-more {
@@ -1562,7 +1564,7 @@ pre > .code-show-more {
15621564
position: absolute;
15631565
bottom: 12px;
15641566
right: 10px;
1565-
letter-spacing: 0px;
1567+
letter-spacing: 0;
15661568
}
15671569

15681570
pre > .code-show-more:hover{
@@ -1675,7 +1677,7 @@ div.box.security > .box-content-container > .box-content > i {
16751677
}
16761678

16771679
div > .box-content-container {
1678-
padding: 0px 0px 0px 12px;
1680+
padding: 0 0 0 12px;
16791681
}
16801682

16811683
.box-text {
@@ -1772,8 +1774,8 @@ blockquote p {
17721774

17731775
display: flex;
17741776
flex-direction: column;
1775-
margin: 0px;
1776-
padding: 0px;
1777+
margin: 0;
1778+
padding: 0;
17771779
overflow: hidden;
17781780
letter-spacing: normal;
17791781
color: var(--fg);
@@ -1969,15 +1971,15 @@ details[open] > .openapi-prop::before {
19691971
display: inline-block;
19701972
padding: 6px 16px;
19711973
font-size: var(--font-size-small);
1972-
outline: 0px;
1974+
outline: 0;
19731975
line-height: 1;
19741976
text-align: center;
19751977
white-space: nowrap;
19761978
background-color: transparent;
19771979
transition: background-color 0.2s ease 0s;
19781980
user-select: none;
19791981
cursor: pointer;
1980-
box-shadow: rgb(0 0 0 / 12%) 0px 1px 3px, rgb(0 0 0 / 24%) 0px 1px 2px;
1982+
box-shadow: rgb(0 0 0 / 12%) 0 1px 3px, rgb(0 0 0 / 24%) 0 1px 2px;
19811983
}
19821984

19831985
.response-code.clicked {
@@ -2033,7 +2035,7 @@ nav.pagination .next {
20332035
}
20342036

20352037
.nav-prev > i {
2036-
padding: 17px 15px 0px 0px;
2038+
padding: 17px 15px 0 0;
20372039
}
20382040

20392041
.nav-prev:hover,
@@ -2051,7 +2053,7 @@ nav.pagination .next {
20512053
}
20522054

20532055
.nav-next > i {
2054-
padding: 17px 0px 0px 15px;
2056+
padding: 17px 0 0 15px;
20552057
}
20562058
/* */
20572059

@@ -2148,7 +2150,7 @@ nav.pagination .next {
21482150
display: flex;
21492151
align-items: center;
21502152
flex-wrap: wrap;
2151-
padding: 20px 0px;
2153+
padding: 20px 0;
21522154
border-radius: 4px;
21532155
margin-bottom: 36px;
21542156
background: url("/images/bottom-cta-background.jpg") no-repeat center center;

site/themes/arangodb-docs-theme/static/js/codeblocks.js

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,30 @@
1+
function addShowMoreButton(parentElem) {
2+
$(parentElem).find("pre > code").each(function() {
3+
code = $(this);
4+
// n-times line-height * root em, larger than to-be-applied max-height to always reveal some lines
5+
// False for currently collapsed code ("Show output" with display: none)
6+
if (!code.hasClass('code-long') && code.prop('scrollHeight') > 20 * 1.8 * 16 ) {
7+
code.addClass('code-long');
8+
var showMore = $('<button class="code-show-more"></button>');
9+
code.after(showMore);
10+
}
11+
});
12+
}
13+
114
function initCopyToClipboard() {
2-
$('code').each(function() {
3-
var code = $(this);
4-
var parent = code.parent();
5-
var inPre = parent.prop('tagName') == 'PRE';
15+
$('article pre > code').each(function() {
16+
code = $(this);
17+
code.addClass('copy-to-clipboard-code');
18+
code.parent().addClass( 'copy-to-clipboard' );
619

7-
if (inPre) {
8-
code.addClass('copy-to-clipboard-code');
9-
if( inPre ){
10-
parent.addClass( 'copy-to-clipboard' );
11-
}
12-
else{
13-
code.replaceWith($('<span/>', {'class': 'copy-to-clipboard'}).append(code.clone() ));
14-
code = parent.children('.copy-to-clipboard').last().children('.copy-to-clipboard-code');
15-
}
16-
var span = $('<span>').addClass("copy-to-clipboard-button").attr("title", window.T_Copy_to_clipboard).attr("onclick", "copyCode(event);")
17-
code.before(span);
18-
if ( code.text().split(/\r\n|\r|\n/).length > 16) {
19-
var showMore = $('<button class="code-show-more"></button>')
20-
code.after(showMore);
21-
}
20+
var span = $('<span>').addClass("copy-to-clipboard-button").attr("title", window.T_Copy_to_clipboard).attr("onclick", "copyCode(event);")
21+
code.before(span);
2222

23-
span.mouseleave( function() {
24-
setTimeout(function(){
25-
span.removeClass("tooltipped");
26-
},1000);
23+
span.mouseleave(function() {
24+
setTimeout(function() {
25+
span.removeClass("tooltipped");
26+
}, 1000);
2727
});
28-
}
2928
});
3029
}
3130

0 commit comments

Comments
 (0)