Skip to content

Commit 3a73e85

Browse files
authored
Merge pull request #1 from colleenmcginnis/sticky-otp-cmcg
[sticky otp/toc] Builds on elastic/docs elastic#2478
2 parents cee57ad + dd2b376 commit 3a73e85

File tree

7 files changed

+127
-49
lines changed

7 files changed

+127
-49
lines changed

resources/web/docs_js/index.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import "../../../../../node_modules/url-search-params-polyfill";
2222
export function init_headers(sticky_content, lang_strings) {
2323
// Add on-this-page block
2424
var this_page = $('<div id="this_page"></div>').prependTo(sticky_content);
25-
this_page.append('<p id="otp">' + lang_strings('On this page') + '</p>');
25+
this_page.append('<p id="otp" class="aside-heading">' + lang_strings('On this page') + '</p>');
2626
var ul = $('<ul></ul>').appendTo(this_page);
2727
var items = 0;
2828
var baseHeadingLevel = 0;
@@ -57,7 +57,7 @@ export function init_headers(sticky_content, lang_strings) {
5757
.remove();
5858
var text = title_container.html();
5959
const adjustedLevel = hLevel - baseHeadingLevel;
60-
const li = '<li id="otp-text" class="heading-level-' + adjustedLevel + '"><a href="#' + this.id + '">' + text + '</a></li>';
60+
const li = '<li id="otp-text-' + i + '" class="otp-text heading-level-' + adjustedLevel + '"><a href="#' + this.id + '">' + text + '</a></li>';
6161
ul.append(li);
6262
}
6363
}
@@ -171,16 +171,24 @@ function init_toc(lang_strings) {
171171
}
172172

173173
function highlight_otp() {
174+
let visibileHeadings = []
174175
const observer = new IntersectionObserver(entries => {
175176
entries.forEach(entry => {
176177
const id = entry.target.getAttribute('id');
177-
const element = document.querySelector(`#sticky_content #this_page a[href="#${id}"]`);
178-
178+
let element = document.querySelector(`#sticky_content #this_page a[href="#${id}"]`);
179+
let itemId = $(element).parent().attr('id')
179180
if (entry.intersectionRatio > 0){
180-
console.log("ir", entry.intersectionRatio)
181-
element.classList.add('active');
181+
visibileHeadings.push(itemId);
182182
} else {
183-
element.classList.remove('active');
183+
const position = visibileHeadings.indexOf(itemId);
184+
visibileHeadings.splice(position, position + 1)
185+
}
186+
if (visibileHeadings.length > 0) {
187+
visibileHeadings.sort()
188+
// Remove existing active classes
189+
$('a.active').removeClass("active");
190+
// Add active class to the first visible heading
191+
$('#' + visibileHeadings[0] + ' > a').addClass('active')
184192
}
185193
})
186194
})

resources/web/style/base_styles.pcss

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,57 @@
3131
margin-bottom: 1.15em;
3232
}
3333

34-
#otp {
34+
.content-container {
35+
width: 100%;
36+
padding-right: 15px;
37+
padding-left: 15px;
38+
margin-right: auto;
39+
margin-left: auto;
40+
@media screen and (min-width: 769px) {
41+
max-width: 760px;
42+
}
43+
@media screen and (min-width: 992px) {
44+
padding: 0px 10px;
45+
max-width: 972px;
46+
}
47+
@media screen and (min-width: 1200px) {
48+
padding: 0px 20px;
49+
max-width: 1160px;
50+
}
51+
@media screen and (min-width: 1560px) {
52+
max-width: 1500px;
53+
}
54+
}
55+
56+
.h-almost-full {
57+
height: 95vh;
58+
}
59+
60+
#this_page {
61+
display: block;
62+
border-bottom: 1px solid #dee2e6;
63+
height:60vh;
64+
overflow: scroll;
65+
@media screen and (max-width: 992px) {
66+
display: none;
67+
}
68+
}
69+
70+
#left_col {
71+
overflow: scroll;
72+
}
73+
74+
.aside-heading {
3575
font-weight: 600;
36-
padding-top: 20px;
37-
margin-top: 10px;
76+
margin-top: 20px;
3877
margin-bottom: 10px;
39-
font-size: 85%;
4078
}
4179

