Added upload Image/Video/File

This commit is contained in:
Piyush Mishra 2018-03-05 19:46:38 +05:30
parent 2fc431a692
commit 5088627dbb
6 changed files with 103 additions and 7 deletions

View File

@ -58,13 +58,13 @@ window.setInterval(function() {
function join(channel) { function join(channel) {
if (document.domain == 'uchats.herokuapp.com') { //if (document.domain == 'uchats.herokuapp.com') {
ws = new WebSocket('wss://uchats.herokuapp.com/uchatsserver') ws = new WebSocket('wss://uchats.herokuapp.com/uchatsserver')
} /*}
else { else {
// for local installs // for local installs
ws = new WebSocket('ws://' + location.hostname+":"+location.port + '/uchatsserver') ws = new WebSocket('ws://' + location.hostname+":"+location.port + '/uchatsserver')
} }*/
var wasConnected = false var wasConnected = false
@ -191,7 +191,7 @@ function pushMessage(args) {
var textEl = document.createElement('pre') var textEl = document.createElement('pre')
textEl.classList.add('text') textEl.classList.add('text')
textEl.textContent = args.text || '' textEl.innerHTML = args.text || ''
textEl.innerHTML = textEl.innerHTML.replace(/(\?|https?:\/\/)\S+?(?=[,.!?:)]?\s|$)/g, parseLinks) textEl.innerHTML = textEl.innerHTML.replace(/(\?|https?:\/\/)\S+?(?=[,.!?:)]?\s|$)/g, parseLinks)
if ($('#parse-latex').checked) { if ($('#parse-latex').checked) {
@ -221,7 +221,6 @@ function pushMessage(args) {
updateTitle() updateTitle()
} }
function insertAtCursor(text) { function insertAtCursor(text) {
var input = $('#chatinput') var input = $('#chatinput')
var start = input.selectionStart || 0 var start = input.selectionStart || 0
@ -297,6 +296,56 @@ $('#footer').onclick = function() {
$('#chatinput').focus() $('#chatinput').focus()
} }
$('#uploadimage').onchange = function() {
file = this.files[0];
reader = new FileReader();
reader.addEventListener("load", function () {
args = {};
args.cmd = "chat";
args.text = '<img src="'+reader.result+'">';
send(args);
}, false);
if (file) {
reader.readAsDataURL(file);
}
}
$('#uploadvideo').onchange = function() {
file = this.files[0];
reader = new FileReader();
reader.addEventListener("load", function () {
args = {};
args.cmd = "chat";
args.text = '<video width="320" height="240" controls>'+
'<source src="'+reader.result+'">'+
'</video>';
send(args);
}, false);
if (file) {
reader.readAsDataURL(file);
}
}
$('#uploadfile').onchange = function() {
file = this.files[0];
reader = new FileReader();
reader.addEventListener("load", function () {
args = {};
args.cmd = "chat";
args.text = '<a target="_blank" href="'+reader.result+'">File: '+file.name+'</a>';
send(args);
}, false);
if (file) {
reader.readAsDataURL(file);
}
}
$('#chatinput').onkeydown = function(e) { $('#chatinput').onkeydown = function(e) {
if (e.keyCode == 13 /* ENTER */ && !e.shiftKey) { if (e.keyCode == 13 /* ENTER */ && !e.shiftKey) {
e.preventDefault() e.preventDefault()

BIN
web/images/file.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 299 B

BIN
web/images/image.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 411 B

BIN
web/images/video.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 297 B

View File

@ -15,6 +15,9 @@
</article> </article>
<footer id="footer"> <footer id="footer">
<div class="container"> <div class="container">
<span class="select-wrapper" style="background-image: url(images/image.png);"><input class="fotterbutton" type="file" id="uploadimage" value="Upload Image" accept="image/*"></span>
<span class="select-wrapper" style="background-image: url(images/video.png);"><input class="fotterbutton" type="file" id="uploadvideo" value="Upload Video" accept="video/*"></span>
<span class="select-wrapper" style="background-image: url(images/file.png);"><input class="fotterbutton" type="file" id="uploadfile" value="Upload File"></span>
<form id="chatform" class="messages"><textarea id="chatinput" type="text" autocomplete="off" autofocus></textarea></form> <form id="chatform" class="messages"><textarea id="chatinput" type="text" autocomplete="off" autofocus></textarea></form>
</div> </div>
</footer> </footer>

View File

@ -3,19 +3,23 @@ body {
margin: 0; margin: 0;
overflow-y: scroll; overflow-y: scroll;
} }
body, body,
input, input,
textarea { textarea {
font-family: 'DejaVu Sans Mono', monospace; font-family: 'DejaVu Sans Mono', monospace;
font-size: 12px; font-size: 12px;
} }
input[type="checkbox"] { input[type="checkbox"] {
margin: 0; margin: 0;
margin-right: 1em; margin-right: 1em;
} }
label { label {
vertical-align: 3px; vertical-align: 3px;
} }
input, input,
textarea { textarea {
background: none; background: none;
@ -23,11 +27,13 @@ textarea {
outline: none; outline: none;
resize: none; resize: none;
} }
h4 { h4 {
font-size: 12px; font-size: 12px;
margin: 1em 0; margin: 1em 0;
font-weight: bold; font-weight: bold;
} }
pre { pre {
tab-size: 2; tab-size: 2;
white-space: pre-wrap; white-space: pre-wrap;
@ -35,37 +41,48 @@ pre {
tab-size: 4; tab-size: 4;
-moz-tab-size: 4; -moz-tab-size: 4;
} }
a { a {
color: inherit; color: inherit;
text-decoration: none; text-decoration: none;
cursor: pointer; cursor: pointer;
} }
a:hover { a:hover {
text-decoration: underline; text-decoration: underline;
} }
ul { ul {
padding-left: 0; padding-left: 0;
} }
ul li { ul li {
list-style: inside; list-style: inside;
} }
.hidden { .hidden {
display: none; display: none;
} }
.container { .container {
max-width: 600px; max-width: 600px;
margin: 0 auto; margin: 0 auto;
} }
.messages { .messages {
border-left: 1px solid; border-left: 1px solid;
} }
#messages { #messages {
padding-top: 2em; padding-top: 2em;
} }
.message { .message {
padding-bottom: 1em; padding-bottom: 1em;
} }
.nick { .nick {
float: left; float: left;
width: 16em; width: 16em;
margin-left: -17em; margin-left: -17em;
@ -74,29 +91,54 @@ ul li {
white-space: nowrap; white-space: nowrap;
overflow: hidden; overflow: hidden;
} }
.trip { .trip {
font-size: 10px; font-size: 10px;
} }
.text { .text {
margin: 0; margin: 0;
margin-left: 1em; margin-left: 1em;
} }
.text p { .text p {
margin: 0; margin: 0;
} }
.select-wrapper {
background-repeat: no-repeat;
background-size: cover;
float:left;
display: block;
position: relative;
width: 20px;
height: 20px;
margin: 5px;
}
.fotterbutton {
width: 20px;
height: 20px;
margin-right: 100px;
opacity: 0;
filter: alpha(opacity=0); /* IE 5-7 */
}
#footer { #footer {
position: fixed; position: fixed;
bottom: 0; bottom: 0;
width: 100%; width: 100%;
} }
#chatform { #chatform {
border-top: 1px solid; border-top: 1px solid;
} }
#chatinput { #chatinput {
width: 100%; width: 100%;
padding: 1em; padding: 1em;
box-sizing: border-box; box-sizing: border-box;
} }
#sidebar { #sidebar {
position: fixed; position: fixed;
top: 0; top: 0;
@ -106,9 +148,11 @@ ul li {
border-left: solid 1px; border-left: solid 1px;
overflow-y: auto; overflow-y: auto;
} }
#sidebar-content { #sidebar-content {
width: 180px; width: 180px;
} }
@media only screen and (max-width: 600px) { @media only screen and (max-width: 600px) {
.messages { .messages {
border: none; border: none;