Skip to content

Commit 0b3f14f

Browse files
committed
fix: sidebar movement after clicking a link
1 parent 151889b commit 0b3f14f

File tree

2 files changed

+35
-108
lines changed

2 files changed

+35
-108
lines changed

wiki/public/js/wiki.js

+12-13
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,16 @@ window.Wiki = class Wiki {
99
if ($(this).data("route") == page_href) {
1010
$(this).addClass(active_class);
1111
$(this).find("a").addClass(active_class);
12+
13+
const element = $(this);
14+
setTimeout(function () {
15+
const topOffset = element.position().top;
16+
$(".doc-sidebar .web-sidebar")
17+
.get(0)
18+
.scrollTo(0, topOffset - 200);
19+
}, 50);
1220
}
1321
});
14-
// scroll the active sidebar item into view
15-
let active_sidebar_item = $(".doc-sidebar .sidebar-item.active");
16-
if (active_sidebar_item.length > 0) {
17-
setTimeout(function () {
18-
let position =
19-
active_sidebar_item.offset().top - $(".doc-sidebar").offset().top;
20-
$(".doc-sidebar .web-sidebar").get(0).scrollTo(0, position);
21-
}, 50);
22-
}
2322
}
2423

2524
toggle_sidebar(event) {
@@ -32,7 +31,7 @@ window.Wiki = class Wiki {
3231
$(".doc-sidebar,.web-sidebar").on(
3332
"click",
3433
".collapsible",
35-
this.toggle_sidebar,
34+
this.toggle_sidebar
3635
);
3736

3837
$(".sidebar-item.active")
@@ -46,7 +45,7 @@ window.Wiki = class Wiki {
4645

4746
set_last_updated_date() {
4847
const lastUpdatedDate = frappe.datetime.prettyDate(
49-
$(".user-contributions").data("date"),
48+
$(".user-contributions").data("date")
5049
);
5150
$(".user-contributions").append(`last updated ${lastUpdatedDate}`);
5251
}
@@ -57,7 +56,7 @@ window.Wiki = class Wiki {
5756
const src = $(".navbar-brand img").attr("src");
5857
if (
5958
!["{{ light_mode_logo }}", "{{ dark_mode_logo }}", "None", ""].includes(
60-
altSrc,
59+
altSrc
6160
)
6261
) {
6362
$(".navbar-brand img").attr("src", altSrc);
@@ -117,7 +116,7 @@ window.Wiki = class Wiki {
117116
$("pre code")
118117
.parent("pre")
119118
.prepend(
120-
`<button title="Copy Code" class="btn copy-btn" data-toggle="tooltip"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-clipboard"><path d="M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2"></path><rect x="8" y="2" width="8" height="4" rx="1" ry="1"></rect></svg></button>`,
119+
`<button title="Copy Code" class="btn copy-btn" data-toggle="tooltip"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-clipboard"><path d="M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2"></path><rect x="8" y="2" width="8" height="4" rx="1" ry="1"></rect></svg></button>`
121120
);
122121

123122
$(".copy-btn").on("click", function () {
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
{% macro render_sidebar_item(item) %}
2-
<li
3-
class="sidebar-item sidebar-group-item {% if item.route == current_route %}sidebar-item-active{% endif %}"
4-
data-type="{{item.type}}"
5-
data-name="{{item.name}}"
6-
data-title="{{item.title or item.name}}"
7-
data-group-name="{{item.group_name or 'sidebar-item'}}"
8-
data-route="{{ item.route }}"
9-
>
2+
<li class="sidebar-item sidebar-group-item {% if item.route == current_route %}sidebar-item-active{% endif %}"
3+
data-type="{{item.type}}" data-name="{{item.name}}" data-title="{{item.title or item.name}}"
4+
data-group-name="{{item.group_name or 'sidebar-item'}}" data-route="{{ item.route }}">
105
<div>
116
<a class="text-sm sidebar-group-item-title" href="/{{ item.route }}">
127
{{ item.title or item.name }}
@@ -17,119 +12,54 @@
1712
sidebar_items | len > 0 -%}
1813
<ul class="list-unstyled sidebar-group-list" style="min-height: 20px">
1914
{% for sidebar_group in sidebar_items -%}
20-
<li
21-
class="sidebar-group"
22-
data-type="Wiki Sidebar"
23-
data-title="{{sidebar_group}}"
24-
>
15+
<li class="sidebar-group" data-type="Wiki Sidebar" data-title="{{sidebar_group}}">
2516
<div class="sidebar-group-container collapsible">
2617
<span class="sidebar-group-title">{{ sidebar_group }}</span>
27-
<span
28-
class="add-sidebar-page hide"
29-
data-group-name="{{ sidebar_group }}"
30-
data-toggle="tooltip"
31-
data-placement="top"
32-
title="New Wiki Page in the group {{ sidebar_group }}"
33-
>
34-
<svg
35-
xmlns="http://www.w3.org/2000/svg"
36-
width="16"
37-
height="20"
38-
viewBox="0 0 24 24"
39-
fill="none"
40-
stroke="currentColor"
41-
stroke-width="2"
42-
stroke-linecap="round"
43-
stroke-linejoin="round"
44-
class="feather feather-plus"
45-
>
18+
<span class="add-sidebar-page hide" data-group-name="{{ sidebar_group }}" data-toggle="tooltip"
19+
data-placement="top" title="New Wiki Page in the group {{ sidebar_group }}">
20+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="20" viewBox="0 0 24 24" fill="none"
21+
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
22+
class="feather feather-plus">
4623
<line x1="12" y1="5" x2="12" y2="19"></line>
4724
<line x1="5" y1="12" x2="19" y2="12"></line>
4825
</svg>
4926
</span>
5027
<span
51-
class="drop-icon {% if collapse_sidebar_groups and sidebar_group != active_sidebar_group %}rotate{% endif %}"
52-
>
53-
<svg
54-
viewBox="0 0 24 24"
55-
width="16"
56-
height="16"
57-
stroke="currentColor"
58-
stroke-width="2"
59-
fill="none"
60-
stroke-linecap="round"
61-
stroke-linejoin="round"
62-
class="css-i6dzq1"
63-
>
28+
class="drop-icon {% if collapse_sidebar_groups and sidebar_group != active_sidebar_group %}rotate{% endif %}">
29+
<svg viewBox="0 0 24 24" width="16" height="16" stroke="currentColor" stroke-width="2" fill="none"
30+
stroke-linecap="round" stroke-linejoin="round" class="css-i6dzq1">
6431
<polyline points="6 9 12 15 18 9"></polyline>
6532
</svg>
6633
</span>
6734
</div>
68-
<ul
69-
class="list-unstyled sidebar-group-item-list {% if collapse_sidebar_groups and sidebar_group != active_sidebar_group %}hidden{% endif %}"
70-
style="min-height: 20px"
71-
>
35+
<ul class="list-unstyled sidebar-group-item-list hidden" style="min-height: 20px">
7236
{% for item in sidebar_items[sidebar_group] -%} {{
7337
render_sidebar_item(item) }} {%- endfor %}
7438
</ul>
7539
</li>
7640
{%- endfor %}
7741
</ul>
7842
<div class="d-none d-lg-block sidebar-options">
79-
<div
80-
class="sidebar-edit-mode-btn text-muted"
81-
data-toggle="tooltip"
82-
data-placement="top"
83-
title="Changes to sidebar will be automatically saved"
84-
>
85-
<svg
86-
xmlns="http://www.w3.org/2000/svg"
87-
width="16"
88-
height="16"
89-
viewBox="0 0 24 24"
90-
fill="none"
91-
stroke="currentColor"
92-
stroke-width="2"
93-
stroke-linecap="round"
94-
stroke-linejoin="round"
95-
class="feather feather-edit-3"
96-
>
43+
<div class="sidebar-edit-mode-btn text-muted" data-toggle="tooltip" data-placement="top"
44+
title="Changes to sidebar will be automatically saved">
45+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor"
46+
stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-edit-3">
9747
<path d="M12 20h9"></path>
9848
<path d="M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z"></path>
9949
</svg>
10050
<span class="small">Edit Sidebar</span>
10151
</div>
10252
<div class="add-sidebar-group text-muted hide">
103-
<svg
104-
xmlns="http://www.w3.org/2000/svg"
105-
width="16"
106-
height="16"
107-
viewBox="0 0 24 24"
108-
fill="none"
109-
stroke="currentColor"
110-
stroke-width="2"
111-
stroke-linecap="round"
112-
stroke-linejoin="round"
113-
class="feather feather-plus"
114-
>
53+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor"
54+
stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-plus">
11555
<line x1="12" y1="5" x2="12" y2="19"></line>
11656
<line x1="5" y1="12" x2="19" y2="12"></line>
11757
</svg>
11858
<span class="small">Add Group</span>
11959
</div>
12060
<div class="sidebar-view-mode-btn text-muted hide">
121-
<svg
122-
xmlns="http://www.w3.org/2000/svg"
123-
width="16"
124-
height="16"
125-
viewBox="0 0 24 24"
126-
fill="none"
127-
stroke="currentColor"
128-
stroke-width="2"
129-
stroke-linecap="round"
130-
stroke-linejoin="round"
131-
class="feather feather-sidebar"
132-
>
61+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor"
62+
stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-sidebar">
13363
<rect x="3" y="3" width="18" height="18" rx="2" ry="2"></rect>
13464
<line x1="9" y1="3" x2="9" y2="21"></line>
13565
</svg>
@@ -139,13 +69,11 @@
13969
{%- endif -%} {% endmacro %} {% macro my_account() %}
14070
<ul class="list-unstyled management">
14171
<li class="sidebar-item">
142-
<a class="new-wiki-page text-muted" href="placeholder_link"
143-
>{{ _("Add a new page") }}</a
144-
>
72+
<a class="new-wiki-page text-muted" href="placeholder_link">{{ _("Add a new page") }}</a>
14573
</li>
14674
</ul>
14775
{% endmacro %}
14876

14977
<div class="web-sidebar" data-name="{{wiki_search_scope}}">
15078
<div class="sidebar-items">{{ render_sidebar_items(sidebar_items) }}</div>
151-
</div>
79+
</div>

0 commit comments

Comments
 (0)