Advertisement
brasofilo

Upload button WP 3.5

Oct 23rd, 2013
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. jQuery(document).ready(function($)
  2. {
  3.     /**
  4.      * Versión 1
  5.      * De aqui conseguimos sacar el tamaño elejido
  6.      * pero no consigo cambiar el texto del botón
  7.      */
  8.     var _custom_media = true,
  9.       _orig_send_attachment = wp.media.editor.send.attachment;
  10.     function b5f_add_image1(button)
  11.     {
  12.         _custom_media = false;
  13.        // var _orig_send_attachment = wp.media.editor.send.attachment;
  14.         //var id = button.attr('id').replace('_button', '');
  15.         var parent = $(button).parent().parent('div.field_row');
  16.         var urlField = $(parent).find("input.meta_image_url");
  17.         var titleField = $(parent).find("input.meta_image_title");
  18.         var descField = $(parent).find("input.meta_image_desc");
  19.         var idField = $(parent).find("input.meta_image_id");
  20.  
  21.         _custom_media = true;
  22.         var my_options = {
  23.                 multiple: false
  24.         };
  25.         wp.media.editor.open(button,my_options);
  26.         wp.media.editor.send.attachment = function(props, attachment)
  27.         {
  28.             var sel_size = attachment.sizes[props.size].url;
  29.             if (_custom_media) {
  30.                 /* DATOS DE LA IMAGEN SELECCIONADA */
  31.                 //attachment.title;
  32.                 //attachment.description;
  33.                 //attachment.id;
  34.             } else {
  35.                 return _orig_send_attachment.apply(this, [props, attachment]);
  36.             }
  37.             ;
  38.         }
  39.         return false;
  40.     }
  41.    
  42.     /**
  43.      * Versión 2
  44.      * De aqui conseguimos cambiar el texto del botón
  45.      * pero no consigo sacar el tamaño elejido
  46.      */
  47.     var file_frame;
  48.     function b5f_add_image2(button)
  49.     {
  50.         // If the media frame already exists, reopen it.
  51.         if (file_frame) {
  52.             file_frame.open();
  53.             return;
  54.         }
  55.  
  56.         // Create the media frame.
  57.         file_frame = wp.media.frames.file_frame = wp.media({
  58.             title: 'upLoad Stuff',
  59.             button: {
  60.                 text: 'Up button text',
  61.             },
  62.             library: {
  63.                 type: 'image'
  64.             },
  65.             //state:'insert',
  66.             frame:'select',
  67.             displaySettings: true,
  68.             displayUserSettings:true,
  69.             toolbar:    'select',
  70.             search: true,
  71.             editable:false,
  72.             multiple: false  // Set to true to allow multiple files to be selected
  73.         });
  74.  
  75.         // When an image is selected, run a callback.
  76.         file_frame.on('select', function() {
  77.             // We set multiple to false so only get one image from the uploader
  78.             attachment = file_frame.state().get('selection').first().toJSON();
  79.             console.dir(file_frame.state().get('selection'));
  80.  
  81.             //attachment.url;
  82.             //attachment.title;
  83.             //attachment.description;
  84.             //attachment.id;
  85.         });
  86.         // Finally, open the modal
  87.         file_frame.open();
  88.     }
  89.  
  90.     /* Upload image */
  91.     $('#field_wrap').on('click', '.field_right .button-add', function() {
  92.         b5f_add_image1( $(this) );
  93.     });
  94.  
  95. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement