Skip to content
Snippets Groups Projects
Commit faa2481f authored by Marcelo Schmidt's avatar Marcelo Schmidt
Browse files

Make startTyping and stopTyping trigger on keyup instead of keydown (better...

Make startTyping and stopTyping trigger on keyup instead of keydown (better checking of input field);
parent bee3f9a3
No related merge requests found
......@@ -4,6 +4,7 @@
input = {}
editing = {}
selfTyping = new ReactiveVar false
typingTimeout = {}
init = ->
wrapper = $(".messages-container").find(".wrapper")
......@@ -90,7 +91,7 @@
KonchatNotification.removeRoomNotification(rid)
msg = input.value
input.value = ''
stopTyping()
stopTyping(rid)
Meteor.call 'sendMessage', { rid: rid, msg: msg, day: window.day }
deleteMsg = (element) ->
......@@ -99,25 +100,32 @@
if error
return Errors.throw error.reason
update = (id, input) ->
update = (id, rid, input) ->
if _.trim(input.value) isnt ''
msg = input.value
Meteor.call 'updateMessage', { id: id, msg: msg }
clearEditing()
stopTyping(rid)
startTyping = (rid, input) ->
if _.trim(input.value) isnt ''
unless self.typingTimeout
unless typingTimeout?[rid]
if Meteor.userId()?
selfTyping.set true
Meteor.call 'typingStatus', rid, true
self.typingTimeout = Meteor.setTimeout ->
stopTyping()
, 30000
Meteor.call 'typingStatus', rid
typingTimeout[rid] = Meteor.setTimeout ->
stopTyping(rid)
, 10000
else
stopTyping(rid)
stopTyping = ->
stopTyping = (rid) ->
selfTyping.set false
self.typingTimeout = null
if typingTimeout?[rid]?
clearTimeout(typingTimeout[rid])
typingTimeout[rid] = null
Meteor.call 'typingStatus', rid, false
bindEvents = ->
if wrapper?.length
......@@ -126,6 +134,32 @@
resize()
# toBottom() if self.scrollable
keyup = (rid, event) ->
input = event.currentTarget
k = event.which
keyCodes = [
13, # Enter
20, # Caps lock
16, # Shift
9, # Tab
27, # Escape Key
17, # Control Key
91, # Windows Command Key
19, # Pause Break
18, # Alt Key
93, # Right Click Point Key
45, # Insert Key
34, # Page Down
35, # Page Up
144, # Num Lock
145 # Scroll Lock
]
keyCodes.push i for i in [35..40] # Home, End, Arrow Keys
keyCodes.push i for i in [112..123] # F1 - F12
unless k in keyCodes
startTyping(rid, input)
keydown = (rid, event) ->
input = event.currentTarget
k = event.which
......@@ -134,7 +168,7 @@
event.preventDefault()
event.stopPropagation()
if editing.id
update(editing.id, input)
update(editing.id, rid, input)
else
send(rid, input)
return
......@@ -144,42 +178,21 @@
event.stopPropagation()
clearEditing()
return
else
keyCodes = [
20, # Caps lock
16, # Shift
9, # Tab
27, # Escape Key
17, # Control Key
91, # Windows Command Key
19, # Pause Break
18, # Alt Key
93, # Right Click Point Key
45, # Insert Key
34, # Page Down
35, # Page Up
144, # Num Lock
145 # Scroll Lock
]
keyCodes.push i for i in [35..40] # Home, End, Arrow Keys
keyCodes.push i for i in [112..123] # F1 - F12
unless k in keyCodes
startTyping(rid, input)
else if k is 38 or k is 40 # Arrow Up or down
if k is 38
return if input.value.slice(0, input.selectionStart).match(/[\n]/) isnt null
toPrevMessage()
else
return if input.value.slice(input.selectionEnd, input.value.length).match(/[\n]/) isnt null
toNextMessage()
else if k is 38 or k is 40 # Arrow Up or down
if k is 38
return if input.value.slice(0, input.selectionStart).match(/[\n]/) isnt null
toPrevMessage()
else
return if input.value.slice(input.selectionEnd, input.value.length).match(/[\n]/) isnt null
toNextMessage()
event.preventDefault()
event.stopPropagation()
event.preventDefault()
event.stopPropagation()
# isScrollable: isScrollable
# toBottom: toBottom
keydown: keydown
keyup: keyup
deleteMsg: deleteMsg
send: send
init: init
......
......@@ -318,6 +318,10 @@ Template.room.events
console.log 'room focus .input-message' if window.rocketDebug
KonchatNotification.removeRoomNotification(this._id)
'keyup .input-message': (event) ->
console.log 'room keyup .input-message',this._id if window.rocketDebug
ChatMessages.keyup(this._id, event, Template.instance())
'keydown .input-message': (event) ->
console.log 'room keydown .input-message',this._id if window.rocketDebug
ChatMessages.keydown(this._id, event, Template.instance())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment