Docs: Difference between revisions
Appearance
I tried my best ,added some event listeners in chat |
Event listener elm chat close |
||
Line 2,455: | Line 2,455: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
|- | |- | ||
|elm.chatbar | |||
|keydown | |||
|See related code | |||
| | | | ||
| | | | ||
|<syntaxhighlight lang="javascript" line="1" start="283"> | |||
elm.chatbar.addEventListener("keydown", function(e) { | |||
var keyCode = e.keyCode; | |||
// scroll through chat history that the client sent | |||
if(keyCode == 38) { // up | |||
// history modified | |||
if(chatWriteHistoryIdx > -1 && elm.chatbar.value != chatWriteHistory[chatWriteHistory.length - chatWriteHistoryIdx - 1]) { | |||
chatWriteHistory[chatWriteHistory.length - chatWriteHistoryIdx - 1] = elm.chatbar.value; | |||
} | |||
if(chatWriteHistoryIdx == -1 && elm.chatbar.value) { | |||
chatWriteTmpBuffer = elm.chatbar.value; | |||
} | |||
chatWriteHistoryIdx++; | |||
if(chatWriteHistoryIdx >= chatWriteHistory.length) chatWriteHistoryIdx = chatWriteHistory.length - 1; | |||
var upVal = chatWriteHistory[chatWriteHistory.length - chatWriteHistoryIdx - 1]; | |||
if(!upVal) return; | |||
elm.chatbar.value = upVal; | |||
// pressing up will move the cursor all the way to the left by default | |||
e.preventDefault(); | |||
moveCaretEnd(elm.chatbar); | |||
} else if(keyCode == 40) { // down | |||
// history modified | |||
if(chatWriteHistoryIdx > -1 && elm.chatbar.value != chatWriteHistory[chatWriteHistory.length - chatWriteHistoryIdx - 1]) { | |||
chatWriteHistory[chatWriteHistory.length - chatWriteHistoryIdx - 1] = elm.chatbar.value; | |||
} | |||
chatWriteHistoryIdx--; | |||
if(chatWriteHistoryIdx < -1) { | |||
chatWriteHistoryIdx = -1; | |||
return; | |||
} | |||
var str = ""; | |||
if(chatWriteHistoryIdx != -1) { | |||
str = chatWriteHistory[chatWriteHistory.length - chatWriteHistoryIdx - 1]; | |||
} else { | |||
if(chatWriteTmpBuffer) { | |||
str = chatWriteTmpBuffer; | |||
e.preventDefault(); | |||
moveCaretEnd(elm.chatbar); | |||
} | |||
} | |||
elm.chatbar.value = str; | |||
e.preventDefault(); | |||
moveCaretEnd(elm.chatbar); | |||
} | |||
}); | |||
</syntaxhighlight> | |||
|- | |||
|elm.chat_close | |||
|click | |||
|w.emit("chatClose"); | |||
elm.chat_window.style.display = "none"; | |||
elm.chat_open.style.display = ""; | |||
chatOpen = false; | |||
| | | | ||
| | |chatClose | ||
| | |<syntaxhighlight lang="javascript" line="1" start="328"> | ||
elm.chat_close.addEventListener("click", function() { | |||
w.emit("chatClose"); | |||
elm.chat_window.style.display = "none"; | |||
elm.chat_open.style.display = ""; | |||
chatOpen = false; | |||
}); | |||
</syntaxhighlight> | |||
|} | |} |