//= require moxie //= require plupload.dev // optional, but recommended. it sets generic settings like flash url, etc. //= require plupload.settings // optional, only if you want to use the jquery integration //= require jquery.plupload.queue (function($) { $.fn.pluploadIt = function (options) { var settings = $.extend({ browse_button: 'pickAttachments', // triggers modal to select files container: 'attachmentUploader', drop_element: 'dropAttachments', flash_swf_url: '/assets/plupload.flash.swf', max_file_size: '10mb', queue_element: 'attachmentQueue', resize: false, runtimes: 'gears,html5,flash,browserplus,html4', silverlight_xap_url: '/assets/plupload.silverlight.xap', target_list: 'loadedAttachments', unique_names: false, upload_button: 'uploadAttachments', url: '/upload' }, options); return this.each(function() { var $container = $(this); settings.container = $container.attr('id'); var modelAndRelation = $container.data('model').replace(/::/g,'-') + "-" + $container.data('relation'); // setup unique ids from classes $container.find('.' + settings.browse_button).attr('id', settings.container + '-' + settings.browse_button); $container.find('.' + settings.drop_element).attr('id', settings.container + '-' + settings.drop_element); $container.find('.' + settings.queue_element).attr('id', settings.container + '-' + settings.queue_element); $container.find('.' + settings.target_list).attr('id', settings.container + '-' + settings.target_list); $container.find('.' + settings.upload_button).attr('id', settings.container + '-' + settings.upload_button); var uploader = new plupload.Uploader({ browse_button: settings.container + '-' + settings.browse_button, container: settings.container, drop_element: settings.container + '-' + settings.drop_element, flash_swf_url: settings.flash_swf_url, max_file_size: settings.max_file_size, multipart_params: { id: $container.data('id'), relation: $container.data('relation'), model: $container.data('model'), partial: $container.data('partial') === undefined ? '' : $container.data('partial'), loader_partial: $container.data('loader-partial') === undefined ? '' : $container.data('loader-partial'), embedded_in_model: $container.data('embedded-in-model') === undefined ? '' : $container.data('embedded-in-model'), embedded_in_id: $container.data('embedded-in-id') === undefined ? '' : $container.data('embedded-in-id') }, resize: settings.resize, runtimes: settings.runtimes, silverlight_xap_url: settings.silverlight_xap_url, unique_names: settings.unique_names, url: settings.url }); uploader.bind('Init', function(up, params) { if ($('#' + settings.container + '-runtimeInfo').length > 0) $('#' + settings.container + '-runtimeInfo').text("Current runtime: " + params.runtime); }); $('#' + settings.container + '-' + settings.upload_button).click(function(e) { uploader.start(); e.preventDefault(); }); uploader.init(); (function (container, queue_element, target_list) { uploader.bind('FilesAdded', function(up, files) { $.each(files, function(i, file) { $('#' + container + '-' + queue_element).append( '