mirror of
https://github.com/darkwire/darkwire.io.git
synced 2025-07-19 19:14:53 +00:00
Abstracted some window events
This commit is contained in:
parent
e27b4e1d5c
commit
e492945fcb
@ -1,18 +1,14 @@
|
|||||||
import AudioHandler from './audio';
|
import AudioHandler from './audio';
|
||||||
import CryptoUtil from './crypto';
|
import CryptoUtil from './crypto';
|
||||||
|
import WindowHandler from './window';
|
||||||
|
|
||||||
let fs = window.RequestFileSystem || window.webkitRequestFileSystem;
|
let fs = window.RequestFileSystem || window.webkitRequestFileSystem;
|
||||||
|
|
||||||
window.favicon = new Favico({
|
|
||||||
animation:'pop',
|
|
||||||
type : 'rectangle'
|
|
||||||
});
|
|
||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
const audio = new AudioHandler();
|
const audio = new AudioHandler();
|
||||||
const cryptoUtil = new CryptoUtil();
|
const cryptoUtil = new CryptoUtil();
|
||||||
|
const windowHandler = new WindowHandler();
|
||||||
|
|
||||||
let isActive = false;
|
|
||||||
let newMessages = 0;
|
let newMessages = 0;
|
||||||
let FADE_TIME = 150; // ms
|
let FADE_TIME = 150; // ms
|
||||||
let TYPING_TIMER_LENGTH = 400; // ms
|
let TYPING_TIMER_LENGTH = 400; // ms
|
||||||
@ -428,9 +424,8 @@ $(function() {
|
|||||||
// Whenever the server emits 'new message', update the chat body
|
// Whenever the server emits 'new message', update the chat body
|
||||||
socket.on('new message', function (data) {
|
socket.on('new message', function (data) {
|
||||||
// Don't show messages if no key
|
// Don't show messages if no key
|
||||||
if (!isActive) {
|
if (!windowHandler.isActive) {
|
||||||
newMessages++;
|
windowHandler.notifyFavicon();
|
||||||
favicon.badge(newMessages);
|
|
||||||
audio.play();
|
audio.play();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -505,16 +500,6 @@ $(function() {
|
|||||||
|
|
||||||
initChat();
|
initChat();
|
||||||
|
|
||||||
window.onfocus = function () {
|
|
||||||
isActive = true;
|
|
||||||
newMessages = 0;
|
|
||||||
favicon.reset();
|
|
||||||
};
|
|
||||||
|
|
||||||
window.onblur = function () {
|
|
||||||
isActive = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Nav links
|
// Nav links
|
||||||
$('a#settings-nav').click(function() {
|
$('a#settings-nav').click(function() {
|
||||||
$('#settings-modal').modal('show');
|
$('#settings-modal').modal('show');
|
||||||
|
40
src/js/window.js
Normal file
40
src/js/window.js
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
export default class WindowHandler {
|
||||||
|
constructor() {
|
||||||
|
this._isActive = false;
|
||||||
|
|
||||||
|
this.newMessages = 0;
|
||||||
|
this.favicon = new Favico({
|
||||||
|
animation:'pop',
|
||||||
|
type : 'rectangle'
|
||||||
|
});
|
||||||
|
|
||||||
|
this.bindEvents();
|
||||||
|
}
|
||||||
|
|
||||||
|
get isActive() {
|
||||||
|
return this._isActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
set isActive(active) {
|
||||||
|
this._isActive = active;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
notifyFavicon() {
|
||||||
|
this.newMessages++;
|
||||||
|
this.favicon.badge(this.newMessages);
|
||||||
|
}
|
||||||
|
|
||||||
|
bindEvents() {
|
||||||
|
window.onfocus = () => {
|
||||||
|
this._isActive = true;
|
||||||
|
this.newMessages = 0;
|
||||||
|
this.favicon.reset();
|
||||||
|
};
|
||||||
|
|
||||||
|
window.onblur = () => {
|
||||||
|
this._isActive = false;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user