gun/examples/basic/upload.html
2020-06-14 16:08:23 -07:00

66 lines
1.7 KiB
HTML

<!DOCTYPE html>
<<<<<<< HEAD
<video id="video" width="100%"></video>
<center>
<span id="up">Drag & Drop Video to Upload!</span>
<button id="play">Play</button>
=======
<div class="model" style="display: none;">
<video width="100%" controls autoplay></video>
<audio width="100%" controls autoplay></audio>
<img style="max-width: 100%;">
</div>
<center>
<p>Drag & drop videos, songs, or images! <input type="file" multiple></p>
>>>>>>> master
</center>
<script src="../jquery.js"></script>
<script src="../../../gun/gun.js"></script>
<script src="../../../gun/lib/upload.js"></script>
<script>
var gun = Gun(location.origin + '/gun');
<<<<<<< HEAD
var video = {data: null};
$('body').upload(function(e){
var b64 = (((e.event || e).target || e).result || e);
gun.get('test').get('screen').put(b64);
})
gun.get('test').get('screen').on((data)=>{
if(!data){ return }
$('#video').get(0).src = video.data = data;
})
$('#play').on('click', ()=>{
if(video.playing || !video.data){
$('#play').text("Play")
$('#video').get(0).pause();
video.playing = false;
return;
}
$('#play').text("Stop");
video.playing = true;
$('#video').get(0).play()
=======
$('html').upload(function resize(eve, up){
if(up){ return up.shrink(eve, resize, 1024) }
var b64 = (eve.base64 || ((eve.event || eve).target || eve).result || eve);
gun.get('test').get(eve.id).put(b64);
});
gun.get('test').map().on(function(data){
if(!data){ return }
var type = data.split(';')[0], ui;
if(type.indexOf('image') + 1){ ui = $("img").get(0) }
if(type.indexOf('video') + 1){ ui = $('video').get(0) }
if(type.indexOf('audio') + 1){ ui = $('audio').get(0) }
if(!ui){ return }
$(ui).clone().prependTo('center').get(0).src = data;
>>>>>>> master
})
</script>