X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/2fd421b115132cdea97ec5ccbbab412e02659ab7..refs/pull/261/head:/resources/assets/js/directives.js diff --git a/resources/assets/js/directives.js b/resources/assets/js/directives.js index 0929a9cf4..16d1ad2a4 100644 --- a/resources/assets/js/directives.js +++ b/resources/assets/js/directives.js @@ -839,11 +839,15 @@ module.exports = function (ngApp, events) { // no need for the event to do anything more. event.stopPropagation(); event.preventDefault(); + scope.closeBox(); + }); + + scope.closeBox = function () { element.remove(); scope.$destroy(); - }); + }; } - } + }; }]); ngApp.directive('commentEdit', [function () { @@ -851,7 +855,7 @@ module.exports = function (ngApp, events) { restrict: 'E', templateUrl: 'comment-reply.html', scope: { - comment: '=', + comment: '=' }, link: function (scope, element) { scope.isEdit = true; @@ -861,16 +865,20 @@ module.exports = function (ngApp, events) { event.stopPropagation(); event.preventDefault(); if (commentId === scope.comment.id && !scope.isNew) { - element.remove(); - scope.$destroy(); + scope.closeBox(); } }); + + scope.closeBox = function () { + element.remove(); + scope.$destroy(); + }; } - } + }; }]); - ngApp.directive('commentReplyLink', ['$document', '$compile', '$http', function ($document, $compile, $http) { + ngApp.directive('commentReplyLink', ['$document', '$compile', function ($document, $compile) { return { scope: { comment: '=' @@ -881,8 +889,9 @@ module.exports = function (ngApp, events) { scope.$destroy(); }); - element.on('click', function () { - var $container = element.parents('.comment-box').first(); + 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!'); return; @@ -916,4 +925,25 @@ module.exports = function (ngApp, events) { $existingElement.remove(); } }]); + + ngApp.directive('commentDeleteLink', ['$window', function ($window) { + return { + controller: 'CommentDeleteController', + scope: { + comment: '=' + }, + link: function (scope, element, attr, ctrl) { + + element.on('click', function(e) { + e.preventDefault(); + var resp = $window.confirm(trans('entities.comment_delete_confirm')); + if (!resp) { + return; + } + + ctrl.delete(scope.comment); + }); + } + }; + }]); };