Skip to content
This repository has been archived by the owner on May 23, 2022. It is now read-only.

Commit

Permalink
Redid IncomingMessages.js to make it more straight to the point and e…
Browse files Browse the repository at this point in the history
…asier to manage. It -should- have better performance now too, but I haven't tested. Continued ES6 conversion. Added Patreon shield to the readme. 😟 Some more ES6 conversion
  • Loading branch information
Madison Tries committed Oct 24, 2015
1 parent 0f02816 commit 6b3acf1
Show file tree
Hide file tree
Showing 5 changed files with 181 additions and 194 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[![Maid IRC](public/img/logo_medium.png)](https://github.com/Phalanxia/Maid-IRC "Maid-IRC")
==

[![Build Status](https://img.shields.io/travis/Phalanxia/Maid-IRC.svg?style=flat-square)](https://travis-ci.org/Phalanxia/Maid-IRC) [![NPM version](https://img.shields.io/npm/v/maid-irc.svg?style=flat-square)](https://www.npmjs.org/package/maid-irc) [![Dependency Status](https://img.shields.io/gemnasium/Phalanxia/Maid-IRC.svg?style=flat-square)](https://gemnasium.com/Phalanxia/Maid-IRC) [![Downloads](https://img.shields.io/npm/dm/maid-irc.svg?style=flat-square)](https://www.npmjs.org/package/maid-irc)
[![Build Status](https://img.shields.io/travis/Phalanxia/Maid-IRC.svg?style=flat-square)](https://travis-ci.org/Phalanxia/Maid-IRC) [![NPM version](https://img.shields.io/npm/v/maid-irc.svg?style=flat-square)](https://www.npmjs.org/package/maid-irc) [![Dependency Status](https://img.shields.io/gemnasium/Phalanxia/Maid-IRC.svg?style=flat-square)](https://gemnasium.com/Phalanxia/Maid-IRC) [![Downloads](https://img.shields.io/npm/dm/maid-irc.svg?style=flat-square)](https://www.npmjs.org/package/maid-irc) [![Pateon](https://img.shields.io/badge/Patreon-%E2%99%A1-ff69b4.svg?style=flat-square)](https://www.patreon.com/Phalanxia)

A modern web IRC client. Built on [Node](https://nodejs.org).

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "maid-irc",
"version": "0.1.3",
"version": "0.1.4",
"description": "A modern web IRC client. Built on Node.",
"author": "Madison Tries <[email protected]> (https://github.com/Phalanxia)",
"homepage": "http://madi.moe/Maid-IRC/",
Expand Down
71 changes: 35 additions & 36 deletions public/js/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@
const select = document.querySelector.bind(document);
const selectAll = selection => Array.prototype.slice.call(document.querySelectorAll(selection));

window.onbeforeunload = function() {
if (client.status.connection) {
return 'You have attempted to leave this page. Doing so will disconnect you from IRC.';
}
};

var client = {
settings: {
awayMessage: 'Away',
Expand Down Expand Up @@ -39,17 +33,15 @@ var client = {
// Modules
const updateInterface = new UpdateInterface();
const outgoingMessages = new OutgoingMessages(socket, updateInterface);
const incomingMessages = new IncomingMessages(socket, updateInterface);
const incomingMessages = new IncomingMessages(updateInterface);
const connectToNetwork = new ConnectToNetwork(socket, updateInterface);

connectToNetwork.setup(connectInfo);

// Respond to pings
socket.on('ping', (data) => {
socket.emit('pong', {beat: 1});
});

// Lets handle all the socket.io stuff here for now. :3
socket.on('connect', () => {
client.status.connection = true;
console.log('Connected to server back end');
Expand All @@ -61,25 +53,20 @@ var client = {
console.warn('Connection lost');
});

// IRC
// Handle recieved IRC messages
socket.on('raw', (data) => {
let connectionId = data[0];
let message = data[1];

// Handle different command types differently (normal, reply, error)
if (message.commandType === 'normal') {
incomingMessages.normal(connectionId, message);
} else if (message.commandType === 'reply') {
incomingMessages.reply(connectionId, message);
} else if (message.commandType === 'error') {
incomingMessages.error(connectionId, message);
const connectionId = data[0];
const message = data[1];

if (message.commandType === 'normal' || message.commandType === 'reply' || message.commandType === 'error') {
incomingMessages.handler(connectionId, message);
} else {
console.warn('Error: Unknown command type ' + '"' + message.commandType + '"');
console.warn('Error: Unknown command type "' + message.commandType + '"');
}
});

function enterMessage() {
var input = select('#channel-console footer input');
const input = select('#channel-console footer input');
outgoingMessages.send(input.value);
input.value = '';
}
Expand All @@ -96,6 +83,12 @@ var client = {
}
};

window.onbeforeunload = function() {
if (client.status.connection) {
return 'You have attempted to leave this page. Doing so will disconnect you from IRC.';
}
};

// Handle connection information
select('#submit').onclick = function(event) {
event.preventDefault();
Expand All @@ -106,12 +99,12 @@ select('#submit').onclick = function(event) {
selectAll('#connect input').forEach(obj => {
connectInfo[obj.name] = obj.value;

// If the input is no longer invalid remove the invalid class.
// If the input is no longer invalid remove the invalid class
if (obj.classList.contains && obj.validity.valid) {
obj.classList.remove('invalid');
}

// If the input is invalid add the invalid class to the input.
// If the input is invalid add the invalid class to the input
if (!obj.validity.valid) {
obj.classList.add('invalid');
invalid = true;
Expand All @@ -135,6 +128,19 @@ select('#submit').onclick = function(event) {
}
};

// Stop form redirect on submit
select('#submit').submit = function(event) {
event.preventDefault();
return false;
}

function hideModals() {
select('#pageCover').classList.remove('displayed');
selectAll('.modal').forEach(obj => {
obj.classList.remove('displayed');
});
}

select('#pageCover').onclick = function() {
hideModals();
};
Expand All @@ -145,27 +151,20 @@ selectAll('.modal header button').forEach(obj => {
};
});

function hideModals() {
select('#pageCover').classList.remove('displayed');
selectAll('.modal').forEach(obj => {
obj.classList.remove('displayed');
});
}

// Show settings modal.
// Show settings modal
select('#network-panel header button.fa-cog').onclick = function() {
select('#pageCover').classList.add('displayed');
select('#settings').classList.add('displayed');
};

// Show connect modal.
// Show connect modal
select('#network-panel header button.fa-sign-in').onclick = function() {
select('#pageCover').classList.add('displayed');
select('#connect').classList.add('displayed');
};

// Settings
var settingsItems = select('#settings nav > ul').getElementsByTagName('li');
const settingsItems = select('#settings nav > ul').getElementsByTagName('li');
for (let i = 0; i < settingsItems.length; i++) {
settingsItems[i].i = i;
settingsItems[i].onclick = function() {
Expand All @@ -175,13 +174,13 @@ for (let i = 0; i < settingsItems.length; i++) {
obj.classList.remove('focused');
});

select('#settings nav > ul li:nth-of-type(' + (theNumber + 1) + ')').classList.add('focused');
select(`#settings nav > ul li:nth-of-type(${theNumber + 1})`).classList.add('focused');

selectAll('#settings .page').forEach(obj => {
obj.style.display = 'none';
});

selectAll('#settings .page:nth-of-type(' + (theNumber + 1) + ')')[0].style.display = 'block';
selectAll(`#settings .page:nth-of-type(${theNumber + 1})`)[0].style.display = 'block';
};
}

Expand Down
Loading

0 comments on commit 6b3acf1

Please sign in to comment.