nfp_sites/app/widgets/newsentry.js

58 lines
1.6 KiB
JavaScript
Raw Normal View History

2019-09-14 19:03:38 +00:00
const Fileinfo = require('./fileinfo')
2019-09-13 13:33:10 +00:00
const Newsentry = {
2019-09-14 19:03:38 +00:00
strip: function(html) {
var doc = new DOMParser().parseFromString(html, 'text/html')
var out = doc.body.textContent || ''
var splitted = out.split('.')
if (splitted.length > 2) {
return splitted.slice(0, 2).join('.') + '...'
}
return out
},
2019-09-13 13:33:10 +00:00
view: function(vnode) {
2019-10-02 21:48:50 +00:00
var deviceWidth = window.innerWidth
var pixelRatio = window.devicePixelRatio || 1
var imagePath = ''
if (vnode.attrs.media) {
if (deviceWidth > 440 || pixelRatio <= 1) {
imagePath = vnode.attrs.media.small_url
} else {
imagePath = vnode.attrs.media.medium_url
}
}
2019-09-13 13:33:10 +00:00
return m('newsentry', [
2019-10-02 21:48:50 +00:00
imagePath
2021-01-05 19:12:10 +00:00
? m(m.route.Link, {
class: 'cover',
href: '/article/' + vnode.attrs.path,
2021-01-05 19:12:10 +00:00
}, m('picture', [
m('source', { srcset:
vnode.attrs.media.small_url + ''
}),
m('img', { src: imagePath, alt: 'Article image for ' + vnode.attrs.name }),
]))
2019-09-13 13:33:10 +00:00
: m('a.cover.nobg'),
m('div.entrycontent', [
2019-09-14 19:03:38 +00:00
m('div.title', [
m(m.route.Link,
{ href: '/article/' + vnode.attrs.path },
m('h3', [vnode.attrs.name])
),
]),
(vnode.attrs.files && vnode.attrs.files.length
? vnode.attrs.files.map(function(file) {
return m(Fileinfo, { file: file, slim: true })
})
: vnode.attrs.description
? m('span.entrydescription', Newsentry.strip(vnode.attrs.description))
: null),
]),
2019-09-13 13:33:10 +00:00
])
},
}
module.exports = Newsentry