2019-09-15 01:53:38 +00:00
|
|
|
const m = require('mithril')
|
2019-10-01 12:19:10 +00:00
|
|
|
const ApiArticle = require('../api/article.p')
|
2019-09-15 01:53:38 +00:00
|
|
|
const Authentication = require('../authentication')
|
|
|
|
const Fileinfo = require('../widgets/fileinfo')
|
|
|
|
|
|
|
|
const Article = {
|
|
|
|
oninit: function(vnode) {
|
|
|
|
this.error = ''
|
|
|
|
this.lastarticle = m.route.param('article') || '1'
|
2019-10-02 00:55:15 +00:00
|
|
|
this.showcomments = false
|
2019-10-01 17:18:20 +00:00
|
|
|
|
|
|
|
if (window.__nfpdata) {
|
|
|
|
this.path = m.route.param('id')
|
|
|
|
this.article = window.__nfpdata
|
|
|
|
window.__nfpdata = null
|
|
|
|
} else {
|
|
|
|
this.fetchArticle(vnode)
|
|
|
|
}
|
2019-09-15 01:53:38 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
fetchArticle: function(vnode) {
|
|
|
|
this.path = m.route.param('id')
|
2019-10-02 00:55:15 +00:00
|
|
|
this.showcomments = false
|
2019-09-15 01:53:38 +00:00
|
|
|
this.article = {
|
|
|
|
id: 0,
|
|
|
|
name: '',
|
|
|
|
path: '',
|
|
|
|
description: '',
|
|
|
|
media: null,
|
|
|
|
banner: null,
|
|
|
|
files: [],
|
|
|
|
}
|
|
|
|
this.loading = true
|
|
|
|
|
2019-10-01 11:35:00 +00:00
|
|
|
ApiArticle.getArticle(this.path)
|
2019-09-15 01:53:38 +00:00
|
|
|
.then(function(result) {
|
|
|
|
vnode.state.article = result
|
2019-10-01 17:18:20 +00:00
|
|
|
if (result.parent) {
|
|
|
|
document.title = result.name + ' - ' + result.parent.name + ' - NFP Moe'
|
|
|
|
} else {
|
|
|
|
document.title = result.name + ' - NFP Moe'
|
|
|
|
}
|
2019-09-15 01:53:38 +00:00
|
|
|
})
|
|
|
|
.catch(function(err) {
|
|
|
|
vnode.state.error = err.message
|
|
|
|
})
|
|
|
|
.then(function() {
|
2019-10-02 21:48:50 +00:00
|
|
|
vnode.state.loading = false
|
2019-09-15 01:53:38 +00:00
|
|
|
m.redraw()
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
onupdate: function(vnode) {
|
|
|
|
if (this.path !== m.route.param('id')) {
|
|
|
|
this.fetchArticle(vnode)
|
2019-10-02 21:48:50 +00:00
|
|
|
m.redraw()
|
2019-09-15 01:53:38 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
view: function(vnode) {
|
2019-10-02 17:40:32 +00:00
|
|
|
var deviceWidth = window.innerWidth
|
|
|
|
var imagePath = ''
|
|
|
|
|
|
|
|
if (this.article.media) {
|
|
|
|
var pixelRatio = window.devicePixelRatio || 1
|
|
|
|
if ((deviceWidth < 800 && pixelRatio <= 1)
|
|
|
|
|| (deviceWidth < 600 && pixelRatio > 1)) {
|
|
|
|
imagePath = this.article.media.medium_url
|
|
|
|
} else {
|
|
|
|
imagePath = this.article.media.large_url
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-15 01:53:38 +00:00
|
|
|
return (
|
|
|
|
this.loading ?
|
2019-10-02 21:48:50 +00:00
|
|
|
m('article.article', m('div.loading-spinner'))
|
2019-09-15 01:53:38 +00:00
|
|
|
: m('article.article', [
|
2019-10-02 18:47:20 +00:00
|
|
|
this.article.parent ? m('div.goback', ['« ', m(m.route.Link, { href: '/page/' + this.article.parent.path }, this.article.parent.name)]) : null,
|
2019-09-15 01:53:38 +00:00
|
|
|
m('header', m('h1', this.article.name)),
|
|
|
|
m('.fr-view', [
|
|
|
|
this.article.media
|
|
|
|
? m('a.cover', {
|
2019-10-01 03:45:44 +00:00
|
|
|
rel: 'noopener',
|
2019-10-02 17:40:32 +00:00
|
|
|
href: this.article.media.link,
|
|
|
|
}, m('img', { src: imagePath, alt: 'Cover image for ' + this.article.name }))
|
2019-09-15 01:53:38 +00:00
|
|
|
: null,
|
|
|
|
this.article.description ? m.trust(this.article.description) : null,
|
|
|
|
(this.article.files && this.article.files.length
|
|
|
|
? this.article.files.map(function(file) {
|
|
|
|
return m(Fileinfo, { file: file })
|
|
|
|
})
|
|
|
|
: null),
|
2019-10-02 18:47:20 +00:00
|
|
|
m('div.entrymeta', [
|
|
|
|
'Posted ',
|
|
|
|
(this.article.parent ? 'in' : ''),
|
|
|
|
(this.article.parent ? m(m.route.Link, { href: '/page/' + this.article.parent.path }, this.article.parent.name) : null),
|
|
|
|
'at ' + (this.article.published_at.replace('T', ' ').split('.')[0]).substr(0, 16),
|
|
|
|
' by ' + (this.article.staff && this.article.staff.fullname || 'Admin'),
|
|
|
|
]),
|
2019-09-15 01:53:38 +00:00
|
|
|
]),
|
|
|
|
Authentication.currentUser
|
|
|
|
? m('div.admin-actions', [
|
|
|
|
m('span', 'Admin controls:'),
|
|
|
|
m(m.route.Link, { href: '/admin/articles/' + this.article.id }, 'Edit article'),
|
|
|
|
])
|
|
|
|
: null,
|
2019-10-02 00:55:15 +00:00
|
|
|
this.showcomments
|
|
|
|
? m('div.commentcontainer', [
|
|
|
|
m('div#disqus_thread', { oncreate: function() {
|
2019-10-02 01:03:40 +00:00
|
|
|
let fullhost = window.location.protocol + '//' + window.location.host
|
2019-10-02 00:55:15 +00:00
|
|
|
/*eslint-disable */
|
|
|
|
window.disqus_config = function () {
|
2019-10-02 01:03:40 +00:00
|
|
|
this.page.url = fullhost + '/article/' + vnode.state.article.path
|
2019-10-02 00:55:15 +00:00
|
|
|
this.page.identifier = 'article-' + vnode.state.article.id
|
|
|
|
};
|
|
|
|
(function() { // DON'T EDIT BELOW THIS LINE
|
|
|
|
var d = document, s = d.createElement('script');
|
|
|
|
s.src = 'https://nfp-moe.disqus.com/embed.js';
|
|
|
|
s.setAttribute('data-timestamp', +new Date());
|
|
|
|
(d.head || d.body).appendChild(s);
|
|
|
|
})()
|
|
|
|
/*eslint-enable */
|
|
|
|
}}, m('div.loading-spinner')),
|
|
|
|
])
|
|
|
|
: m('button.opencomments', {
|
|
|
|
onclick: function() { vnode.state.showcomments = true },
|
|
|
|
}, 'Open comment discussion'),
|
2019-09-15 01:53:38 +00:00
|
|
|
])
|
|
|
|
)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Article
|
2019-09-16 16:47:29 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
<div id="disqus_thread"></div>
|
|
|
|
<script>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* RECOMMENDED CONFIGURATION VARIABLES: EDIT AND UNCOMMENT THE SECTION BELOW TO INSERT DYNAMIC VALUES FROM YOUR PLATFORM OR CMS.
|
|
|
|
* LEARN WHY DEFINING THESE VARIABLES IS IMPORTANT: https://disqus.com/admin/universalcode/#configuration-variables*/
|
|
|
|
/*
|
|
|
|
var disqus_config = function () {
|
|
|
|
this.page.url = PAGE_URL; // Replace PAGE_URL with your page's canonical URL variable
|
|
|
|
this.page.identifier = PAGE_IDENTIFIER; // Replace PAGE_IDENTIFIER with your page's unique identifier variable
|
|
|
|
};
|
|
|
|
/
|
|
|
|
(function() { // DON'T EDIT BELOW THIS LINE
|
|
|
|
var d = document, s = d.createElement('script');
|
|
|
|
s.src = 'https://nfp-moe.disqus.com/embed.js';
|
|
|
|
s.setAttribute('data-timestamp', +new Date());
|
|
|
|
(d.head || d.body).appendChild(s);
|
|
|
|
})();
|
|
|
|
</script>
|
|
|
|
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
|
|
|
|
*/
|