]> BookStack Code Mirror - bookstack/commitdiff
Added functionality to highlight a comment.
authorAbijeet <redacted>
Mon, 21 Aug 2017 20:01:11 +0000 (01:31 +0530)
committerAbijeet <redacted>
Mon, 21 Aug 2017 20:01:11 +0000 (01:31 +0530)
resources/assets/js/controllers.js
resources/assets/js/vues/components/comments/comment.js
resources/assets/js/vues/page-comments.js

index 7f2e6cdb4486597537196c011707383ffe6796bd..32ff76fa167bc9dad0a470a2429ed147ad4a3718 100644 (file)
@@ -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);
-        }
-    }]);
 };
index ada638526b95433be535da84ab5fdade3bc1ae68..419c0a5fa9890f00affeb64f4694a99acff16744 100644 (file)
@@ -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}`;
     }
 };
 
index 76d11ac6c4a6d520bff13cfb443b18cb28d434d8..4cdee05edab0fbef81d41ac3afa1e20afc56c0c8 100644 (file)
@@ -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