From b5cd3bff3cd9ede7277a60927857101cf75614cc Mon Sep 17 00:00:00 2001 From: Abijeet Date: Tue, 22 Aug 2017 01:31:11 +0530 Subject: [PATCH] Added functionality to highlight a comment. --- resources/assets/js/controllers.js | 13 ---------- .../js/vues/components/comments/comment.js | 13 ++++------ resources/assets/js/vues/page-comments.js | 26 ++++++++++++++++--- 3 files changed, 28 insertions(+), 24 deletions(-) diff --git a/resources/assets/js/controllers.js b/resources/assets/js/controllers.js index 7f2e6cdb4..32ff76fa1 100644 --- a/resources/assets/js/controllers.js +++ b/resources/assets/js/controllers.js @@ -144,17 +144,4 @@ module.exports = function (ngApp, events) { }; }]); - - // 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); - } - }]); }; diff --git a/resources/assets/js/vues/components/comments/comment.js b/resources/assets/js/vues/components/comments/comment.js index ada638526..419c0a5fa 100644 --- a/resources/assets/js/vues/components/comments/comment.js +++ b/resources/assets/js/vues/components/comments/comment.js @@ -59,7 +59,6 @@ const props = ['initialComment', 'index', 'level', 'permissions', 'currentUserId function data() { return { - commentHref: null, trans: trans, comments: [], showEditor: false, @@ -144,13 +143,11 @@ const methods = { }; 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}`; } }; diff --git a/resources/assets/js/vues/page-comments.js b/resources/assets/js/vues/page-comments.js index 76d11ac6c..4cdee05ed 100644 --- a/resources/assets/js/vues/page-comments.js +++ b/resources/assets/js/vues/page-comments.js @@ -45,7 +45,7 @@ let computed = { 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. @@ -60,9 +60,13 @@ function mounted() { 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')); }); } @@ -91,6 +95,22 @@ function beforeDestroy() { 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