spee.ch/public/assets/js/memeFodder-publish.js

65 lines
2.7 KiB
JavaScript
Raw Normal View History

2017-06-20 22:07:49 +02:00
// define variables
var socket = io();
var uploader = new SocketIOFileUpload(socket);
var stagedFiles = null;
2017-06-21 01:36:19 +02:00
var license = 'Creative Commons';
var nsfw = false;
2017-06-23 19:47:01 +02:00
var nameInput = document.getElementById("publish-name");
2017-06-21 18:14:53 +02:00
2017-06-20 22:07:49 +02:00
/* socketio-file-upload listeners */
uploader.addEventListener('start', function(event){
2017-06-23 19:47:01 +02:00
event.file.meta.name = nameInput.value;
2017-06-20 22:07:49 +02:00
event.file.meta.license = license;
event.file.meta.nsfw = nsfw;
event.file.meta.type = stagedFiles[0].type;
// re-set the html in the publish area
document.getElementById('publish-active-area').innerHTML = '<div id="publish-status"></div><div id="progress-bar"></div>';
// start a progress animation
createProgressBar(document.getElementById('progress-bar'), 12);
2017-06-30 07:26:29 +02:00
// google analytics
ga('send', {
hitType: 'event',
eventCategory: 'publish',
eventAction: nameInput.value
});
2017-06-20 22:07:49 +02:00
});
uploader.addEventListener('progress', function(event){
var percent = event.bytesLoaded / event.file.size * 100;
updatePublishStatus('File is ' + percent.toFixed(2) + '% loaded to the server');
});
/* socket.io message listeners */
socket.on('publish-status', function(msg){
updatePublishStatus(msg);
});
socket.on('publish-failure', function(msg){
2017-06-21 18:14:53 +02:00
document.getElementById('publish-active-area').innerHTML = '<p>' + JSON.stringify(msg) + '</p><p> --(✖╭╮✖)→ </p><strong>For help, post the above error text in the #speech channel on the <a href="https://lbry.slack.com/" target="_blank">LBRY slack</a></strong>';
2017-06-20 22:07:49 +02:00
});
socket.on('publish-complete', function(msg){
2017-06-21 18:14:53 +02:00
var publishResults;
2017-06-22 04:10:39 +02:00
var directUrl = '/' + msg.name + '/' + msg.result.claim_id;
2017-06-21 18:14:53 +02:00
// build new publish area
2017-06-22 22:25:18 +02:00
publishResults = '<p>Your publish is complete! View it here:</p>';
publishResults += '<p><a target="_blank" href="' + directUrl + '">spee.ch' + directUrl + '</a></p>';
publishResults += '<p><button class="copy-button">Copy to clipboard</button></p>';
2017-06-22 04:45:56 +02:00
publishResults += '<p><a target="_blank" href="https://explorer.lbry.io/#!/transaction/' + msg.result.txid + '">View the transaction details</a></p>';
2017-06-22 22:25:18 +02:00
publishResults += '<a href="/meme-fodder/play"><button>Reload</button></a></p>';
2017-06-21 18:14:53 +02:00
// update publish area
document.getElementById('publish-active-area').innerHTML = publishResults;
2017-06-22 22:25:18 +02:00
// update the link holder
2017-06-23 07:19:04 +02:00
document.getElementById('direct-link-holder').innerText = 'https://spee.ch' + directUrl;
2017-06-22 22:25:18 +02:00
// enable copy-to-clipboard
var copyBtn = document.querySelector('.copy-button');
copyBtn.addEventListener('click', function(event) {
// select the text
var text = document.getElementById('direct-link-holder');
text.select();
try {
var successful = document.execCommand('copy');
var msg = successful ? 'successful' : 'unsuccessful';
} catch (err) {
alert('Oops, unable to copy');
}
});
2017-06-20 22:07:49 +02:00
});