Docs: Difference between revisions
Appearance
Event listener elm chat close |
No edit summary |
||
Line 2,457: | Line 2,457: | ||
|elm.chatbar | |elm.chatbar | ||
|keydown | |keydown | ||
| | |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); | |||
} | |||
| | | | ||
| | | | ||
Line 2,515: | Line 2,596: | ||
chatOpen = false; | chatOpen = false; | ||
|"chatClose" | |||
| | | | ||
|<syntaxhighlight lang="javascript" line="1" start="328"> | |<syntaxhighlight lang="javascript" line="1" start="328"> | ||
elm.chat_close.addEventListener("click", function() { | elm.chat_close.addEventListener("click", function() { | ||
Line 2,523: | Line 2,604: | ||
elm.chat_open.style.display = ""; | elm.chat_open.style.display = ""; | ||
chatOpen = false; | chatOpen = false; | ||
}); | |||
</syntaxhighlight> | |||
|- | |||
|elm.chat_open | |||
|click | |||
|elm.chat_window.style.display = ""; | |||
elm.chat_open.style.display = "none"; | |||
chatOpen = true; | |||
if(selectedChatTab == 0) { | |||
chatPageUnread = 0; | |||
updateUnread(); | |||
if(!initPageTabOpen) { | |||
initPageTabOpen = true; | |||
elm.page_chatfield.scrollTop = elm.page_chatfield.scrollHeight; | |||
} | |||
} else { | |||
chatGlobalUnread = 0; | |||
updateUnread(); | |||
if(!initGlobalTabOpen) { | |||
initGlobalTabOpen = true; | |||
elm.global_chatfield.scrollTop = elm.global_chatfield.scrollHeight; | |||
} | |||
} | |||
var chatWidth = chat_window.offsetWidth - 2; | |||
var chatHeight = chat_window.offsetHeight - 2; | |||
var screenRatio = window.devicePixelRatio; | |||
if(!screenRatio) screenRatio = 1; | |||
var virtWidth = owotWidth / screenRatio; | |||
if(chatWidth > virtWidth) { | |||
resizeChat(virtWidth - 2, chatHeight); | |||
} | |||
|"chatOpen" | |||
| | |||
|<syntaxhighlight lang="javascript" line="1" start="335"> | |||
elm.chat_open.addEventListener("click", function() { | |||
w.emit("chatOpen"); | |||
elm.chat_window.style.display = ""; | |||
elm.chat_open.style.display = "none"; | |||
chatOpen = true; | |||
if(selectedChatTab == 0) { | |||
chatPageUnread = 0; | |||
updateUnread(); | |||
if(!initPageTabOpen) { | |||
initPageTabOpen = true; | |||
elm.page_chatfield.scrollTop = elm.page_chatfield.scrollHeight; | |||
} | |||
} else { | |||
chatGlobalUnread = 0; | |||
updateUnread(); | |||
if(!initGlobalTabOpen) { | |||
initGlobalTabOpen = true; | |||
elm.global_chatfield.scrollTop = elm.global_chatfield.scrollHeight; | |||
} | |||
} | |||
var chatWidth = chat_window.offsetWidth - 2; | |||
var chatHeight = chat_window.offsetHeight - 2; | |||
var screenRatio = window.devicePixelRatio; | |||
if(!screenRatio) screenRatio = 1; | |||
var virtWidth = owotWidth / screenRatio; | |||
if(chatWidth > virtWidth) { | |||
resizeChat(virtWidth - 2, chatHeight); | |||
} | |||
}); | |||
</syntaxhighlight> | |||
|- | |||
|elm.chat_page_tab | |||
|click | |||
|elm.chat_page_tab.classList.add("chat_tab_selected"); | |||
elm.chat_global_tab.classList.remove("chat_tab_selected"); | |||
elm.global_chatfield.style.display = "none"; | |||
elm.page_chatfield.style.display = ""; | |||
selectedChatTab = 0; | |||
chatPageUnread = 0; | |||
updateUnread(); | |||
if(!initPageTabOpen) { | |||
initPageTabOpen = true; | |||
elm.page_chatfield.scrollTop = elm.page_chatfield.scrollHeight; | |||
} | |||
| | |||
| | |||
|<syntaxhighlight lang="js" line="1" start="365"> | |||
elm.chat_page_tab.addEventListener("click", function() { | |||
elm.chat_page_tab.classList.add("chat_tab_selected"); | |||
elm.chat_global_tab.classList.remove("chat_tab_selected"); | |||
elm.global_chatfield.style.display = "none"; | |||
elm.page_chatfield.style.display = ""; | |||
selectedChatTab = 0; | |||
chatPageUnread = 0; | |||
updateUnread(); | |||
if(!initPageTabOpen) { | |||
initPageTabOpen = true; | |||
elm.page_chatfield.scrollTop = elm.page_chatfield.scrollHeight; | |||
} | |||
}); | }); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
|} | |} |