Merge pull request #2376 from overleaf/cmg-no-comment-blur

Stop cancelling a comment on Safari from still creating it

GitOrigin-RevId: b2e6ca77caa9ba318d330f23dd88e04972c7c829
This commit is contained in:
Eric Mc Sween 2019-11-21 07:42:14 -05:00 committed by sharelatex
parent 11419845e8
commit 1c0dc0a13f
2 changed files with 16 additions and 36 deletions

View file

@ -477,7 +477,6 @@ script(type='text/ng-template', id='addCommentEntryTemplate')
ng-keypress="handleCommentKeyPress($event);"
placeholder=translate("add_your_comment_here")
focus-on="comment:new:open"
ng-blur="submitNewComment($event)"
)
.rp-entry-actions
button.rp-entry-button.rp-entry-button-cancel(

View file

@ -1,17 +1,5 @@
/* eslint-disable
max-len,
no-return-assign,
no-undef,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
define(['base'], App =>
define(['base'], App => {
let content = ''
App.directive('addCommentEntry', () => ({
restrict: 'E',
templateUrl: 'addCommentEntryTemplate',
@ -23,48 +11,41 @@ define(['base'], App =>
link(scope, element, attrs) {
scope.state = {
isAdding: false,
content: ''
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()
return setTimeout(() => scope.$broadcast('comment:new:open'))
setTimeout(() => scope.$broadcast('comment:new:open'))
}
scope.cancelNewComment = function() {
scope.state.isAdding = false
return scope.onCancel()
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) {
return scope.submitNewComment()
scope.submitNewComment()
}
}
}
return (scope.submitNewComment = function(event) {
// If this is from a blur event from clicking on cancel, ignore it.
if (event != null && event.type === 'blur') {
if (
// Includes relatedTarget workaround for Firefox
$(event.relatedTarget).hasClass('rp-entry-button-cancel') ||
$(event.originalEvent.explicitOriginalTarget).hasClass(
'rp-entry-button-cancel'
)
) {
return true
}
}
scope.submitNewComment = function(event) {
scope.onSubmit({ content: scope.state.content })
content = scope.state.content
scope.state.isAdding = false
return (scope.state.content = '')
})
scope.state.content = ''
}
}
})))
}))
})