2020-06-06 00:03:37 +02:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const iosCorrectedInnerHeight = require("ios-inner-height");
|
|
|
|
const router = require("../router.js");
|
|
|
|
const views = require("../util/views.js");
|
|
|
|
const uri = require("../util/uri.js");
|
|
|
|
const keyboard = require("../util/keyboard.js");
|
|
|
|
const Touch = require("../util/touch.js");
|
|
|
|
const PostContentControl = require("../controls/post_content_control.js");
|
|
|
|
const PostNotesOverlayControl = require("../controls/post_notes_overlay_control.js");
|
|
|
|
const PostReadonlySidebarControl = require("../controls/post_readonly_sidebar_control.js");
|
|
|
|
const PostEditSidebarControl = require("../controls/post_edit_sidebar_control.js");
|
|
|
|
const CommentControl = require("../controls/comment_control.js");
|
|
|
|
const CommentListControl = require("../controls/comment_list_control.js");
|
|
|
|
|
|
|
|
const template = views.getTemplate("post-main");
|
2016-06-06 20:57:22 +02:00
|
|
|
|
2016-10-22 10:03:38 +02:00
|
|
|
class PostMainView {
|
2016-06-14 10:31:48 +02:00
|
|
|
constructor(ctx) {
|
2020-06-06 00:03:37 +02:00
|
|
|
this._hostNode = document.getElementById("content-holder");
|
2016-06-06 20:57:22 +02:00
|
|
|
|
2016-06-14 10:31:48 +02:00
|
|
|
const sourceNode = template(ctx);
|
2020-06-06 00:03:37 +02:00
|
|
|
const postContainerNode = sourceNode.querySelector(".post-container");
|
|
|
|
const sidebarNode = sourceNode.querySelector(".sidebar");
|
2016-06-14 10:31:48 +02:00
|
|
|
views.replaceContent(this._hostNode, sourceNode);
|
2016-07-13 17:18:28 +02:00
|
|
|
views.syncScrollPosition();
|
2016-06-06 20:57:22 +02:00
|
|
|
|
2020-06-06 00:03:37 +02:00
|
|
|
const topNavigationNode = document.body.querySelector(
|
|
|
|
"#top-navigation"
|
|
|
|
);
|
2016-06-06 20:57:22 +02:00
|
|
|
|
|
|
|
this._postContentControl = new PostContentControl(
|
|
|
|
postContainerNode,
|
|
|
|
ctx.post,
|
|
|
|
() => {
|
2018-04-05 19:40:53 +02:00
|
|
|
const margin = sidebarNode.getBoundingClientRect().left;
|
|
|
|
|
2016-06-06 20:57:22 +02:00
|
|
|
return [
|
2016-06-12 22:10:20 +02:00
|
|
|
window.innerWidth -
|
|
|
|
postContainerNode.getBoundingClientRect().left -
|
|
|
|
margin,
|
2018-04-05 19:40:53 +02:00
|
|
|
iosCorrectedInnerHeight() -
|
2016-06-13 22:34:39 +02:00
|
|
|
topNavigationNode.getBoundingClientRect().height -
|
2020-06-06 00:03:37 +02:00
|
|
|
margin * 2,
|
2016-06-06 20:57:22 +02:00
|
|
|
];
|
2020-06-06 00:03:37 +02:00
|
|
|
}
|
|
|
|
);
|
2016-06-06 20:57:22 +02:00
|
|
|
|
2016-07-22 13:27:52 +02:00
|
|
|
this._postNotesOverlayControl = new PostNotesOverlayControl(
|
2020-06-06 00:03:37 +02:00
|
|
|
postContainerNode.querySelector(".post-overlay"),
|
|
|
|
ctx.post
|
|
|
|
);
|
2016-06-06 20:57:22 +02:00
|
|
|
|
2020-06-06 00:03:37 +02:00
|
|
|
if (ctx.post.type === "video" || ctx.post.type === "flash") {
|
2016-08-27 22:14:17 +02:00
|
|
|
this._postContentControl.disableOverlay();
|
|
|
|
}
|
|
|
|
|
2016-06-12 18:08:50 +02:00
|
|
|
this._installSidebar(ctx);
|
2016-06-17 20:25:44 +02:00
|
|
|
this._installCommentForm();
|
|
|
|
this._installComments(ctx.post.comments);
|
2016-06-11 17:41:28 +02:00
|
|
|
|
2019-04-08 17:25:52 +02:00
|
|
|
const showPreviousImage = () => {
|
2016-10-02 17:04:56 +02:00
|
|
|
if (ctx.prevPostId) {
|
2017-09-21 21:24:03 +02:00
|
|
|
router.show(ctx.getPostUrl(ctx.prevPostId, ctx.parameters));
|
2016-06-11 21:37:19 +02:00
|
|
|
}
|
2019-04-08 17:25:52 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const showNextImage = () => {
|
2016-10-02 17:04:56 +02:00
|
|
|
if (ctx.nextPostId) {
|
2017-09-21 21:24:03 +02:00
|
|
|
router.show(ctx.getPostUrl(ctx.nextPostId, ctx.parameters));
|
2016-06-11 21:37:19 +02:00
|
|
|
}
|
2019-04-08 17:25:52 +02:00
|
|
|
};
|
|
|
|
|
2020-06-06 00:03:37 +02:00
|
|
|
keyboard.bind("e", () => {
|
2019-04-08 17:25:52 +02:00
|
|
|
if (ctx.editMode) {
|
2020-06-06 00:03:37 +02:00
|
|
|
router.show(uri.formatClientLink("post", ctx.post.id));
|
2019-04-08 17:25:52 +02:00
|
|
|
} else {
|
2020-06-06 00:03:37 +02:00
|
|
|
router.show(uri.formatClientLink("post", ctx.post.id, "edit"));
|
2019-04-08 17:25:52 +02:00
|
|
|
}
|
2016-06-11 21:37:19 +02:00
|
|
|
});
|
2020-06-06 00:03:37 +02:00
|
|
|
keyboard.bind(["a", "left"], showPreviousImage);
|
|
|
|
keyboard.bind(["d", "right"], showNextImage);
|
|
|
|
keyboard.bind("del", (e) => {
|
2017-09-21 19:42:56 +02:00
|
|
|
if (ctx.editMode) {
|
|
|
|
this.sidebarControl._evtDeleteClick(e);
|
|
|
|
}
|
|
|
|
});
|
2019-04-08 17:25:52 +02:00
|
|
|
|
|
|
|
new Touch(
|
|
|
|
postContainerNode,
|
2019-04-08 20:01:42 +02:00
|
|
|
() => {
|
|
|
|
if (!ctx.editMode) {
|
2020-06-06 00:03:37 +02:00
|
|
|
showPreviousImage();
|
2019-04-08 20:01:42 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
() => {
|
|
|
|
if (!ctx.editMode) {
|
2020-06-06 00:03:37 +02:00
|
|
|
showNextImage();
|
2019-04-08 20:01:42 +02:00
|
|
|
}
|
|
|
|
}
|
2020-06-06 00:03:37 +02:00
|
|
|
);
|
2016-06-11 21:37:19 +02:00
|
|
|
}
|
2016-06-12 18:08:50 +02:00
|
|
|
|
|
|
|
_installSidebar(ctx) {
|
|
|
|
const sidebarContainerNode = document.querySelector(
|
2020-06-06 00:03:37 +02:00
|
|
|
"#content-holder .sidebar-container"
|
|
|
|
);
|
2016-06-12 18:08:50 +02:00
|
|
|
|
|
|
|
if (ctx.editMode) {
|
2016-06-17 20:25:44 +02:00
|
|
|
this.sidebarControl = new PostEditSidebarControl(
|
2016-07-22 13:27:52 +02:00
|
|
|
sidebarContainerNode,
|
|
|
|
ctx.post,
|
|
|
|
this._postContentControl,
|
2020-06-06 00:03:37 +02:00
|
|
|
this._postNotesOverlayControl
|
|
|
|
);
|
2016-06-12 18:08:50 +02:00
|
|
|
} else {
|
2016-06-17 20:25:44 +02:00
|
|
|
this.sidebarControl = new PostReadonlySidebarControl(
|
2020-06-06 00:03:37 +02:00
|
|
|
sidebarContainerNode,
|
|
|
|
ctx.post,
|
|
|
|
this._postContentControl
|
|
|
|
);
|
2016-06-12 18:08:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-17 20:25:44 +02:00
|
|
|
_installCommentForm() {
|
2016-06-12 18:08:50 +02:00
|
|
|
const commentFormContainer = document.querySelector(
|
2020-06-06 00:03:37 +02:00
|
|
|
"#content-holder .comment-form-container"
|
|
|
|
);
|
2016-06-12 18:08:50 +02:00
|
|
|
if (!commentFormContainer) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-12-24 21:49:39 +01:00
|
|
|
this.commentControl = new CommentControl(
|
2020-06-06 00:03:37 +02:00
|
|
|
commentFormContainer,
|
|
|
|
null,
|
|
|
|
true
|
|
|
|
);
|
2016-06-12 18:08:50 +02:00
|
|
|
}
|
|
|
|
|
2016-06-17 20:25:44 +02:00
|
|
|
_installComments(comments) {
|
2016-06-12 18:08:50 +02:00
|
|
|
const commentsContainerNode = document.querySelector(
|
2020-06-06 00:03:37 +02:00
|
|
|
"#content-holder .comments-container"
|
|
|
|
);
|
2016-06-17 20:25:44 +02:00
|
|
|
if (!commentsContainerNode) {
|
|
|
|
return;
|
2016-06-12 18:08:50 +02:00
|
|
|
}
|
2016-06-17 20:25:44 +02:00
|
|
|
|
|
|
|
this.commentListControl = new CommentListControl(
|
2020-06-06 00:03:37 +02:00
|
|
|
commentsContainerNode,
|
|
|
|
comments
|
|
|
|
);
|
2016-06-12 18:08:50 +02:00
|
|
|
}
|
2016-06-06 20:57:22 +02:00
|
|
|
}
|
|
|
|
|
2016-10-22 10:03:38 +02:00
|
|
|
module.exports = PostMainView;
|