szurubooru/client/js/views/home_view.js

63 lines
1.9 KiB
JavaScript
Raw Normal View History

2016-03-31 22:33:49 +02:00
'use strict';
const page = require('page');
2016-03-31 22:33:49 +02:00
const config = require('../config.js');
const misc = require('../util/misc.js');
const views = require('../util/views.js');
const PostContentControl = require('../controls/post_content_control.js');
const PostNotesOverlayControl
= require('../controls/post_notes_overlay_control.js');
const TagAutoCompleteControl =
require('../controls/tag_auto_complete_control.js');
2016-03-31 22:33:49 +02:00
class HomeView {
2016-03-31 22:33:49 +02:00
constructor() {
this._homeTemplate = views.getTemplate('home');
2016-03-31 22:33:49 +02:00
}
2016-04-08 10:35:38 +02:00
render(ctx) {
Object.assign(ctx, {
2016-04-06 20:38:45 +02:00
name: config.name,
2016-03-31 23:18:08 +02:00
version: config.meta.version,
2016-04-05 17:57:26 +02:00
buildDate: config.meta.buildDate,
2016-04-08 10:35:38 +02:00
});
const target = document.getElementById('content-holder');
const source = this._homeTemplate(ctx);
views.listenToMessages(source);
views.showView(target, source);
const form = source.querySelector('form');
if (form) {
const searchTextInput = form.querySelector('input');
new TagAutoCompleteControl(searchTextInput);
form.addEventListener('submit', e => {
e.preventDefault();
const text = searchTextInput.value;
searchTextInput.blur();
page('/posts/' + misc.formatSearchQuery({text: text}));
});
}
const postContainerNode = source.querySelector('.post-container');
if (postContainerNode && ctx.featuredPost) {
new PostContentControl(
postContainerNode,
ctx.featuredPost,
() => {
return [
window.innerWidth * 0.8,
window.innerHeight * 0.7,
];
});
new PostNotesOverlayControl(
postContainerNode.querySelector('.post-overlay'),
ctx.featuredPost);
}
2016-03-31 22:33:49 +02:00
}
}
module.exports = HomeView;