diff options
-rw-r--r-- | index.html | 28 | ||||
-rw-r--r-- | index.js | 75 | ||||
-rw-r--r-- | package.json | 11 |
3 files changed, 88 insertions, 26 deletions
@@ -1,17 +1,25 @@ -<html> +<html class="page"> <head> </head> - <body> - <div id="chat" height="90%"> - Hello world<br> + <body class="container"> + <div id="chan-container"> + <div class="ui pointing secondary menu"> + </div> + </div> - <input id="send-message" type="text"> - <input id="submitb" type="submit" text="send"> - <script> - window.$ = window.jQuery = require('./jquery-2.2.2.js'); - var blachat = require("./lib/index.js"); - </script> + <div id="message"> + <div class="ui input" id="message-container"> + <input placeholder="Message" id="send-message" type="text"> + </div> + </div> + <script> + window.$ = window.jQuery = require('./lib/jquery-2.2.2.js'); + var blachat = require("./index.js"); + </script> + <link rel="stylesheet" type="text/css" href="lib/semantic/dist/semantic.min.css"> + <link rel="stylesheet" type="text/css" href="style.css"> + <script src="lib/semantic/dist/semantic.min.js"></script> </body> </html> @@ -1,22 +1,75 @@ +$(document).ready(function(){ +}); -$("#submitb").click(function() { - sendMsg(); +$("#send-message").keypress(function(e) { + if(e.which == 13) { + var channel = $(".tab.chat.active").attr("data-tab").replace("chan-", "#") + sendMsg($("#send-message").val(), channel) + $("#send-message").val(''); + } }); +function sendMsg(message, channel) { + console.log(channel + ': ' + message); + client.say(channel, message); + var chanTab = $("[data-tab=chan-"+ channel.replace("#","") +"].chat"); + chanTab.append("<p class='chat-line'><" + "wclient" + "> " + message +"</p>"); + chanTab.scrollTop(chanTab.prop("scrollHeight")); +} + +function joinChannel(channel) { + client.join(channel); + channel = channel.replace("#",""); + + $(".active").removeClass("active"); + $(".ui.menu").append("<a class='active item' data-tab='chan-"+channel+"'>#"+channel+"</a>"); + + + $("#chan-container").append("<div class='ui active tab segment chat active' id='chan-"+channel+"' data-tab='chan-"+channel+"'></div>") + $('.menu .item').tab({history:false}); + var chanTab = $("[data-tab=chan-"+ channel +"].chat"); + client.addListener('message#'+channel, function (from, message) { + console.log(from + ' => #'+ channel +': ' + message); + console.log(chanTab); + chanTab.append("<p class='chat-line'><" + from + "> " + message +"</p>"); + chanTab.scrollTop(chanTab.prop("scrollHeight")); + }); +} + + const irc = require('irc'); +var channels = ["#wtest", "#wtest2"] const client = new irc.Client('irc.blatech.net', 'wclient', { - channels: ['#wtest'], + channels: channels, userName: ['wclient'] }); -function sendMsg() { - console.log('#wtest: ' + $("#send-message").val()); - client.say("#wtest", $("#send-message").val()); -} - +client.addListener('error', function(message) { + console.log('error: ', message); +}); -client.addListener('message#wtest', function (from, message) { - console.log(from + ' => #wtest: ' + message); - $("#chat").append(from + ' : ' + message + "<br>"); +client.addListener('registered', function() { + channels.forEach(function(channel) { + joinChannel(channel); + }); }); + + + +// client.addListener('message#wtest', function (from, message) { +// console.log(from + ' => #wtest: ' + message); +// var chanTab = $("[data-tab=chan-wtest].chat"); +// chanTab.append("<p class='chat-line'><" + from + "> " + message +"</p>"); +// chanTab.scrollTop(chanTab.prop("scrollHeight")); +// }); +// +// client.addListener('message#jerseyesports', function (from, message) { +// console.log(from + ' => #jerseyesports: ' + message); +// $("[data-tab=chan-jerseyesports].chat").append("<p class='chat-line'><" + from + "> " + message +"</p>"); +// }); + +// client.addListener('message#theblueroom', function (from, message) { +// console.log(from + ' => #jerseyesports: ' + message); +// $("[data-tab=chan-theblueroom].chat").append("<p class='chat-line'><" + from + "> " + message +"</p>"); +// }); diff --git a/package.json b/package.json index 0ae8985..d3b46e5 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,8 @@ { - "name" : "blachat", - "version" : "0.1.0", - "main" : "main.js" + "name": "blachat", + "version": "0.1.0", + "main": "main.js", + "dependencies": { + "semantic-ui": "^2.1.8" + } } - - |