File tree 2 files changed +20
-4
lines changed
2 files changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -4,10 +4,15 @@ export function initDashboardAsideScroll () {
4
4
5
5
if ( ! el ) return
6
6
7
- window . addEventListener ( 'beforeunload' , function ( ) {
8
- const scrollPosition = el . scrollTop
9
- localStorage . setItem ( key , scrollPosition )
10
- } )
7
+ const saveScrollPosition = window . debounce (
8
+ ( ) => {
9
+ const scrollPosition = el . scrollTop
10
+ localStorage . setItem ( key , scrollPosition )
11
+ console . log ( scrollPosition )
12
+ } ,
13
+ 200
14
+ )
15
+ el . addEventListener ( 'scroll' , saveScrollPosition )
11
16
12
17
document . addEventListener ( 'DOMContentLoaded' , function ( ) {
13
18
const scrollPosition = localStorage . getItem ( key )
Original file line number Diff line number Diff line change 1
1
export function initHelpers ( ) {
2
+ function debounce ( fn , delayMilliseconds ) {
3
+ let timeoutInstance
4
+ return function ( ...args ) {
5
+ clearTimeout ( timeoutInstance )
6
+ timeoutInstance = setTimeout ( ( ) => {
7
+ fn . apply ( this , args )
8
+ } , delayMilliseconds )
9
+ }
10
+ }
11
+
2
12
function copyToClipboard ( textToCopy ) {
3
13
const successMessage = 'Text copied'
4
14
const errorMessage = 'Error copying text'
@@ -58,6 +68,7 @@ export function initHelpers () {
58
68
}
59
69
}
60
70
71
+ window . debounce = debounce
61
72
window . copyToClipboard = copyToClipboard
62
73
window . textareaAutoGrow = textareaAutoGrow
63
74
window . formatJson = formatJson
You can’t perform that action at this time.
0 commit comments