1 const comment = require('./components/comments/comment');
2 const commentReply = require('./components/comments/comment-reply');
5 totalCommentsStr: trans('entities.comments_loading'),
14 commentAdded: function () {
22 return this.commentCount;
24 set: function (value) {
25 this.commentCount = value;
27 this.totalCommentsStr = trans('entities.no_comments');
28 } else if (value === 1) {
29 this.totalCommentsStr = trans('entities.one_comment');
31 this.totalCommentsStr = trans('entities.x_comments', {
37 canComment: function () {
38 if (!this.permissions) {
41 return this.permissions.comment_create === true;
46 this.pageId = Number(this.$el.getAttribute('page-id'));
47 let linkedCommentId = getUrlParameter('cm');
48 this.$http.get(window.baseUrl(`/ajax/page/${this.pageId}/comments/`)).then(resp => {
49 if (!isCommentOpSuccess(resp)) {
50 // just show that no comments are available.
52 this.$events.emit('error', getErrorMsg(resp));
55 this.comments = resp.data.comments;
56 this.totalComments = +resp.data.total;
57 this.permissions = resp.data.permissions;
58 this.currentUserId = resp.data.user_id;
59 if (!linkedCommentId) {
63 // adding a setTimeout to give the comment list some time to render
64 // before focusing the comment.
65 setTimeout(function() {
66 focusLinkedComment(linkedCommentId);
69 this.$events.emit('error', trans('errors.comment_list'));
73 function isCommentOpSuccess(resp) {
74 if (resp && resp.data && resp.data.status === 'success') {
80 function getErrorMsg(response) {
82 return response.data.message;
84 return trans('errors.comment_add');
89 this.$on('new-comment', function (event, comment) {
90 this.comments.push(comment);
94 function beforeDestroy() {
95 this.$off('new-comment');
98 function getUrlParameter(name) {
99 name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
100 var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
101 var results = regex.exec(location.hash);
102 return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
105 function focusLinkedComment(linkedCommentId) {
106 let comment = document.getElementById(linkedCommentId);
107 if (comment && comment.length !== 0) {
108 window.setupPageShow.goToText(linkedCommentId);
113 data, methods, mounted, computed, components: {
114 comment, commentReply
116 created, beforeDestroy