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 11import { tokenEditor } from './instances.js' ;
2+ import { isWideScreen } from '../utils.js' ;
23import {
34 algorithmSelect ,
45 publicKeyTextArea ,
@@ -28,7 +29,7 @@ export function copyTokenLink() {
2829}
2930
3031export function fixEditorHeight ( ) {
31- if ( window . matchMedia ( '(min-width: 768px)' ) . matches ) {
32+ if ( isWideScreen ( ) ) {
3233 editorElement . style . height = `${ decodedElement . offsetHeight } px` ;
3334 }
3435}
Original file line number Diff line number Diff line change @@ -7,11 +7,12 @@ import {
77 useDefaultToken
88} from './editor' ;
99import { setupJwtCounter } from './counter.js' ;
10- import { getParameterByName } from './utils.js' ;
10+ import { getParameterByName , smoothScrollTo } from './utils.js' ;
1111import {
1212 publicKeyTextArea ,
1313 codeElements ,
14- debuggerSection
14+ debuggerSection ,
15+ menuScrollableLinks
1516} from './dom-elements.js' ;
1617
1718import hljs from 'highlight.js' ;
@@ -70,8 +71,21 @@ function setupHighlighting() {
7071}
7172
7273function 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+ } ) ;
7589}
7690
7791// Initialization
Original file line number Diff line number Diff line change 1+ import { navbarElement } from './dom-elements.js' ;
2+
13export function safeLocalStorageSetItem ( key , value ) {
24 try {
35 localStorage . setItem ( key , value ) ;
@@ -103,3 +105,27 @@ export function isInViewport(elem) {
103105 bounding . right <= ( window . innerWidth || document . documentElement . clientWidth )
104106 ) ;
105107} ;
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 5656 & :hover
5757 color : darken (#00 b9 f1 , 50% )
5858
59+ p
60+ margin 30px 0 30px 0
61+
5962.container
6063 width 100%
6164 max-width 1200px
You can’t perform that action at this time.
0 commit comments