file upload preparations

php
Marc Wäckerlin 10 years ago
parent 0758a9d217
commit 2c2872a452
  1. 6
      html/chat.html
  2. 14
      html/safechat.js

@ -1,6 +1,12 @@
<form id="chat" autocomplete="off" onsubmit="sendmessage(this.elements['recv'].value, this.elements['msg'].value)"> <form id="chat" autocomplete="off" onsubmit="sendmessage(this.elements['recv'].value, this.elements['msg'].value)">
<input placeholder="receiver" autocomplete="off" type="text" id="recv" oninput="checkpartner(this.value)" /> <input placeholder="receiver" autocomplete="off" type="text" id="recv" oninput="checkpartner(this.value)" />
<input placeholder="message" autocomplete="off" type="text" id="msg"/> <input placeholder="message" autocomplete="off" type="text" id="msg"/>
<label class="icon" for="file" style="flex-grow: 0"><img style="width: 2em; height: 2em" src="attachment.svg"/></label>
<input class="icon" autocomplete="off" type="file" id="file" style="display:none"/>
<input type="submit" id="send" disabled/> <input type="submit" id="send" disabled/>
</form> </form>
<div id="msgs"></div> <div id="msgs"></div>
<script>
$("#file").change(function(evt){fileupload(evt)});
if (!window.FileReader) $("#file").hide(); // not supported by browser
</script>

@ -151,6 +151,20 @@ function userid() {
return publicKey().keys[0].getUserIds()[0]; return publicKey().keys[0].getUserIds()[0];
} }
function fileupload(evt) {
if (!window.FileReader)
return error("your browser dows not support file upload", true);
var reader = new FileReader();
reader.onload = function(evt) {
if (evt.target.readyState!=2)
return notice("ReadyState="+evt.target.readyState);
if (evt.target.error) return error("error reading file", true);
filecontent = evt.target.result;
success(filecontent);
}
reader.readAsText(evt.target.files[0]);
}
function setreceiver(name) { function setreceiver(name) {
$("#recv").val(name); $("#recv").val(name);
checkpartner(name); checkpartner(name);

Loading…
Cancel
Save