File: chat-websocket/node_modules/socket.io/node_modules/socket.io-client/node_modules/ws/examples/fileapi/public/app.js

Recommend this page to a friend!
  Classes of Igor Escobar   Terminal Crossword   chat-websocket/node_modules/socket.io/node_modules/socket.io-client/node_modules/ws/examples/fileapi/public/app.js   Download  
File: chat-websocket/node_modules/socket.io/node_modules/socket.io-client/node_modules/ws/examples/fileapi/public/app.js
Role: Example script
Content type: text/plain
Description: Example script
Class: Terminal Crossword
Generate a crosswords board on a text console
Author: By
Last change:
Date: 2 years ago
Size: 1,190 bytes
 

Contents

Class file image Download
function onFilesSelected(e) { var button = e.srcElement; button.disabled = true; var progress = document.querySelector('div#progress'); progress.innerHTML = '0%'; var files = e.target.files; var totalFiles = files.length; var filesSent = 0; if (totalFiles) { var uploader = new Uploader('ws://localhost:8080', function () { Array.prototype.slice.call(files, 0).forEach(function(file) { if (file.name == '.') { --totalFiles; return; } uploader.sendFile(file, function(error) { if (error) { console.log(error); return; } ++filesSent; progress.innerHTML = ~~(filesSent / totalFiles * 100) + '%'; console.log('Sent: ' + file.name); }); }); }); } uploader.ondone = function() { uploader.close(); progress.innerHTML = '100% done, ' + totalFiles + ' files sent.'; } } window.onload = function() { var importButtons = document.querySelectorAll('[type="file"]'); Array.prototype.slice.call(importButtons, 0).forEach(function(importButton) { importButton.addEventListener('change', onFilesSelected, false); }); }