summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/notes.js.coffee
diff options
context:
space:
mode:
Diffstat (limited to 'app/assets/javascripts/notes.js.coffee')
-rw-r--r--app/assets/javascripts/notes.js.coffee36
1 files changed, 33 insertions, 3 deletions
diff --git a/app/assets/javascripts/notes.js.coffee b/app/assets/javascripts/notes.js.coffee
index fa91baa07c0..82e210fed7d 100644
--- a/app/assets/javascripts/notes.js.coffee
+++ b/app/assets/javascripts/notes.js.coffee
@@ -75,6 +75,9 @@ class @Notes
# when issue status changes, we need to refresh data
$(document).on "issuable:change", @refresh
+ # when a key is clicked on the notes
+ $(document).on "keydown", ".js-note-text", @keydownNoteText
+
cleanBinding: ->
$(document).off "ajax:success", ".js-main-target-form"
$(document).off "ajax:success", ".js-discussion-note-form"
@@ -92,10 +95,19 @@ class @Notes
$(document).off "click", ".js-note-target-reopen"
$(document).off "click", ".js-note-target-close"
$(document).off "click", ".js-note-discard"
+ $(document).off "keydown", ".js-note-text"
$('.note .js-task-list-container').taskList('disable')
$(document).off 'tasklist:changed', '.note .js-task-list-container'
+ keydownNoteText: (e) ->
+ $this = $(this)
+ if $this.val() is '' and e.which is 38 #aka the up key
+ myLastNote = $("li.note[data-author-id='#{gon.current_user_id}'][data-editable]:last")
+ if myLastNote.length
+ myLastNoteEditBtn = myLastNote.find('.js-note-edit')
+ myLastNoteEditBtn.trigger('click', [true, myLastNote])
+
initRefresh: ->
clearInterval(Notes.interval)
Notes.interval = setInterval =>
@@ -343,7 +355,7 @@ class @Notes
Adds a hidden div with the original content of the note to fill the edit note form with
if the user cancels
###
- showEditForm: (e) ->
+ showEditForm: (e, scrollTo, myLastNote) ->
e.preventDefault()
note = $(this).closest(".note")
note.addClass "is-editting"
@@ -354,9 +366,27 @@ class @Notes
# Show the attachment delete link
note.find(".js-note-attachment-delete").show()
- new GLForm form
+ done = ($noteText) ->
+ # Neat little trick to put the cursor at the end
+ noteTextVal = $noteText.val()
+ $noteText.val('').val(noteTextVal);
- form.find(".js-note-text").focus()
+ new GLForm form
+ if scrollTo? and myLastNote?
+ # scroll to the bottom
+ # so the open of the last element doesn't make a jump
+ $('html, body').scrollTop($(document).height());
+ $('html, body').animate({
+ scrollTop: myLastNote.offset().top - 150
+ }, 500, ->
+ $noteText = form.find(".js-note-text")
+ $noteText.focus()
+ done($noteText)
+ );
+ else
+ $noteText = form.find('.js-note-text')
+ $noteText.focus()
+ done($noteText)
###
Called in response to clicking the edit note link