nfp_sites/heimaerbest/app/header.js

58 lines
1.4 KiB
JavaScript

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()
if (!currentPath || currentPath === '/' || currentPath.startsWith('/#')) this.currentActive = 'home'
else if (currentPath === '/login') this.currentActive = 'login'
},
logOut: function() {
Authentication.clearToken()
m.route.set('/')
},
scrollToView: function(e, name) {
if (this.currentActive === 'home') {
var el = document.getElementById(name)
if (el) {
el.scrollIntoView({ behavior: 'smooth' })
e.preventDefault()
return false
}
}
},
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áð'),
m(m.route.Link, {
class: 'button-active',
href: '/#subscribe',
onclick: (e) => { this.scrollToView(e, 'subscribe') },
}, 'Subscribe'),
]),
]
},
}
module.exports = Header