From e647ec22b1e4b6ca565ad9b9269deefe36da2ea6 Mon Sep 17 00:00:00 2001 From: Abijeet Date: Thu, 8 Jun 2017 01:14:53 +0530 Subject: [PATCH] #47 - Adds direct linking to comments. --- resources/assets/js/controllers.js | 23 ++++++++++++++++++-- resources/assets/js/directives.js | 16 ++++++++------ resources/assets/js/pages/page-show.js | 2 ++ resources/views/comments/list-item.blade.php | 2 +- 4 files changed, 33 insertions(+), 10 deletions(-) diff --git a/resources/assets/js/controllers.js b/resources/assets/js/controllers.js index a929f4aed..c1bfd441f 100644 --- a/resources/assets/js/controllers.js +++ b/resources/assets/js/controllers.js @@ -776,7 +776,7 @@ module.exports = function (ngApp, events) { }]); // Controller used to fetch all comments for a page - ngApp.controller('CommentListController', ['$scope', '$http', '$timeout', function ($scope, $http, $timeout) { + ngApp.controller('CommentListController', ['$scope', '$http', '$timeout', '$location', function ($scope, $http, $timeout, $location) { let vm = this; $scope.errors = {}; // keep track of comment levels @@ -808,7 +808,7 @@ module.exports = function (ngApp, events) { if (vm.permissions[propOwn] && comment.created_by.id === vm.current_user_id) { return true; } - + return false; }; @@ -816,6 +816,9 @@ module.exports = function (ngApp, events) { return vm.permissions.comment_create; }; + // check if there are is any direct linking + let linkedCommentId = $location.search().cm; + $timeout(function() { $http.get(window.baseUrl(`/ajax/page/${$scope.pageId}/comments/`)).then(resp => { if (!isCommentOpSuccess(resp)) { @@ -829,6 +832,13 @@ module.exports = function (ngApp, events) { vm.permissions = resp.data.permissions; vm.current_user_id = resp.data.user_id; setTotalCommentMsg(); + if (!linkedCommentId) { + return; + } + $timeout(function() { + // wait for the UI to render. + focusLinkedComment(linkedCommentId); + }); }, checkError); }); @@ -844,6 +854,15 @@ module.exports = function (ngApp, events) { } } + function focusLinkedComment(linkedCommentId) { + let comment = angular.element('#' + linkedCommentId); + if (comment.length === 0) { + return; + } + + window.setupPageShow.goToText(linkedCommentId); + } + function checkError(response) { let msg = null; if (isCommentOpSuccess(response)) { diff --git a/resources/assets/js/directives.js b/resources/assets/js/directives.js index 0b9402a6b..bbdf1a0ae 100644 --- a/resources/assets/js/directives.js +++ b/resources/assets/js/directives.js @@ -889,7 +889,8 @@ module.exports = function (ngApp, events) { scope.$destroy(); }); - element.on('click', function () { + element.on('click', function (e) { + e.preventDefault(); var $container = element.parents('.comment-actions').first(); if (!$container.length) { console.error('commentReplyLink directive should be placed inside a container with class comment-box!'); @@ -933,13 +934,14 @@ module.exports = function (ngApp, events) { }, link: function (scope, element, attr, ctrl) { - element.on('click', function() { - var resp = $window.confirm('This will remove the content of the comment, are you sure you want to continue?'); - if (!resp) { - return; - } + element.on('click', function(e) { + e.preventDefault(); + var resp = $window.confirm('This will remove the content of the comment, are you sure you want to continue?'); + if (!resp) { + return; + } - ctrl.delete(scope.comment); + ctrl.delete(scope.comment); }); } }; diff --git a/resources/assets/js/pages/page-show.js b/resources/assets/js/pages/page-show.js index 67d339d63..020229d2f 100644 --- a/resources/assets/js/pages/page-show.js +++ b/resources/assets/js/pages/page-show.js @@ -161,6 +161,8 @@ let setupPageShow = window.setupPageShow = function (pageId) { } }); + // in order to call from other places. + window.setupPageShow.goToText = goToText; }; module.exports = setupPageShow; \ No newline at end of file diff --git a/resources/views/comments/list-item.blade.php b/resources/views/comments/list-item.blade.php index 6904a4abf..391e64baf 100644 --- a/resources/views/comments/list-item.blade.php +++ b/resources/views/comments/list-item.blade.php @@ -17,7 +17,7 @@
  • {{ trans('entities.comment_reply') }}
  • {{ trans('entities.comment_edit') }}
  • {{ trans('entities.comment_delete') }}
  • -
  • Created @{{::comment.created.diff}}
  • +
  • Created @{{::comment.created.diff}}
  • @{{ ::vm.trans('entities.comment_updated_text', { updateDiff: comment.updated.diff }) }} @{{::comment.updated_by.name}}