File tree Expand file tree Collapse file tree 4 files changed +49
-5
lines changed Expand file tree Collapse file tree 4 files changed +49
-5
lines changed Original file line number Diff line number Diff line change 1
1
import { tokenEditor } from './instances.js' ;
2
+ import { isWideScreen } from '../utils.js' ;
2
3
import {
3
4
algorithmSelect ,
4
5
publicKeyTextArea ,
@@ -28,7 +29,7 @@ export function copyTokenLink() {
28
29
}
29
30
30
31
export function fixEditorHeight ( ) {
31
- if ( window . matchMedia ( '(min-width: 768px)' ) . matches ) {
32
+ if ( isWideScreen ( ) ) {
32
33
editorElement . style . height = `${ decodedElement . offsetHeight } px` ;
33
34
}
34
35
}
Original file line number Diff line number Diff line change @@ -7,11 +7,12 @@ import {
7
7
useDefaultToken
8
8
} from './editor' ;
9
9
import { setupJwtCounter } from './counter.js' ;
10
- import { getParameterByName } from './utils.js' ;
10
+ import { getParameterByName , smoothScrollTo } from './utils.js' ;
11
11
import {
12
12
publicKeyTextArea ,
13
13
codeElements ,
14
- debuggerSection
14
+ debuggerSection ,
15
+ menuScrollableLinks
15
16
} from './dom-elements.js' ;
16
17
17
18
import hljs from 'highlight.js' ;
@@ -70,8 +71,21 @@ function setupHighlighting() {
70
71
}
71
72
72
73
function setupSmoothScrolling ( ) {
73
- //TODO
74
- console . log ( 'TODO: smooth scrolling' ) ;
74
+ Array . prototype . forEach . call ( menuScrollableLinks , scrollable => {
75
+ scrollable . addEventListener ( 'click' , event => {
76
+ event . preventDefault ( ) ;
77
+
78
+ const start = scrollable . href . indexOf ( '#' ) ;
79
+ if ( start === - 1 ) {
80
+ console . error ( '<a> element with .scrollto set and bad link: ' ,
81
+ scrollable . href ) ;
82
+ return ;
83
+ }
84
+
85
+ const id = scrollable . href . substr ( start + 1 ) ;
86
+ smoothScrollTo ( document . getElementById ( id ) ) ;
87
+ } ) ;
88
+ } ) ;
75
89
}
76
90
77
91
// Initialization
Original file line number Diff line number Diff line change
1
+ import { navbarElement } from './dom-elements.js' ;
2
+
1
3
export function safeLocalStorageSetItem ( key , value ) {
2
4
try {
3
5
localStorage . setItem ( key , value ) ;
@@ -103,3 +105,27 @@ export function isInViewport(elem) {
103
105
bounding . right <= ( window . innerWidth || document . documentElement . clientWidth )
104
106
) ;
105
107
} ;
108
+
109
+ export function isWideScreen ( ) {
110
+ return window . matchMedia ( '(min-width: 768px)' ) . matches ;
111
+ }
112
+
113
+ // This is the only function that really requires jQuery, other than some
114
+ // of the dependencies. Consider this when adding code that depends on
115
+ // jQuery somewhere else.
116
+ export function smoothScrollTo ( element ) {
117
+ // TODO: don't use jQuery
118
+
119
+ const navHeight = $ ( navbarElement ) . height ( ) ;
120
+ const targetElement = $ ( element ) ;
121
+
122
+ if ( isWideScreen ( ) ) {
123
+ $ ( 'html, body' ) . animate ( {
124
+ scrollTop : targetElement . offset ( ) . top - navHeight
125
+ } , 500 ) ;
126
+ } else {
127
+ $ ( 'html, body' ) . animate ( {
128
+ scrollTop : targetElement . offset ( ) . top
129
+ } , 500 ) ;
130
+ }
131
+ }
Original file line number Diff line number Diff line change 56
56
& :hover
57
57
color : darken (#00 b9 f1 , 50% )
58
58
59
+ p
60
+ margin 30px 0 30px 0
61
+
59
62
.container
60
63
width 100%
61
64
max-width 1200px
You can’t perform that action at this time.
0 commit comments