mirror of
https://github.com/wbbaddons/Tims-Chat.git
synced 2024-12-22 21:40:08 +00:00
Automagically disable scrolling when user scrolls
This commit is contained in:
parent
8f6b7c5e12
commit
c1fac59618
@ -18,6 +18,7 @@ TimWolla.WCF ?= {}
|
|||||||
isActive: true
|
isActive: true
|
||||||
autocompleteOffset: 0
|
autocompleteOffset: 0
|
||||||
autocompleteValue: null
|
autocompleteValue: null
|
||||||
|
scrollHeightTopDiff: null
|
||||||
events:
|
events:
|
||||||
newMessage: $.Callbacks()
|
newMessage: $.Callbacks()
|
||||||
userMenu: $.Callbacks()
|
userMenu: $.Callbacks()
|
||||||
@ -72,6 +73,7 @@ TimWolla.WCF ?= {}
|
|||||||
, @
|
, @
|
||||||
|
|
||||||
$('#chatInput').keydown $.proxy (event) ->
|
$('#chatInput').keydown $.proxy (event) ->
|
||||||
|
# tab key
|
||||||
if event.keyCode is 9
|
if event.keyCode is 9
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
if @autocompleteValue is null
|
if @autocompleteValue is null
|
||||||
@ -104,6 +106,12 @@ TimWolla.WCF ?= {}
|
|||||||
element.data 'status', 1
|
element.data 'status', 1
|
||||||
icon.attr 'src', icon.attr('src').replace /disabled(\d?).([a-z]{3})$/, 'enabled$1.$2'
|
icon.attr 'src', icon.attr('src').replace /disabled(\d?).([a-z]{3})$/, 'enabled$1.$2'
|
||||||
element.attr 'title', element.data 'disableMessage'
|
element.attr 'title', element.data 'disableMessage'
|
||||||
|
|
||||||
|
$('#chatAutoscroll').click (event) ->
|
||||||
|
$(this).removeClass('hot')
|
||||||
|
if $(this).data 'status'
|
||||||
|
$('.chatMessageContainer').scrollTop $('.chatMessageContainer ul').height()
|
||||||
|
|
||||||
if typeof window.webkitNotifications isnt 'undefined'
|
if typeof window.webkitNotifications isnt 'undefined'
|
||||||
$('#chatNotify').click (event) ->
|
$('#chatNotify').click (event) ->
|
||||||
window.webkitNotifications.requestPermission() if $(this).data 'status'
|
window.webkitNotifications.requestPermission() if $(this).data 'status'
|
||||||
@ -182,7 +190,7 @@ TimWolla.WCF ?= {}
|
|||||||
fish.animate
|
fish.animate
|
||||||
top: '+=' + top
|
top: '+=' + top
|
||||||
left: '+=' + left
|
left: '+=' + left
|
||||||
, 1000
|
, 1e3
|
||||||
, 1.5e3);
|
, 1.5e3);
|
||||||
###
|
###
|
||||||
# Loads new messages.
|
# Loads new messages.
|
||||||
@ -201,6 +209,13 @@ TimWolla.WCF ?= {}
|
|||||||
# @param array<object> messages
|
# @param array<object> messages
|
||||||
###
|
###
|
||||||
handleMessages: (messages) ->
|
handleMessages: (messages) ->
|
||||||
|
# disable scrolling automagically when user manually scrolled
|
||||||
|
if @scrollHeightTopDiff isnt null
|
||||||
|
if @scrollHeightTopDiff isnt $('.chatMessageContainer ul').height() - $('.chatMessageContainer').scrollTop()
|
||||||
|
if $('#chatAutoscroll').data('status') is 1
|
||||||
|
$('#chatAutoscroll').click()
|
||||||
|
$('#chatAutoscroll').addClass('hot').fadeOut('slow').fadeIn('slow')
|
||||||
|
|
||||||
for message in messages
|
for message in messages
|
||||||
@events.newMessage.fire message
|
@events.newMessage.fire message
|
||||||
|
|
||||||
@ -211,9 +226,11 @@ TimWolla.WCF ?= {}
|
|||||||
li.append output
|
li.append output
|
||||||
|
|
||||||
li.appendTo $ '.chatMessageContainer ul'
|
li.appendTo $ '.chatMessageContainer ul'
|
||||||
$('.chatMessageContainer').animate
|
|
||||||
scrollTop: $('.chatMessageContainer ul').height()
|
# autoscroll down
|
||||||
, 1000
|
if $('#chatAutoscroll').data('status') is 1
|
||||||
|
$('.chatMessageContainer').scrollTop $('.chatMessageContainer ul').height()
|
||||||
|
@scrollHeightTopDiff = $('.chatMessageContainer ul').height() - $('.chatMessageContainer').scrollTop()
|
||||||
handleUsers: (users) ->
|
handleUsers: (users) ->
|
||||||
foundUsers = {}
|
foundUsers = {}
|
||||||
for user in users
|
for user in users
|
||||||
|
Loading…
Reference in New Issue
Block a user