Skip to content

Commit fbd43ba

Browse files
committed
style(client): reformat JavaScript files for consistent indentation
1 parent c6ef990 commit fbd43ba

File tree

16 files changed

+369
-297
lines changed

16 files changed

+369
-297
lines changed

app/client/lib/navigation.js

Lines changed: 54 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4,52 +4,58 @@ import event from '@muvon/event'
44
let pageEl
55

66
export default class Navigation {
7-
static init() {
8-
pageEl = document.getElementById('page')
9-
const d = delegate(document)
10-
11-
d.on('click', '[data-load]', (ev, el) => {
12-
if (el.href) {
13-
ev.preventDefault()
14-
this.load(el.href)
15-
}
16-
})
17-
18-
window.onpopstate = ev => {
19-
if (ev.srcElement.location.pathname == ev.target.location.pathname) {
20-
return
21-
}
22-
this.load(location.href)
23-
}
24-
}
25-
26-
static load(url) {
27-
if (location.href !== url) {
28-
history.pushState({}, '', url)
29-
}
30-
31-
const opts = {
32-
credentials: 'same-origin',
33-
method: 'GET',
34-
headers: {
35-
'X-Requested-With': 'navigation'
36-
}
37-
}
38-
39-
fetch(url, opts).then(res => res.text()).then(body => {
40-
window.requestAnimationFrame(() => {
41-
window.scrollTo(0, 0)
42-
pageEl.innerHTML = body
43-
const title_el = pageEl.querySelector('#title')
44-
const token_el = pageEl.querySelector('#token')
45-
document.title = title_el.innerText
46-
pageEl.removeChild(title_el)
47-
pageEl.removeChild(token_el)
48-
49-
const url_path = url.replace(/https?\:\/\/[^\/]+/, '')
50-
event.send('page_content_loaded', {ajax: true, url: url_path}, 'navigation')
51-
event.send('token_updated', token_el.innerText, 'navigation')
52-
})
53-
})
54-
}
7+
static init() {
8+
pageEl = document.getElementById('page')
9+
const d = delegate(document)
10+
11+
d.on(
12+
'click', '[data-load]', (ev, el) => {
13+
if (el.href) {
14+
ev.preventDefault()
15+
this.load(el.href)
16+
}
17+
}
18+
)
19+
20+
window.onpopstate = ev => {
21+
if (ev.srcElement.location.pathname == ev.target.location.pathname) {
22+
return
23+
}
24+
this.load(location.href)
25+
}
26+
}
27+
28+
static load(url) {
29+
if (location.href !== url) {
30+
history.pushState({}, '', url)
31+
}
32+
33+
const opts = {
34+
credentials: 'same-origin',
35+
method: 'GET',
36+
headers: {
37+
'X-Requested-With': 'navigation'
38+
}
39+
}
40+
41+
fetch(url, opts).then(res => res.text()).then(
42+
body => {
43+
window.requestAnimationFrame(
44+
() => {
45+
window.scrollTo(0, 0)
46+
pageEl.innerHTML = body
47+
const title_el = pageEl.querySelector('#title')
48+
const token_el = pageEl.querySelector('#token')
49+
document.title = title_el.innerText
50+
pageEl.removeChild(title_el)
51+
pageEl.removeChild(token_el)
52+
53+
const url_path = url.replace(/https?\:\/\/[^\/]+/, '')
54+
event.send('page_content_loaded', {ajax: true, url: url_path}, 'navigation')
55+
event.send('token_updated', token_el.innerText, 'navigation')
56+
}
57+
)
58+
}
59+
)
60+
}
5561
}

app/client/main.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,23 @@ import Navigation from 'app/lib/navigation.js'
22
import event from '@muvon/event'
33

44
// Init components
5-
event.on('page_content_loaded', (ev, {ajax}) => {
6-
const element = ajax ? document.getElementById('page') : document
7-
const components = element.querySelectorAll('[data-component]')
8-
Array.prototype.forEach.call(components, (mount_point) => {
9-
const cn = mount_point.getAttribute('data-component')
10-
try {
11-
const cc = require('./component/' + cn + '/index.js').default
12-
cc(mount_point)
13-
} catch (e) {
14-
console.warn('Failed to initialize component ' + cn + '. ' + e)
15-
}
16-
})
17-
})
5+
event.on(
6+
'page_content_loaded', (ev, {ajax}) => {
7+
const element = ajax ? document.getElementById('page') : document
8+
const components = element.querySelectorAll('[data-component]')
9+
Array.prototype.forEach.call(
10+
components, (mount_point) => {
11+
const cn = mount_point.getAttribute('data-component')
12+
try {
13+
const cc = require('./component/' + cn + '/index.js').default
14+
cc(mount_point)
15+
} catch (e) {
16+
console.warn('Failed to initialize component ' + cn + '. ' + e)
17+
}
18+
}
19+
)
20+
}
21+
)
1822

1923
Navigation.init()
2024
event.send('page_content_loaded', { ajax: false, url: location.pathname + location.search })

0 commit comments

Comments
 (0)