# Listens to fileuploads for content pictures. # Displays a progressbar when an image is uploaded, and a preview # thumbnail for the picture. jQuery -> $('#new_picture').fileupload dataType: "script" add: (e, data) -> types = /(\.|\/)(gif|jpe?g|png)$/i file = data.files[0] if types.test(file.type) || types.test(file.name) data.context = $(tmpl("template-upload", file)) $('#new_picture').append(data.context) data.submit() else alert("#{file.name} is not a gif, jpeg, or png image file") progress: (e, data) -> if data.context progress = parseInt(data.loaded / data.total * 100, 10) data.context.find('.bar').css('width', progress + '%') data.context.find('.percent').html(progress + '%') if progress >= 100 $('.upload').remove()