Last active
October 9, 2020 05:02
-
-
Save jalvarado-it/17bacd114ead9f97626b2c40265b1981 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="en"> | |
<head> | |
<title>Dojo Chat</title> | |
<!-- Required meta tags --> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | |
<!-- Bootstrap CSS --> | |
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"> | |
<script src="https://ajax.googleapis.com/ajax/libs/dojo/1.7.12/dojo/dojo.js"></script> | |
<script>typeof(dojo) === "undefined" && document.write(unescape('%3Cscriptsrc="js/libs/dojo/dojo.js"%3E%3C/script%3E'))</script> | |
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script> | |
</head> | |
<body> | |
<div id="status" class="container"></div> | |
<div class="container"> | |
<h3>Publish something</h3> | |
<form action=""> | |
<div class="form-group"> | |
<label for="">Message:</label> | |
<input type="text" name="" id="msg" class="form-control" placeholder="Mensaje" aria-describedby="helpId"> | |
<small id="helpId" class="text-muted"></small> | |
</div> | |
<button id="btnenviar" type="button" class="btn btn-primary">Send</button> | |
</form> | |
</div> | |
<div class="container"> | |
<h4>Received message</h4> | |
<div id="msglist" class="row"> | |
</div> | |
</div> | |
<script> | |
require(["dojo/ready", "dojo/dom", "dojo/dom-construct", "dojo/on", "dojo/topic"],function(ready,dom,construct,on,topic){ | |
var status = dom.byId("status"); | |
var enviar = dom.byId("btnenviar"); | |
var msg = dom.byId("msg"); | |
var msglist = dom.byId("msglist"); | |
ready(function(){ | |
status.innerHTML = "All is ready!"; | |
topic.subscribe("messages",function(data){ | |
var msgitem = construct.create("div", | |
{ | |
innerHTML: data, | |
class: "col-sm-12 border" | |
}, | |
msglist | |
); | |
}); | |
on(enviar,"click",function(){ | |
console.log("Sended mesage: " + msg.value); | |
topic.publish("messages",msg.value); | |
}); | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment