Commit 09c85ccb authored by Douwe Maan's avatar Douwe Maan

Use switch/when statement

parent 0deec938
...@@ -106,14 +106,17 @@ class @Notes ...@@ -106,14 +106,17 @@ class @Notes
$textarea = $(e.target) $textarea = $(e.target)
# Edit previous note when UP arrow is hit # Edit previous note when UP arrow is hit
if $textarea.val() is '' and e.which is 38 switch e.which
when 38
return unless $textarea.val() is ''
myLastNote = $("li.note[data-author-id='#{gon.current_user_id}'][data-editable]:last") myLastNote = $("li.note[data-author-id='#{gon.current_user_id}'][data-editable]:last")
if myLastNote.length if myLastNote.length
myLastNoteEditBtn = myLastNote.find('.js-note-edit') myLastNoteEditBtn = myLastNote.find('.js-note-edit')
myLastNoteEditBtn.trigger('click', [true, myLastNote]) myLastNoteEditBtn.trigger('click', [true, myLastNote])
# Cancel creating diff note or editing any note when ESCAPE is hit # Cancel creating diff note or editing any note when ESCAPE is hit
if e.which is 27 when 27
discussionNoteForm = $textarea.closest('.js-discussion-note-form') discussionNoteForm = $textarea.closest('.js-discussion-note-form')
if discussionNoteForm.length if discussionNoteForm.length
if $textarea.val() isnt '' if $textarea.val() isnt ''
...@@ -122,7 +125,7 @@ class @Notes ...@@ -122,7 +125,7 @@ class @Notes
@removeDiscussionNoteForm(discussionNoteForm) @removeDiscussionNoteForm(discussionNoteForm)
return return
editNote = $textarea.closest(".note") editNote = $textarea.closest('.note')
if editNote.length if editNote.length
originalText = $textarea.closest('form').data('original-note') originalText = $textarea.closest('form').data('original-note')
newText = $textarea.val() newText = $textarea.val()
...@@ -427,7 +430,7 @@ class @Notes ...@@ -427,7 +430,7 @@ class @Notes
### ###
cancelEdit: (e) => cancelEdit: (e) =>
e.preventDefault() e.preventDefault()
note = $(e.target).closest(".note") note = $(e.target).closest('.note')
@removeNoteEditForm(note) @removeNoteEditForm(note)
removeNoteEditForm: (note) -> removeNoteEditForm: (note) ->
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment