2023-02-15 05:18:18 +00:00
|
|
|
const m = require('mithril')
|
|
|
|
const Authentication = require('./authentication')
|
|
|
|
|
|
|
|
const Header = {
|
|
|
|
oninit: function(vnode) {
|
|
|
|
this.currentActive = 'home'
|
|
|
|
this.error = ''
|
|
|
|
this.loading = false
|
|
|
|
this.onbeforeupdate()
|
|
|
|
},
|
|
|
|
|
|
|
|
onbeforeupdate: function() {
|
|
|
|
let currentPath = m.route.get()
|
|
|
|
|
2023-05-10 15:32:28 +00:00
|
|
|
if (!currentPath || currentPath === '/' || currentPath.startsWith('/#')) this.currentActive = 'home'
|
2023-02-15 05:18:18 +00:00
|
|
|
else if (currentPath === '/login') this.currentActive = 'login'
|
|
|
|
},
|
|
|
|
|
|
|
|
logOut: function() {
|
|
|
|
Authentication.clearToken()
|
|
|
|
m.route.set('/')
|
|
|
|
},
|
|
|
|
|
2023-05-10 15:32:28 +00:00
|
|
|
scrollToView: function(e, name) {
|
|
|
|
if (this.currentActive === 'home') {
|
|
|
|
var el = document.getElementById(name)
|
|
|
|
if (el) {
|
|
|
|
el.scrollIntoView({ behavior: 'smooth' })
|
|
|
|
e.preventDefault()
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2023-02-15 05:18:18 +00:00
|
|
|
view: function() {
|
|
|
|
return [
|
|
|
|
m(m.route.Link,
|
|
|
|
{ href: '/', class: 'title' },
|
|
|
|
[
|
|
|
|
m('img.logo', { src: '/assets/img/logo.svg' }),
|
|
|
|
]
|
|
|
|
),
|
|
|
|
m('div.filler'),
|
|
|
|
m('div.links', [
|
|
|
|
m(m.route.Link, { href: '/#Heim' }, 'Heim'),
|
|
|
|
m(m.route.Link, { href: '/#GoodAdvice' }, 'Góð ráð'),
|
2023-05-10 15:32:28 +00:00
|
|
|
m(m.route.Link, {
|
|
|
|
class: 'button-active',
|
|
|
|
href: '/#subscribe',
|
|
|
|
onclick: (e) => { this.scrollToView(e, 'subscribe') },
|
|
|
|
}, 'Subscribe'),
|
2023-02-15 05:18:18 +00:00
|
|
|
]),
|
|
|
|
]
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Header
|