[ create a new paste ] login | about

Link: http://codepad.org/pGTddaiw    [ raw code | fork ]

Plain Text, pasted on Mar 11:
jQuery(function($){ 

  var myUploader = new plupload.Uploader({
    browse_button: 'browse_file', // id of the browser button
    multipart: true,              // <- this is important because you want
                                  //    to pass other data as well
    url: ajax_object.ajaxurl 
  });

  myUploader.init();

  myUploader.bind('FilesAdded', function(up, files){
    $('#browse_file').text('Selected: ' + files[0].name); 
    // do a console.log(files) to see what file was selected...
  });

  // before upload starts, get the value of the other fields
  // and send them with the file
  myUploader.bind('BeforeUpload', function(up) {
    myUploader.settings.multipart_params = {
      action: 'action_upload_pattern',

            sender_name: $('div#uploadPatternForm').find('input#senderName').attr('value'),
            sender_email: $('div#uploadPatternForm').find('input#senderEmail').attr('value'),
            sender_website: $('div#uploadPatternForm').find('input#senderWebsite').attr('value'),
            sender_country: $('div#uploadPatternForm').find('input#senderCountry').attr('value'),
            pattern_name: $('div#uploadPatternForm').find('input#patternName').attr('value'),
            pattern_image: $('div#uploadPatternForm').find('input#patternImage').attr('value'),
            pattern_desc: $('div#uploadPatternForm').find('#patternDesc').attr('value'),
            pattern_terms_personal: $('div#uploadPatternForm').find('#personalProjects').attr('value'),
            pattern_terms_commercial: $('div#uploadPatternForm').find('#commercialProjects').attr('value'),
            pattern_terms_templates: $('div#uploadPatternForm').find('#templatesYouSell').attr('value')
    };
  });

  // equivalent of the your "success" callback
  myUploader.bind('FileUploaded', function(up, file, ret){   

      var $response=$(ret.response);
            var postid      = $response.filter('#postid').html();
            var success     = $response.filter('#success').html();
            var error       = $response.filter('#error').html();


            if(success) {
                // APPEND NRE ITEMS AND FADE IN SLOW    
                $('input#returnedId').val(postid);

                // APPEND NRE ITEMS AND FADE IN SLOW                
                setTimeout(function(){
                    $('div#pu_message').fadeOut('fast');
                    $('div#pu_message').empty();
                    $('div#pu_message').append(success);                    
                    $('div#pu_message').fadeIn('slow');
                }, 500);
            }





  });

  // trigger submission when this button is clicked
  $('#submitPattern').on('click', function(e) {
    myUploader.start();
    e.preventDefault();      
  });

});


Create a new paste based on this one


Comments: