Skip to content

Commit

Permalink
Merge pull request #52 from giulong/docs/search
Browse files Browse the repository at this point in the history
Docs/search
  • Loading branch information
giulong authored Dec 2, 2023
2 parents 431b577 + 506c679 commit 20e81a3
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/_includes/topButton.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<button onclick="topFunction()" id="topButton" title="Go to top">Top</button>
2 changes: 2 additions & 0 deletions docs/_layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ <h1>{{ site.title | default: site.github.repository_name }}</h1>

{% include search.html %}
{{ content }}
{% include topButton.html %}

</section>
</div>
Expand All @@ -51,5 +52,6 @@ <h1>{{ site.title | default: site.github.repository_name }}</h1>
<script src="assets/scripts/search.js"></script>
<script src="assets/scripts/copyCode.js"></script>
<script src="assets/scripts/openImage.js"></script>
<script src="assets/scripts/topButton.js"></script>
</body>
</html>
21 changes: 21 additions & 0 deletions docs/assets/css/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,24 @@ img.copy-icon {
width: 16px;
vertical-align: bottom;
}

#topButton {
display: none;
position: fixed;
bottom: 15px;
right: 15px;
z-index: 99;
border: 1px solid #444;
outline: none;
background-color: #3A3C42;
color: white;
cursor: pointer;
padding: 10px;
border-radius: 5px;
font-size: 14px;
}

#topButton:hover {
background-color: #555;
box-shadow: rgba(0, 0, 0, 0.2) 0 0 0 1px, rgba(0, 0, 0, 0.45) 0 3px 10px;
}
3 changes: 3 additions & 0 deletions docs/assets/scripts/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const resultsContainer = document.getElementById('results-container');
const noResult = document.createElement('li');
const searchContainerTop = searchContainer.getBoundingClientRect().top - 5;
const section = document.querySelectorAll('section')[0];
const topButton = document.getElementById("topButton");

noResult.innerText = 'No results'
noResult.setAttribute('id', 'no-results');
Expand Down Expand Up @@ -36,9 +37,11 @@ function stickyHeader() {
if (window.pageYOffset > searchContainerTop) {
searchContainer.classList.add('sticky');
section.classList.add('sticky-section');
topButton.style.display = 'block';
} else {
searchContainer.classList.remove('sticky');
section.classList.remove('sticky-section');
topButton.style.display = 'none';
}
}

Expand Down
4 changes: 4 additions & 0 deletions docs/assets/scripts/topButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function topFunction() {
document.body.scrollTop = 0; // For Safari
document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera
}

0 comments on commit 20e81a3

Please sign in to comment.