Skip to content

Commit ab170ee

Browse files
committed
Fix introduction.
1 parent 4006ee5 commit ab170ee

File tree

13 files changed

+107
-88
lines changed

13 files changed

+107
-88
lines changed

Gruntfile.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const webpackConfig = require('./webpack.config.js');
1+
const websiteWebpackConfig = require('./website.webpack.config.js');
22

33
module.exports = grunt => {
44
grunt.loadNpmTasks('grunt-contrib-copy');
@@ -42,8 +42,8 @@ module.exports = grunt => {
4242
}
4343
},
4444
webpack: {
45-
prod: webpackConfig,
46-
dev: webpackConfig
45+
prod: websiteWebpackConfig,
46+
dev: websiteWebpackConfig
4747
}
4848
});
4949

src/utils.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ export function httpGet(url, cache = true) {
2828
});
2929
}
3030

31-
export function downloadPublicKeyIfPossible(decodedToken) {
32-
return Promise.reject();
33-
}
34-
3531
export function isValidBase64String(s, urlOnly) {
3632
try {
3733
const validChars = urlOnly ?
@@ -105,3 +101,7 @@ export function isValidKey(key) {
105101
};
106102
}
107103

104+
export function downloadPublicKeyIfPossible(decodedToken) {
105+
return Promise.reject();
106+
}
107+

src/website/dom-elements.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ export const menuScrollableLinks =
77
export const sectionElements = document.getElementsByTagName('section');
88

99
export const extensionButton = document.getElementById('extension-button');
10-
export const extensionButtonText =
11-
extensionButton.querySelector('.button-text');
10+
export const extensionButtonText = extensionButton ?
11+
extensionButton.querySelector('.button-text') :
12+
undefined;
1213

1314
export const codeElements = document.querySelectorAll('.plain-text pre code');
1415

src/website/highlighting.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { codeElements } from './dom-elements.js';
2+
3+
import hljs from 'highlight.js';
4+
5+
export function setupHighlighting() {
6+
// TODO: consider replacing this with CodeMirror, which we already use.
7+
8+
hljs.configure({
9+
classPrefix: ''
10+
});
11+
12+
Array.prototype.forEach.call(codeElements, element => {
13+
if (!element.classList.contains('hljs')) {
14+
element.classList.add('hljs');
15+
hljs.highlightBlock(element);
16+
}
17+
});
18+
}

src/website/index.js

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,15 @@ import {
77
useDefaultToken
88
} from './editor';
99
import { setupJwtCounter } from './counter.js';
10+
import { setupSmoothScrolling } from './smooth-scrolling.js';
11+
import { setupHighlighting } from './highlighting.js';
1012
import { getParameterByName, smoothScrollTo } from './utils.js';
1113
import {
1214
publicKeyTextArea,
1315
codeElements,
1416
debuggerSection,
15-
menuScrollableLinks
1617
} from './dom-elements.js';
1718

18-
import hljs from 'highlight.js';
19-
2019
/* For initialization, look at the end of this file */
2120

2221
function parseLocationQuery() {
@@ -38,7 +37,9 @@ function parseLocationQuery() {
3837
scroll = true;
3938
}
4039

41-
debuggerSection.scrollIntoView(true);
40+
if(scroll) {
41+
debuggerSection.scrollIntoView(true);
42+
}
4243
}
4344

4445
function loadToken() {
@@ -55,39 +56,6 @@ function loadToken() {
5556
}
5657
}
5758

58-
function setupHighlighting() {
59-
// TODO: consider replacing this with CodeMirror, which we already use.
60-
61-
hljs.configure({
62-
classPrefix: ''
63-
});
64-
65-
Array.prototype.forEach.call(codeElements, element => {
66-
if(!element.classList.contains('hljs')) {
67-
element.classList.add('hljs');
68-
hljs.highlightBlock(element);
69-
}
70-
});
71-
}
72-
73-
function setupSmoothScrolling() {
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-
});
89-
}
90-
9159
// Initialization
9260
setupNavbar();
9361
setupExtensionButton();

src/website/introduction/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { setupHighlighting } from '../highlighting.js';
2+
import { setupJwtCounter } from '../counter.js';
3+
4+
// Initialization
5+
setupHighlighting();
6+
setupJwtCounter();

src/website/smooth-scrolling.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { menuScrollableLinks, navbarElement } from './dom-elements.js';
2+
import { isWideScreen } from './utils.js';
3+
4+
import $ from 'jquery';
5+
6+
// This is the only function that really requires jQuery, other than some
7+
// of the dependencies. Consider this when adding code that depends on
8+
// jQuery somewhere else.
9+
export function smoothScrollTo(element) {
10+
// TODO: don't use jQuery
11+
12+
const navHeight = $(navbarElement).height();
13+
const targetElement = $(element);
14+
15+
if (isWideScreen()) {
16+
$('html, body').animate({
17+
scrollTop: targetElement.offset().top - navHeight
18+
}, 500);
19+
} else {
20+
$('html, body').animate({
21+
scrollTop: targetElement.offset().top
22+
}, 500);
23+
}
24+
}
25+
26+
export function setupSmoothScrolling() {
27+
Array.prototype.forEach.call(menuScrollableLinks, scrollable => {
28+
scrollable.addEventListener('click', event => {
29+
event.preventDefault();
30+
31+
const start = scrollable.href.indexOf('#');
32+
if (start === -1) {
33+
console.error('<a> element with .scrollto set and bad link: ',
34+
scrollable.href);
35+
return;
36+
}
37+
38+
const id = scrollable.href.substr(start + 1);
39+
smoothScrollTo(document.getElementById(id));
40+
});
41+
});
42+
}

src/website/utils.js

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { navbarElement } from './dom-elements.js';
2-
31
export function safeLocalStorageSetItem(key, value) {
42
try {
53
localStorage.setItem(key, value);
@@ -109,23 +107,3 @@ export function isInViewport(elem) {
109107
export function isWideScreen() {
110108
return window.matchMedia('(min-width: 768px)').matches;
111109
}
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-
}

views/counter.pug

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.tokens-created
2+
.container
3+
img(src='/img/pic_logo_ft.svg')
4+
p JWT.io is brought to you by
5+
a(href='https://auth0.com/signup', target="_blank") Auth0
6+
p Securely implement authentication with JWTs using Auth0 on any stack and any device in less than 10 minutes.
7+
8+
a(href='https://auth0.com/signup', target="_blank").btn.btn-success Create free account
9+
10+
.token
11+
h5 TOKENS CREATED
12+
13+
.counter
14+

views/index.pug

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,3 +333,7 @@ block content
333333
h2 Store
334334
img(src='img/pic_tshirt.png')
335335
a.buy(href='http://swag.auth0.com/', target='_blank') Buy T-Shirt
336+
337+
include counter.pug
338+
339+
script(src='/js/index.js')

0 commit comments

Comments
 (0)