2016-03-31 22:33:49 +02:00
|
|
|
'use strict';
|
|
|
|
|
2016-06-12 20:11:43 +02:00
|
|
|
const router = require('../router.js');
|
2017-01-20 21:51:04 +01:00
|
|
|
const uri = require('../util/uri.js');
|
2016-04-09 18:54:23 +02:00
|
|
|
const views = require('../util/views.js');
|
2016-05-29 12:28:52 +02:00
|
|
|
const PostContentControl = require('../controls/post_content_control.js');
|
2016-05-29 12:29:24 +02:00
|
|
|
const PostNotesOverlayControl
|
|
|
|
= require('../controls/post_notes_overlay_control.js');
|
2016-05-29 12:28:52 +02:00
|
|
|
const TagAutoCompleteControl =
|
|
|
|
require('../controls/tag_auto_complete_control.js');
|
2016-03-31 22:33:49 +02:00
|
|
|
|
2016-06-14 10:31:48 +02:00
|
|
|
const template = views.getTemplate('home');
|
2016-07-06 09:49:21 +02:00
|
|
|
const footerTemplate = views.getTemplate('home-footer');
|
2016-07-06 00:07:30 +02:00
|
|
|
const featuredPostTemplate = views.getTemplate('home-featured-post');
|
2016-06-14 10:31:48 +02:00
|
|
|
|
2016-04-09 18:54:23 +02:00
|
|
|
class HomeView {
|
2016-06-14 10:31:48 +02:00
|
|
|
constructor(ctx) {
|
|
|
|
this._hostNode = document.getElementById('content-holder');
|
2016-07-06 09:49:21 +02:00
|
|
|
this._ctx = ctx;
|
2016-03-31 22:33:49 +02:00
|
|
|
|
2016-06-14 10:31:48 +02:00
|
|
|
const sourceNode = template(ctx);
|
|
|
|
views.replaceContent(this._hostNode, sourceNode);
|
2016-07-13 17:18:28 +02:00
|
|
|
views.syncScrollPosition();
|
2016-06-01 21:31:15 +02:00
|
|
|
|
2016-06-14 10:31:48 +02:00
|
|
|
if (this._formNode) {
|
|
|
|
this._tagAutoCompleteControl = new TagAutoCompleteControl(
|
|
|
|
this._searchInputNode);
|
|
|
|
this._formNode.addEventListener(
|
|
|
|
'submit', e => this._evtFormSubmit(e));
|
2016-05-29 12:28:52 +02:00
|
|
|
}
|
|
|
|
|
2016-06-14 10:31:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
showSuccess(text) {
|
|
|
|
views.showSuccess(this._hostNode, text);
|
|
|
|
}
|
|
|
|
|
|
|
|
showError(text) {
|
|
|
|
views.showError(this._hostNode, text);
|
|
|
|
}
|
2016-05-29 12:28:52 +02:00
|
|
|
|
2016-06-14 10:31:48 +02:00
|
|
|
setStats(stats) {
|
2016-07-06 09:49:21 +02:00
|
|
|
views.replaceContent(
|
|
|
|
this._footerContainerNode,
|
|
|
|
footerTemplate(Object.assign({}, stats, this._ctx)));
|
2016-06-14 10:31:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
setFeaturedPost(postInfo) {
|
2016-07-06 00:07:30 +02:00
|
|
|
views.replaceContent(
|
|
|
|
this._postInfoContainerNode, featuredPostTemplate(postInfo));
|
2016-06-14 10:31:48 +02:00
|
|
|
if (this._postContainerNode && postInfo.featuredPost) {
|
|
|
|
this._postContentControl = new PostContentControl(
|
|
|
|
this._postContainerNode,
|
|
|
|
postInfo.featuredPost,
|
2016-05-29 12:28:52 +02:00
|
|
|
() => {
|
|
|
|
return [
|
|
|
|
window.innerWidth * 0.8,
|
|
|
|
window.innerHeight * 0.7,
|
|
|
|
];
|
|
|
|
});
|
2016-05-29 12:29:24 +02:00
|
|
|
|
2016-06-14 10:31:48 +02:00
|
|
|
this._postNotesOverlay = new PostNotesOverlayControl(
|
|
|
|
this._postContainerNode.querySelector('.post-overlay'),
|
|
|
|
postInfo.featuredPost);
|
2017-09-09 23:42:00 +02:00
|
|
|
|
|
|
|
if (postInfo.featuredPost.type === 'video'
|
|
|
|
|| postInfo.featuredPost.type === 'flash') {
|
|
|
|
this._postContentControl.disableOverlay();
|
|
|
|
}
|
2016-05-29 12:28:52 +02:00
|
|
|
}
|
2016-03-31 22:33:49 +02:00
|
|
|
}
|
2016-06-14 10:31:48 +02:00
|
|
|
|
2016-07-06 09:49:21 +02:00
|
|
|
get _footerContainerNode() {
|
|
|
|
return this._hostNode.querySelector('.footer-container');
|
2016-06-14 10:31:48 +02:00
|
|
|
}
|
|
|
|
|
2016-07-06 00:07:30 +02:00
|
|
|
get _postInfoContainerNode() {
|
|
|
|
return this._hostNode.querySelector('.post-info-container');
|
|
|
|
}
|
|
|
|
|
2016-06-14 10:31:48 +02:00
|
|
|
get _postContainerNode() {
|
|
|
|
return this._hostNode.querySelector('.post-container');
|
|
|
|
}
|
|
|
|
|
|
|
|
get _formNode() {
|
|
|
|
return this._hostNode.querySelector('form');
|
|
|
|
}
|
|
|
|
|
|
|
|
get _searchInputNode() {
|
|
|
|
return this._formNode.querySelector('input[name=search-text]');
|
|
|
|
}
|
|
|
|
|
|
|
|
_evtFormSubmit(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
this._searchInputNode.blur();
|
2017-01-20 21:51:04 +01:00
|
|
|
router.show(uri.formatClientLink('posts', {
|
2016-07-07 21:18:35 +02:00
|
|
|
query: this._searchInputNode.value}));
|
2016-06-14 10:31:48 +02:00
|
|
|
}
|
2016-03-31 22:33:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = HomeView;
|