42-
#otp-text {
43-
font-size: 85%;
80+
.media-type {
81+
opacity: 0.6;
82+
text-transform: uppercase;
83+
font-size: 80%;
84+
font-weight: 400;
85+
margin-bottom: 0px;
4486
}
4587
}

resources/web/style/link.pcss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#guide {
22
a {
3-
color: #00a9e5;
3+
color: #0077CC;
44
font-weight: normal;
55
text-decoration: none;
66
outline: none;

resources/web/style/on_this_page.pcss

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,22 @@
55

66
.heading-level-1 {
77
display: block;
8-
padding-left: 1.5em !important;
8+
a {
9+
font-size: 0.85rem;
10+
}
911
}
1012

1113
.heading-level-2 {
1214
display: block;
13-
padding-left: 3em !important;
15+
padding-left: 1em !important;
1416
}
1517

1618
.heading-level-3 {
1719
display: block;
1820
padding-left: 4.5em !important;
1921
}
22+
23+
.otp-text {
24+
font-size: 85%;
25+
}
2026
}

resources/web/style/rtpcontainer.pcss

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
* on the rtpcontainer in general. */
66
#rtpcontainer {
77
.mktg-promo {
8-
margin: 55px 0 30px;
9-
padding: 32px;
10-
border: 1px solid #d4dae5;
8+
padding: 12px;
119
}
1210
h3 {
1311
margin: 5px 0;

resources/web/style/toc.pcss

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
#guide {
2+
.book-title {
3+
font-size: 120%;
4+
font-weight: 600;
5+
margin: 20px 0px 20px 20px;
6+
}
27
.toc {
38
ul {
49
margin: 0 0 1em 0;
510
padding: 0;
6-
border: 1px solid #ddd;
711
ul {
812
/* Hide all sub-toc elements by default. See rules with `.show` that
913
* show specific sub-toc elements. */
@@ -14,6 +18,9 @@
1418
margin: 0;
1519
padding: 0;
1620
list-style: none;
21+
a {
22+
color: rgb(52, 55, 65) !important;
23+
}
1724
ul {
1825
border: none;
1926
}
@@ -30,21 +37,20 @@
3037
}
3138

3239
.collapsible.show {
40+
3341
> ul {
3442
display: block;
3543
}
3644
> span {
37-
background-image: inline("img/minus.png");
38-
background-color: white;
45+
background-image: url('data:image/svg+xml;utf8,<svg width="16" height="16" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg" class="euiIcon euiIcon--small euiIcon--subdued euiIcon-isLoaded" focusable="false" role="img" aria-hidden="true"><path fill-rule="non-zero" d="M8 7V3.5a.5.5 0 00-1 0V7H3.5a.5.5 0 000 1H7v3.5a.5.5 0 101 0V8h3.5a.5.5 0 100-1H8zm-.5 8a7.5 7.5 0 110-15 7.5 7.5 0 010 15z"></path></svg>');
3946
border-bottom: 1px solid white;
4047
}
4148
}
4249
.collapsible {
4350
> span {
4451
background-repeat: no-repeat;
45-
background-image: inline("img/plus.png");
52+
background-image: url('data:image/svg+xml;utf8,<svg width="16" height="16" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg" class="euiIcon euiIcon--small euiIcon--subdued euiIcon-isLoaded" focusable="false" role="img" aria-hidden="true"><path fill-rule="non-zero" d="M8 7h3.5a.5.5 0 110 1H8v3.5a.5.5 0 11-1 0V8H3.5a.5.5 0 010-1H7V3.5a.5.5 0 011 0V7zm-.5-7C11.636 0 15 3.364 15 7.5S11.636 15 7.5 15 0 11.636 0 7.5 3.364 0 7.5 0zm0 .882a6.618 6.618 0 100 13.236A6.618 6.618 0 007.5.882z"></path></svg>');
4653
&:hover {
47-
background-color: #fafafa;
4854
cursor: pointer;
4955
}
5056
}
@@ -53,15 +59,13 @@
5359
/* Customize each level of the TOC, mostly so it looks "indented". */
5460
> li {
5561
> span {
56-
background-color: #efefef;
57-
border-bottom: 1px solid #ddd;
5862
font-size: 1em;
5963
background-position: 0 11px;
6064
padding-left: 20px;
6165
}
6266
> ul > li {
6367
> span {
64-
padding-left: 40px;
68+
padding-left: 30px;
6569
background-position: 20px 8px;
6670
}
6771
> ul > li {
@@ -107,14 +111,22 @@
107111
}
108112

109113
#book_title {
110-
color: #2b4590;
114+
color: rgb(52, 55, 65);
115+
font-weight: 600;
116+
display: block;
117+
border-bottom-width: 1px;
118+
border-bottom-style: solid;
119+
border-bottom-color: #dee2e6;
111120

112121
select {
113-
background-color: #fcfcfc;
114-
border: none;
115-
margin-left: 1px;
116-
color: #2b4590;
117-
width: 150px;
122+
width: 100%;
123+
display: block;
124+
color: #495057;
125+
background-color: #fff;
126+
border: 1px solid #495057;
127+
border-radius: 5px;
128+
padding: 3px;
129+
margin-top: 6px;
118130
}
119131
#other_versions {
120132
/* We'll show it if you click "other versions". */

resources/web/template.html

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -82,32 +82,44 @@
8282
<div class="content-wrapper">
8383

8484
<section id="guide" <!-- DOCS LANG -->>
85-
<div class="container">
85+
<div class="content-container">
8686
<div class="row">
87-
88-
<div class="col-12 order-2 col-sm-3 order-sm-1 col-md-3 order-md-1" id="left_col">
89-
<div id="rtpcontainer" style="display: block;">
90-
<div class="mktg-promo">
91-
<h3>Most Popular</h3>
92-
<ul class="icons">
93-
<li class="icon-elasticsearch-white"><a href="https://www.elastic.co/webinars/getting-started-elasticsearch?baymax=default&elektra=docs&storm=top-video">Get Started with Elasticsearch: Video</a></li>
94-
<li class="icon-kibana-white"><a href="https://www.elastic.co/webinars/getting-started-kibana?baymax=default&elektra=docs&storm=top-video">Intro to Kibana: Video</a></li>
95-
<li class="icon-logstash-white"><a href="https://www.elastic.co/webinars/introduction-elk-stack?baymax=default&elektra=docs&storm=top-video">ELK for Logs & Metrics: Video</a></li>
96-
</ul>
97-
</div>
98-
</div>
87+
<div class="col-12 order-2 col-sm-3 order-sm-1 col-md-3 order-md-1 col-lg-3 sticky-top h-almost-full" id="left_col">
9988
<!-- The TOC is appended here -->
10089
</div>
10190

102-
<div class="col-12 order-1 col-sm-9 order-sm-2 col-md-7 order-md-2 guide-section">
91+
<div class="col-12 order-1 col-sm-9 col-lg-7 order-lg-2 guide-section">
10392
<!-- start body -->
10493
<!-- DOCS BODY -->
10594
<!-- end body -->
10695
</div>
10796

108-
<div class="col-12 order-3 col-sm-12 order-sm-3 col-md-2 order-md-3" id="right_col">
109-
<div class="sticky-top" id="sticky_content">
97+
<div class="col-12 order-3 col-lg-2 order-lg-3 sticky-top h-almost-full" id="right_col">
98+
<div id="sticky_content">
11099
<!-- The OTP is appended here -->
100+
<div id="rtpcontainer">
101+
<div class="mktg-promo">
102+
<p class="aside-heading">Most Popular</p>
103+
<div class="pb-2">
104+
<p class="media-type">Video</p>
105+
<a href="https://www.elastic.co/webinars/getting-started-elasticsearch?baymax=default&elektra=docs&storm=top-video">
106+
<p class="mb-0">Get Started with Elasticsearch</p>
107+
</a>
108+
</div>
109+
<div class="pb-2">
110+
<p class="media-type">Video</p>
111+
<a href="https://www.elastic.co/webinars/getting-started-kibana?baymax=default&elektra=docs&storm=top-video">
112+
<p class="mb-0">Intro to Kibana</p>
113+
</a>
114+
</div>
115+
<div class="pb-2">
116+
<p class="media-type">Video</p>
117+
<a href="https://www.elastic.co/webinars/introduction-elk-stack?baymax=default&elektra=docs&storm=top-video">
118+
<p class="mb-0">ELK for Logs & Metrics</p>
119+
</a>
120+
</div>
121+
</div>
122+
</div>
111123
</div>
112124
</div>
113125
</div>

0 commit comments

Comments
 (0)