function bytesToSize(bytes) { var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB']; if (bytes == 0) return 'n/a'; var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024))); return Math.round(bytes / Math.pow(1024, i), 2) + ' ' + sizes[[i]]; }; var FileZipView = Backbone.View.extend({ initialize: function() { this.model.on('change', this.render, this); this.model.on('uploadCompleted', this.removeProgressBar); this.model.on('uploadCompleted', this.activeButtons); this.model.on('uploadCompleted', updateFileList); }, activeButtons: function(){ jQuery('#upload-buttons').fadeIn(); }, removeProgressBar: function(){ with({model: this.model}){ if(this.$el != undefined) { this.$el.find('.progress').fadeOut(); this.$el.find('.progress').fadeOut(500, function(){ model.set({fadeOutProgress: true}); }); } } }, render : function(){ var html; html = '
'+ this.model.get('loadingMessage') +'
'; html += '' + bytesToSize(this.model.get('loadedBytes'), 3)+ ' / ' + bytesToSize(this.model.get('totalBytes'), 3) + ''+'
'; html += '