mirror of
https://github.com/darkwire/darkwire.io.git
synced 2025-07-25 13:26:26 +00:00
Key definitions. Moving window to window handler
This commit is contained in:
parent
7fa4517e01
commit
87802963f9
@ -13,9 +13,7 @@ $(function() {
|
|||||||
const darkwire = new Darkwire();
|
const darkwire = new Darkwire();
|
||||||
const cryptoUtil = new CryptoUtil();
|
const cryptoUtil = new CryptoUtil();
|
||||||
|
|
||||||
let $window = $(window);
|
|
||||||
let $participants = $('#participants');
|
let $participants = $('#participants');
|
||||||
let keyMapping = [];
|
|
||||||
|
|
||||||
let roomId = window.location.pathname.length ? window.location.pathname : null;
|
let roomId = window.location.pathname.length ? window.location.pathname : null;
|
||||||
|
|
||||||
@ -68,25 +66,6 @@ $(function() {
|
|||||||
return sanitized;
|
return sanitized;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Keyboard events
|
|
||||||
$window.keydown((event) => {
|
|
||||||
// When the client hits ENTER on their keyboard and chat message input is focused
|
|
||||||
if (event.which === 13 && !event.shiftKey && $('.inputMessage').is(':focus')) {
|
|
||||||
handleMessageSending();
|
|
||||||
socket.emit('stop typing');
|
|
||||||
chat.typing = false;
|
|
||||||
event.preventDefault();
|
|
||||||
} else {
|
|
||||||
keyMapping[event.keyCode] = event.type === 'keydown';
|
|
||||||
}
|
|
||||||
|
|
||||||
}).keyup((event) => {
|
|
||||||
if ((keyMapping[17] || keyMapping[91] || keyMapping[93]) && keyMapping[75]) {
|
|
||||||
chat.clear();
|
|
||||||
}
|
|
||||||
keyMapping = [];
|
|
||||||
});
|
|
||||||
|
|
||||||
// Select message input when closing modal
|
// Select message input when closing modal
|
||||||
$('.modal').on('hidden.bs.modal', function(e) {
|
$('.modal').on('hidden.bs.modal', function(e) {
|
||||||
chat.inputMessage.focus();
|
chat.inputMessage.focus();
|
||||||
@ -205,7 +184,7 @@ $(function() {
|
|||||||
darkwire.audio.soundEnabled = state;
|
darkwire.audio.soundEnabled = state;
|
||||||
});
|
});
|
||||||
|
|
||||||
function handleMessageSending() {
|
window.handleMessageSending = function() {
|
||||||
let message = chat.inputMessage;
|
let message = chat.inputMessage;
|
||||||
let cleanedMessage = cleanInput(message.val());
|
let cleanedMessage = cleanInput(message.val());
|
||||||
let slashCommand = chat.parseCommand(cleanedMessage);
|
let slashCommand = chat.parseCommand(cleanedMessage);
|
||||||
@ -227,7 +206,7 @@ $(function() {
|
|||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
window.triggerFileTransfer = function(context) {
|
window.triggerFileTransfer = function(context) {
|
||||||
const fileId = context.getAttribute('data-file');
|
const fileId = context.getAttribute('data-file');
|
||||||
|
@ -4,6 +4,9 @@ export default class WindowHandler {
|
|||||||
constructor(darkwire, socket, chat) {
|
constructor(darkwire, socket, chat) {
|
||||||
this._isActive = false;
|
this._isActive = false;
|
||||||
this.fileHandler = new FileHandler(darkwire, socket, chat);
|
this.fileHandler = new FileHandler(darkwire, socket, chat);
|
||||||
|
this.socket = socket;
|
||||||
|
this.chat = chat;
|
||||||
|
this.keyMapping = [];
|
||||||
|
|
||||||
this.newMessages = 0;
|
this.newMessages = 0;
|
||||||
this.favicon = new Favico({
|
this.favicon = new Favico({
|
||||||
@ -52,6 +55,32 @@ export default class WindowHandler {
|
|||||||
this._isActive = false;
|
this._isActive = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Keyboard events
|
||||||
|
window.onkeydown = (event) => {
|
||||||
|
// When the client hits ENTER on their keyboard and chat message input is focused
|
||||||
|
if (event.which === 13 && !event.shiftKey && $('.inputMessage').is(':focus')) {
|
||||||
|
handleMessageSending();
|
||||||
|
this.socket.emit('stop typing');
|
||||||
|
this.chat.typing = false;
|
||||||
|
event.preventDefault();
|
||||||
|
} else {
|
||||||
|
this.keyMapping[event.keyCode] = event.type === 'keydown';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
window.onkeyup = (event) => {
|
||||||
|
/**
|
||||||
|
* 17: CTRL
|
||||||
|
* 91: Left CMD
|
||||||
|
* 93: Right CMD
|
||||||
|
* 75: K
|
||||||
|
*/
|
||||||
|
if ((this.keyMapping[17] || this.keyMapping[91] || this.keyMapping[93]) && this.keyMapping[75]) {
|
||||||
|
this.chat.clear();
|
||||||
|
}
|
||||||
|
this.keyMapping = [];
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user