From b403a621a3bd67c5a4fcb348e14c41fcd29d12d9 Mon Sep 17 00:00:00 2001 From: Felix Niklas Date: Mon, 4 Jul 2016 16:29:42 +0200 Subject: [PATCH] customer chat: only show hint on new message --- .../javascripts/app/controllers/chat.coffee | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) 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