Skip to content

Commit fc735c4

Browse files
committed
Remove awful scrolling code
God bless position: sticky
1 parent 942ed0f commit fc735c4

File tree

2 files changed

+27
-110
lines changed

2 files changed

+27
-110
lines changed

css/kunai/site/sidebar.css

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ main[role="main"] .kunai-sidebar.force-legacy {
103103
}
104104
}
105105

106+
ul, li {
107+
box-sizing: border-box;
108+
}
109+
106110
.cr-index {
107111
display: flex;
108112
flex-basis: 100%;
@@ -165,8 +169,6 @@ main[role="main"] .kunai-sidebar.force-legacy {
165169
overflow: hidden;
166170

167171
.kunai-branch {
168-
overflow: hidden;
169-
170172
margin: .2rem 0 0 0;
171173
padding: 0;
172174

@@ -205,6 +207,8 @@ main[role="main"] .kunai-sidebar.force-legacy {
205207

206208
> .expandbar {
207209
display: inline-flex;
210+
position: sticky;
211+
top: -1px;
208212
}
209213

210214

@@ -249,9 +253,11 @@ main[role="main"] .kunai-sidebar.force-legacy {
249253
}
250254

251255
&.expanded {
252-
> .expandbar > .expander {
253-
&:before {
254-
transform: rotate(45deg);
256+
> .expandbar {
257+
> .expander {
258+
&:before {
259+
transform: rotate(45deg);
260+
}
255261
}
256262
}
257263
}
@@ -358,37 +364,6 @@ main[role="main"] .kunai-sidebar.force-legacy {
358364

359365
position: relative;
360366
}
361-
362-
&.scrolling {
363-
> .content > .kunai-branch > ul.branch {
364-
// margin-top: 4em;
365-
366-
> li.preview.expanded {
367-
> .expandbar {
368-
position: absolute;
369-
left: 0;
370-
width: 100%;
371-
372-
// box-shadow: 0 2px 20px -2px rgba(20, 20, 20, 0.3);
373-
// background-color: #FBFBFB;
374-
375-
background-color: rgba(220, 220, 240, 0.5);
376-
377-
> a {
378-
background: rgba(250, 250, 255, 1);
379-
font-weight: bold;
380-
}
381-
382-
.cr-index {
383-
ul.badges {
384-
display: none;
385-
}
386-
}
387-
}
388-
}
389-
}
390-
}
391-
392367
}
393368
}
394369
}
@@ -534,6 +509,22 @@ main[role="main"] .kunai-sidebar.force-legacy {
534509

535510
> .expandbar {
536511
margin-bottom: .5em;
512+
513+
// box-shadow: 0 2px 20px -2px rgba(20, 20, 20, 0.3);
514+
// background-color: #FBFBFB;
515+
516+
background-color: rgba(220, 220, 240, 0.5);
517+
518+
> a {
519+
background: rgba(250, 250, 255, 1);
520+
font-weight: bold;
521+
}
522+
523+
.cr-index {
524+
ul.badges {
525+
display: none;
526+
}
527+
}
537528
}
538529
}
539530

js/kunai/ui/treeview.js

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -31,76 +31,6 @@ class DOM {
3131
// this.scrollIsAutoFired = false
3232
}
3333

34-
static scrollEps = 8
35-
36-
async handleScroll(e) {
37-
// if (this.scrollIsAutoFired) {
38-
// this.log.debug(`handleScroll(auto)`, e)
39-
// this.scrollIsAutoFired = false
40-
// return false
41-
// }
42-
43-
let content_wrapper = $(e.target)
44-
const content = content_wrapper.children('.content')
45-
46-
const st = content_wrapper.scrollTop()
47-
const cOfs = content.position().top
48-
49-
const k_branch = content.children('.kunai-branch[data-branch-for="headers"]')
50-
const bID = k_branch.attr('data-branch-id')
51-
const branch = k_branch.children('.branch')
52-
// this.log.debug(`handleScroll #${bID} (top = ${st}px, cOfs = ${cOfs}px)`, e, content_wrapper, content, k_branch, branch)
53-
54-
let closestChild = null
55-
let closestDelta = 0
56-
57-
// find a child item with least deltaY to current scrollTop
58-
for (const child_ of branch.children('li')) {
59-
const child = $(child_)
60-
const cTop = child.position().top
61-
const delta = st - cTop
62-
63-
// this.log.debug(`checking '${child.find('.cr-index .title').get(0).innerText.trim()}' | cTop: ${cTop}, delta: ${delta} (closestDelta: ${closestDelta})`, child_)
64-
65-
if (!closestChild) {
66-
closestDelta = delta
67-
closestChild = child
68-
} else {
69-
// if (cTop + (st + cOfs) < st) {
70-
if (cTop < st) {
71-
closestDelta = cTop
72-
closestChild = child
73-
} else {
74-
break
75-
}
76-
}
77-
}
78-
79-
{
80-
let last = this.branchPrevs.get(bID)
81-
if (last) {
82-
// this.log.debug(`preview target change --> '${closestChild.find('.cr-index > .title > .keys')[0].innerText.trim()}'`, closestChild[0])
83-
last.removeClass('preview')
84-
}
85-
}
86-
87-
this.branchPrevs.set(bID, closestChild)
88-
closestChild.addClass('preview')
89-
// throw [closestChild, closestDelta]
90-
91-
if (closestChild.hasClass('expanded')) {
92-
let bar = $(closestChild.children('.expandbar')[0])
93-
bar.css({top: `${(st)}px`})
94-
// throw true
95-
}
96-
97-
if (st < DOM.scrollEps) {
98-
content_wrapper.removeClass('scrolling')
99-
} else {
100-
content_wrapper.addClass('scrolling')
101-
}
102-
}
103-
10434
async createContent(obj) {
10535
this.log.info(`createContent '${obj.self.id}'`, obj)
10636

@@ -461,10 +391,6 @@ class Treeview {
461391
stack.addClass('empty')
462392
}
463393

464-
if (top.category.index === this.kc.categories().get('reference').index) {
465-
content_wrapper.on('scroll', ::this.dom.handleScroll)
466-
}
467-
468394
return stack
469395
})
470396
))

0 commit comments

Comments
 (0)