Skip to content

Commit f9e3fd3

Browse files
committed
Dark and Ligth mode skin is now easily switchable
- mode can be switched from cookies (settings UI is not added yet, a separate GitHub issue has been added for it already) - fixed cases if masthead is turned off completely in the site config, the search must work nicely (with the hotkey) even if it is turned off - added support for tiny tooltips (similar to the classic short ones) that can have predefined text - added support for static tooltips (that remain steady even if the content is scrolled) - added some enhancements around hiding the tooltip Signed-off-by: Hofi <hofione@gmail.com> Signed-off-by: Hofi <hofione@gmail.com>
1 parent aeb54f7 commit f9e3fd3

File tree

11 files changed

+420
-155
lines changed

11 files changed

+420
-155
lines changed

_includes/globals.html

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
<script async="false">
66

77
const searchEnabled = {% if site.search == true %} true {% else %} false {% endif %};
8-
const searchFromMastHead = {% if site.search_from_masthead == true %} true {% else %} false {% endif %};
8+
const hasMastHead = {% if site.masthead != false %} true {% else %} false {% endif %};
9+
const searchFromMastHead = {% if site.masthead != false and site.search_from_masthead == true %} true {% else %} false {% endif %};
910

1011
const docRoot = '{{ site.baseurl }}';
1112

@@ -40,4 +41,33 @@
4041
return defaultValue;
4142
}
4243

44+
function compareDOMRect(rect1, rect2) {
45+
return {
46+
top: rect1.top === rect2.top,
47+
right: rect1.right === rect2.right,
48+
bottom: rect1.bottom === rect2.bottom,
49+
left: rect1.left === rect2.left,
50+
width: rect1.width === rect2.width,
51+
height: rect1.height === rect2.height
52+
};
53+
}
54+
55+
function getElementPositionRelativeToRoot(element) {
56+
var rect = element.getBoundingClientRect();
57+
58+
// Calculate the position relative to the document
59+
var scrollLeft = window.pageXOffset || document.documentElement.scrollLeft;
60+
var scrollTop = window.pageYOffset || document.documentElement.scrollTop;
61+
62+
var position = {
63+
top: rect.top + scrollTop,
64+
left: rect.left + scrollLeft
65+
};
66+
return position;
67+
}
68+
69+
function comparePositions(pos1, pos2) {
70+
return pos1.top === pos2.top && pos1.left === pos2.left;
71+
}
72+
4373
</script>

_includes/masthead.html

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
{% capture logo_path %}{{ site.logo }}{% endcapture %}
22

33
<div class="masthead {% if site.masthead.sticky == true %}sticky{% endif %}">
4+
5+
{% comment %}<!--
6+
TODO: Far from perfect but working solution for now to have static (none moving) tooltips
7+
It's satisfying now as
8+
- we do have only in the masthead such controls
9+
- eliminates the need to add a real tooltip to each of the elements that require such a tooltip
10+
- it aids the detection of wether the tooltip needs to be hiding (e.g on tooltip movements caused by scrolling)
11+
-->{% endcomment %}
12+
<span id="tooltip" class="tooltip"></span>
13+
<span id="tooltipRenderer" class="tooltip visible"></span>
14+
415
<div class="masthead__inner-wrap">
516
<div class="masthead__menu">
617
<nav id="site-nav" class="greedy-nav">
@@ -36,11 +47,11 @@
3647
{% if site.search == true %}
3748
{% comment %}<!-- search__toggle is kept for backward compatibility -->{% endcomment %}
3849
<label class="sr-only" for="search-button">
39-
{{ site.data.ui-text[site.locale].search_label_text | default: 'Toggle search (Shift + Ctrl + F or ESC to close)' }}
50+
{{ site.data.ui-text[site.locale].search_label_text | default: 'Toggle search (`Shift + Ctrl + F`, ESC to close)' }}
4051
</label>
41-
<button id="search-button" class="masthead_button search__toggle" type="button">
42-
<span id="search_hint" class="">{{ site.data.ui-text[site.locale].search_label | default: "Toggle search (Shift + Ctrl + F or ESC to close)" }}</span>
43-
<i class="masthead_button_icon fas fa-search" style="font-size: 120%;"></i>
52+
<button id="search-button" class="masthead_button search__toggle" type="button" >
53+
<i class="masthead_button_icon content-tooltip tooltip-align-center text-content-tooltip fas fa-search" style="font-size: 120%;"
54+
data-tooltip-text="{{ site.data.ui-text[site.locale].search_label | default: 'Toggle search (`Shift + Ctrl + F`, ESC to close)' }}"></i>
4455
</button>
4556
{% endif %}
4657

_includes/search/search_form.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
{%- case search_provider -%}
44

55
{%- when "lunr" -%}
6-
{% if site.search_from_masthead == false %}
6+
{% if site.search_from_masthead == false or site.masthead == false %}
77
{% include /search/search_input.html %}
88
{% endif %}
9-
<div id="results" class="results {% if site.search_from_masthead %}from-masthead{% else %}from-search-content{% endif %}"></div>
9+
<div id="results" class="results {% if site.search_from_masthead and site.masthead != false %}from-masthead{% else %}from-search-content{% endif %}"></div>
1010

1111
{%- when "google" -%}
1212
{% include /search/search_input.html %}

_includes/search/search_input.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
{%- case search_provider -%}
33

44
{%- when "lunr" -%}
5-
<form class="search-content__form {% if site.search_from_masthead %}from-masthead{% else %}from-search-content{% endif %}"
5+
<form class="search-content__form {% if site.search_from_masthead and site.masthead != false %}from-masthead{% else %}from-search-content{% endif %}"
66
onkeydown="return event.key != 'Enter';" role="search">
77
<label class="sr-only" for="search">
88
{{ site.data.ui-text[site.locale].search_label_text | default: 'Enter your search term...' }}
99
</label>
10-
<input type="search" id="search" class="search-input {% if site.search_from_masthead %}from-masthead{% else %}from-search-content{% endif %}"
10+
<input type="search" id="search" class="search-input {% if site.search_from_masthead and site.masthead != false %}from-masthead{% else %}from-search-content{% endif %}"
1111
placeholder="{{ site.data.ui-text[site.locale].search_placeholder_text | default: 'Enter your search term...' }}" />
1212
<a class="search-help content-tooltip tooltip-align-center full-content-tooltip nav-link fas fa-info-circle" href="{{ '/lunr_search_help.html' | relative_url }}"></a>
1313
</form>

0 commit comments

Comments
 (0)