diff --git a/app/assets/javascripts/app/controllers/chat.coffee b/app/assets/javascripts/app/controllers/chat.coffee index 59369c927..595b76e16 100644 --- a/app/assets/javascripts/app/controllers/chat.coffee +++ b/app/assets/javascripts/app/controllers/chat.coffee @@ -372,7 +372,7 @@ class ChatWindow extends App.Controller @chat = App.Chat.find(@session.chat_id) @name = "#{@chat.displayName()} ##{@session.id}" - @on 'layout-change', @scrollToBottom + @on 'layout-change', @onLayoutChange @bind('chat_session_typing', (data) => return if data.session_id isnt @session.session_id @@ -406,6 +406,9 @@ class ChatWindow extends App.Controller @focus() ) + onLayoutChange: => + @scrollToBottom() + render: -> @html App.view('customer_chat/chat_window') name: @name @@ -609,7 +612,7 @@ class ChatWindow extends App.Controller isNew: isNew timestamp: Date.now() - @scrollToBottom() + @scrollToBottom showHint: true showWritingLoader: => if !@isTyping @@ -685,16 +688,19 @@ class ChatWindow extends App.Controller scrollBottom = @scrollHolder.scrollTop() + @scrollHolder.height() @scrolledToBottom = Math.abs(scrollBottom - @scrollHolder.prop('scrollHeight')) <= @scrollSnapTolerance + showScrollHint: -> + @scrollHint.removeClass('is-hidden') + onScrollHintClick: -> # animate scroll @scrollHolder.animate({scrollTop: @scrollHolder.prop('scrollHeight')}, 300) @scrollHint.addClass('is-hidden') - scrollToBottom: -> + scrollToBottom: ({ showHint } = { showHint: false }) -> if @scrolledToBottom @scrollHolder.scrollTop(@scrollHolder.prop('scrollHeight')) - else - @scrollHint.removeClass('is-hidden') + else if showHint + @showScrollHint() class Setting extends App.ControllerModal buttonClose: true