Created
January 6, 2012 16:34
-
-
Save moski/1571330 to your computer and use it in GitHub Desktop.
plupload + Coffeescript + Rails 3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| window.initUploader = () -> | |
| uploader = new plupload.Uploader({ | |
| runtimes : 'html5,flash,silverlight,', | |
| browse_button : 'drop_zone_home', | |
| drop_element : 'drop_zone_home', | |
| container : 'uploadContainer', | |
| max_file_size : '10mb', | |
| url : '/posts', | |
| flash_swf_url : '/swf/plupload.flash.swf', | |
| silverlight_xap_url : '/swf/plupload.silverlight.xap', | |
| filters : [ | |
| {title : "Image files", extensions : "jpg,gif,png"}], | |
| resize : {width : 320, height : 240, quality : 90}, | |
| multipart: true, | |
| urlstream_upload: true, | |
| multi_selection:false, | |
| multipart_params: { | |
| 'authenticity_token': $('meta[name="csrf-token"]').attr('content') | |
| }, | |
| }) | |
| uploader.bind('Init', (up, params) -> $('#filelist').html("")) | |
| $('#uploadfile').click((e) -> uploader.start(); e.preventDefault()); | |
| uploader.init(); | |
| uploader.bind('FilesAdded', (up, files) -> | |
| if (uploader.files.length == 2) | |
| f = uploader.files[0] | |
| uploader.removeFile(f) | |
| $("#" + f.id).remove() | |
| $.each(files, (i, file) -> $('#filelist').append('<div id="' + file.id + '">' + file.name + '</div>')) | |
| $('#uploadContainer').find('p').hide(); | |
| up.refresh(); # Reposition Flash/Silverlight | |
| ); | |
| uploader.bind('UploadProgress', (up, file) -> $('#' + file.id + " b").html(file.percent + "%")) | |
| uploader.bind('Error', (up, err) -> | |
| $('#filelist').append("<div>Error: " + err.code + | |
| ", Message: " + err.message + | |
| (if err.file then ", File: " + err.file.name else "") + | |
| "</div>" | |
| ) | |
| up.refresh(); #Reposition Flash/Silverlight | |
| ) | |
| uploader.bind('FileUploaded', (up, file) -> $('#' + file.id + " b").html("100%")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment