sagive

plupload question

Apr 4th, 2013
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. jQuery(function($){
  2. //alert($.fn.jquery)
  3.  
  4. var siteurl = $('div#new_talk_container').find('input#siteurl').attr('value');
  5. var themeurl = $('div#new_talk_container').find('input#themeurl').attr('value');
  6.  
  7.  
  8. var myUploader = new plupload.Uploader({
  9. runtimes: 'html5,flash',
  10. browse_button: 'browse_file', // id of the browser button
  11. max_file_size: '5mb',
  12. unique_names: true,
  13. file_data_name: 'filedata',
  14. filters : [
  15. {
  16. title : "Allowed files",
  17. extensions : "jpg,gif,png"
  18. },
  19. ],
  20. multiple_queues: false,
  21. multipart: true, // <- this is important because you want
  22. multi_selection:true,
  23. // to pass other data as well
  24. url: ajax_object.ajaxurl,
  25. });
  26.  
  27. myUploader.init();
  28.  
  29. myUploader.bind('FilesAdded', function(up, files){
  30. $('#browse_file').text('Selected: ' + files[0].name);
  31. // alert(files[0].toSource());
  32. // do a console.log(files) to see what file was selected...
  33. });
  34.  
  35.  
  36. // before upload starts, get the value of the other fields
  37. // and send them with the file
  38. myUploader.bind('BeforeUpload', function(up) {
  39. myUploader.settings.multipart_params = {
  40. action: 'action_insert_newtalk',
  41. talk_text: $('div#new_talk_container').find('#newTalkTxt').attr('value'),
  42. talk_author_id: $('div#current_user_id').find('input#current_user_id').attr('value')
  43. };
  44. });
  45.  
  46.  
  47. // equivalent of the your "success" callback
  48. myUploader.bind('FileUploaded', function(up, file, ret){
  49.  
  50. var $response = $(ret.response);
  51. var brandNewTalk = $response.filter('#brandNewTalk').html();
  52.  
  53. if(brandNewTalk) {
  54. setTimeout(function(){
  55. $('div#newTalkAfter').append(brandNewTalk);
  56. $('div#newTalkAfter').fadeIn('slow');
  57. }, 500);
  58.  
  59. $('#newTalkTxt').val('');
  60. }
  61.  
  62. });
  63.  
  64.  
  65. // trigger submission when this button is clicked
  66. $('div#publish_new_talk').on('click', function(e) {
  67. myUploader.start();
  68. e.preventDefault();
  69. });
  70.  
  71. });
Advertisement
Add Comment
Please, Sign In to add comment