};
}]);
-
- // Controller used to fetch all comments for a page
- ngApp.controller('CommentListController', ['$scope', '$http', '$timeout', '$location', function ($scope, $http, $timeout, $location) {
-
- function focusLinkedComment(linkedCommentId) {
- let comment = angular.element('#' + linkedCommentId);
- if (comment.length === 0) {
- return;
- }
-
- window.setupPageShow.goToText(linkedCommentId);
- }
- }]);
};
function data() {
return {
- commentHref: null,
trans: trans,
comments: [],
showEditor: false,
};
const computed = {
- commentId: {
- get: function () {
- return `comment-${this.comment.page_id}-${this.comment.id}`;
- },
- set: function () {
- this.commentHref = `#?cm=${this.commentId}`
- }
+ commentId: function () {
+ return `comment-${this.comment.page_id}-${this.comment.id}`;
+ },
+ commentHref: function () {
+ return `#?cm=${this.commentId}`;
}
};
function mounted() {
this.pageId = Number(this.$el.getAttribute('page-id'));
// let linkedCommentId = this.$route.query.cm;
- let linkedCommentId = null;
+ let linkedCommentId = getUrlParameter('cm');
this.$http.get(window.baseUrl(`/ajax/page/${this.pageId}/comments/`)).then(resp => {
if (!isCommentOpSuccess(resp)) {
// just show that no comments are available.
if (!linkedCommentId) {
return;
}
- focusLinkedComment(linkedCommentId);
+
+ // adding a setTimeout to give comment list some time to render.
+ setTimeout(function() {
+ focusLinkedComment(linkedCommentId);
+ });
}).catch(err => {
- this.$events.emit('error', 'errors.comment_list');
+ this.$events.emit('error', trans('errors.comment_list'));
});
}
this.$off('new-comment');
}
+function getUrlParameter(name) {
+ name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
+ var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
+ var results = regex.exec(location.hash);
+ return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
+}
+
+function focusLinkedComment(linkedCommentId) {
+ let comment = document.getElementById(linkedCommentId);
+ if (comment && comment.length === 0) {
+ return;
+ }
+
+ window.setupPageShow.goToText(linkedCommentId);
+}
+
module.exports = {
data, methods, mounted, computed, components: {
comment, commentReply