overleaf/services/web/frontend/js/ide/review-panel/directives/addCommentEntry.js
Alasdair Smith 8f5270899f Merge pull request #2707 from overleaf/as-transform-esm
Transform frontend module format from AMD to ESM

GitOrigin-RevId: 9adbcdc95e819a54114010c6fd3521d8f58ef2fe
2020-05-20 03:21:38 +00:00

50 lines
1.2 KiB
JavaScript

import App from '../../../base'
let content = ''
App.directive('addCommentEntry', () => ({
restrict: 'E',
templateUrl: 'addCommentEntryTemplate',
scope: {
onStartNew: '&',
onSubmit: '&',
onCancel: '&'
},
link(scope, element, attrs) {
scope.state = {
isAdding: false,
content: content
}
scope.$on('comment:start_adding', () => scope.startNewComment())
scope.$on('$destroy', function() {
content = scope.state.content
})
scope.startNewComment = function() {
scope.state.isAdding = true
scope.onStartNew()
setTimeout(() => scope.$broadcast('comment:new:open'))
}
scope.cancelNewComment = function() {
scope.state.isAdding = false
scope.state.content = ''
scope.onCancel()
}
scope.handleCommentKeyPress = function(ev) {
if (ev.keyCode === 13 && !ev.shiftKey && !ev.ctrlKey && !ev.metaKey) {
ev.preventDefault()
if (scope.state.content.length > 0) {
scope.submitNewComment()
}
}
}
scope.submitNewComment = function(event) {
scope.onSubmit({ content: scope.state.content })
content = scope.state.content
scope.state.isAdding = false
scope.state.content = ''
}
}
}))