;(function($) { /** * Upload handler helper * * @param string {browse_button} browse_button ID of the pickfile * @param string {container} container ID of the wrapper * @param int {max} maximum number of file uplaods * @param string {type} */ window.WPUF_Uploader = function (browse_button, container, max, type, allowed_type, max_file_size) { this.removed_files = []; this.container = container; this.browse_button = browse_button; this.max = max || 1; this.count = $('#' + container).find('.wpuf-attachment-list > li').length; //count how many items are there this.perFileCount = 0; //file count on each upload this.UploadedFiles = 0; //file count on each upload //if no element found on the page, bail out if( !$('#'+browse_button).length ) { return; } // enable drag option for ordering $( "ul.wpuf-attachment-list" ).sortable({ placeholder: "highlight" }); $( "ul.wpuf-attachment-list" ).disableSelection(); //instantiate the uploader this.uploader = new plupload.Uploader({ runtimes: 'html5,html4', browse_button: browse_button, container: container, multipart: true, multipart_params: { action: 'wpuf_upload_file', form_id: $( '#' + browse_button ).data('form_id') }, max_file_count : 2, multiple_queues: false, multi_selection: ( ( browse_button == 'wpuf-avatar-pickfiles' || browse_button == 'wpuf-featured_image-pickfiles' ) ? false : true ), urlstream_upload: true, file_data_name: 'wpuf_file', max_file_size: max_file_size + 'kb', url: wpuf_frontend_upload.plupload.url + '&type=' + type, flash_swf_url: wpuf_frontend_upload.flash_swf_url, filters: [{ title: 'Allowed Files', extensions: allowed_type }] }); //attach event handlers this.uploader.bind('Init', $.proxy(this, 'init')); this.uploader.bind('FilesAdded', $.proxy(this, 'added')); this.uploader.bind('QueueChanged', $.proxy(this, 'upload')); this.uploader.bind('UploadProgress', $.proxy(this, 'progress')); this.uploader.bind('Error', $.proxy(this, 'error')); this.uploader.bind('FileUploaded', $.proxy(this, 'uploaded')); this.uploader.init(); $('#' + container).on('click', 'a.attachment-delete', $.proxy(this.removeAttachment, this)); return this.uploader; }; WPUF_Uploader.prototype = { init: function (up, params) { this.showHide(); $('#' + this.container).prepend('
'); }, showHide: function () { if ( this.count >= this.max) { if ( this.count > this.max ) { $('#' + this.container + ' .wpuf-file-warning').html( wpuf_frontend_upload.warning ); } else { $('#' + this.container + ' .wpuf-file-warning').html( wpuf_frontend_upload.warning ); } $('#' + this.container).find('.file-selector').hide(); return; }; $('#' + this.container + ' .wpuf-file-warning').html( '' ); $('#' + this.container).find('.file-selector').show(); }, added: function (up, files) { var $container = $('#' + this.container).find('.wpuf-attachment-upload-filelist'); this.showHide(); $.each(files, function(i, file) { $(".wpuf-submit-button").attr("disabled", "disabled"); $container.append( '