Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- index.html
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8" />
- <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Vert.X</title>
- <link rel="stylesheet" type="text/css" href="css/bootstrap.css" />
- <link rel="stylesheet" type="text/css" href="css/style.css" />
- <link rel="stylesheet" type="text/css" href="css/component.css" />
- <script src="http://cdn.sockjs.org/sockjs-0.3.4.min.js"></script>
- <script src="vertxbus.min.js"></script>
- <script src="vertxhandler.js"></script>
- <!--[if IE]>
- <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
- <![endif]-->
- </head>
- <body>
- <div class="container">
- <header class="clearfix">
- <a href="" class="navbar-brand"><img alt="Brand" width="162" src="img/logo-sm.png"></a>
- </header>
- <div id="tabs" class="tabs">
- <nav>
- <ul>
- <li><a href="#section-1" class="login"><span>Login</span></a></li>
- <li id="register-btn"><a href="#section-2" class="Register"><span>Register</span></a></li>
- <li><a href="#section-3" class="Chat"><span>Chat</span></a></li>
- </ul>
- </nav>
- <div class="content">
- <section id="section-1">
- <div id="signInContainer" class="mediabox">
- <h4>Login</h4>
- <input name="userName" class="form-control" type="text" placeholder="User Name">
- <input name="password" class="form-control" type="password" placeholder="Password">
- <input id="signIn" class="btn" type="button" value="Submit" data-target="#section-3">
- <p><a href="#section-2" role="tab" data-toggle="tab" id="register-link" style=" color: #782b90;"> click here to register</a></p>
- <div class="power">
- <span>Powered by Vert.x</span><img width="162" src="img/logo-sm.png ">
- </div>
- </div>
- </section>
- <section id="section-2">
- <div class="mediabox">
- <h4>Register</h4>
- <form class="form">
- <input class="form-control" type="text" placeholder="User Name">
- <input class="form-control" type="text" placeholder="Email">
- <input class="form-control" type="password" placeholder="Password">
- <input class="form-control" type="password" placeholder="Confirm Password">
- <input class="btn" type="button" value="Submit">
- </form>
- <div class="power">
- <span>Powered by Vert.x</span><img width="162" src="img/logo-sm.png ">
- </div>
- </div>
- </section>
- <section id="section-3" style="padding-left:0em;">
- <div class="chatbox" style=" ">
- <div class="container-fluid">
- <div class="row">
- <div id="userListContainer" class="col-md-2 col-xs-4 col-sm-2" style="border-right:1px solid #782b90; height:550px; padding-left:0px; padding-right:0px;">
- Online users
- </div>
- <div class="col-md-10 col-xs-8 col-sm-10" style="padding-left:0em;">
- <div class="container-fluid">
- <div class="row">
- <div class="col-md-12 col-sm-12 col-xs-12" style="margin-left:8px; margin-top:10px; padding-left:0px; padding-right:0px; ">
- <table id="chatHistory" class="table table-bordered">
- </table>
- </div>
- </div>
- </div>
- <div class="container-fluid">
- <div class="row">
- <div class="col-md-12">
- <form class="form" style="margin-bottom:20px;">
- <div class="input-group">
- <input id="newChat" type="text" class="form-control input-lg" aria-describedby="send-addon" required autofocus>
- <span style="color:#fff;background-color: #782b90; border-color: #782b90;" class="btn input-group-addon input-lg" id="sendChat">Send</span>
- </div>
- </form>
- </div>
- </div>
- </div>
- </div>
- <div class="chatpower">
- <span>Powered by Vert.x</span><img width="162" src="img/logo-sm.png ">
- </div>
- </div>
- </div>
- </div>
- </section>
- </div><!-- /content -->
- </div><!-- /tabs -->
- </div>
- <script src="js/vertx.js"></script>
- <script>
- new CBPFWTabs(document.getElementById('tabs'));
- </script>
- <script src="js/jquery-1.10.2.js"></script>
- <script src="js/bootstrap.min.js"></script>
- <script>
- $('#register-link').click(function () {
- $('#register-btn').trigger('click');
- });
- </script>
- </body>
- </html>
- ____________________________________________________________________________________________
- vertxhandler.js
- window.onload = function () {
- var eventBus = new vertx.EventBus("http://localhost:8080/chat");
- var userName = document.querySelector("input[name=userName]");
- var password = document.querySelector("input[name=password]");
- var email = document.querySelector("input[name=email]");
- var userListContainer = document.getElementById("userListContainer");
- var chatContainer = document.getElementById("chatContainer");
- var chatHistory = document.getElementById("chatHistory");
- var newChat = document.getElementById("newChat");
- var signInContainer = document.getElementById("signInContainer");
- eventBus.onopen = function () {
- eventBus.registerHandler("users/signedIn", function (message) {
- userListContainer.innerHTML += "<div>" + message.userName + "</div>";
- });
- document.getElementById("register").addEventListener("click", function (event) {
- eventBus.send("users/register"), {
- userName: userName.value,
- email: email.value,
- password: password.value
- }, function (reply) {
- if (reply.status === 200) {
- } else if (reply.status === 120) {
- }
- }
- }, false);
- document.getElementById("signIn").addEventListener("click", function (event) {
- eventBus.send("users/signIn", {
- userName: userName.value, password: password.value
- }, function (reply) {
- if (reply.status === 200) {
- document.getElementById("sendChat").addEventListener("click", function () {
- var text = newChat.value;
- if (text.substring(0, 1) === ".") {
- var args = text.split(' ');
- eventBus.send("commands/perform", {
- userName: userName.value,
- command: args[0],
- arg1: args[1]
- });
- }
- eventBus.send("messages/post", {
- userName: userName.value,
- text: text
- });
- newChat.value = "";
- }, false);
- eventBus.registerHandler("messages/posted", function (message) {
- //chatHistory.innerHTML += addToTable(message.userName, message.text);
- //var table = document.getElementById("elementID");
- //Callum method
- var row = chatHistory.insertRow(0);
- var cell1 = row.insertCell(0);
- cell1.innerHTML = "put in timestamp here";
- });
- }
- });
- }, false);
- };
- };
- function addToTable(username, message) {
- //Jon method
- return "<tr><td class=\"col-md-3 col-sm-3 col-xs-4\">" + username + "</td><td class=\"col-md-9 col-sm-9 col-xs-8\">" + message + "</td></tr>";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement