Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- jQuery(document).ready(function($)
- {
- /**
- * Versión 1
- * De aqui conseguimos sacar el tamaño elejido
- * pero no consigo cambiar el texto del botón
- */
- var _custom_media = true,
- _orig_send_attachment = wp.media.editor.send.attachment;
- function b5f_add_image1(button)
- {
- _custom_media = false;
- // var _orig_send_attachment = wp.media.editor.send.attachment;
- //var id = button.attr('id').replace('_button', '');
- var parent = $(button).parent().parent('div.field_row');
- var urlField = $(parent).find("input.meta_image_url");
- var titleField = $(parent).find("input.meta_image_title");
- var descField = $(parent).find("input.meta_image_desc");
- var idField = $(parent).find("input.meta_image_id");
- _custom_media = true;
- var my_options = {
- multiple: false
- };
- wp.media.editor.open(button,my_options);
- wp.media.editor.send.attachment = function(props, attachment)
- {
- var sel_size = attachment.sizes[props.size].url;
- if (_custom_media) {
- /* DATOS DE LA IMAGEN SELECCIONADA */
- //attachment.title;
- //attachment.description;
- //attachment.id;
- } else {
- return _orig_send_attachment.apply(this, [props, attachment]);
- }
- ;
- }
- return false;
- }
- /**
- * Versión 2
- * De aqui conseguimos cambiar el texto del botón
- * pero no consigo sacar el tamaño elejido
- */
- var file_frame;
- function b5f_add_image2(button)
- {
- // If the media frame already exists, reopen it.
- if (file_frame) {
- file_frame.open();
- return;
- }
- // Create the media frame.
- file_frame = wp.media.frames.file_frame = wp.media({
- title: 'upLoad Stuff',
- button: {
- text: 'Up button text',
- },
- library: {
- type: 'image'
- },
- //state:'insert',
- frame:'select',
- displaySettings: true,
- displayUserSettings:true,
- toolbar: 'select',
- search: true,
- editable:false,
- multiple: false // Set to true to allow multiple files to be selected
- });
- // When an image is selected, run a callback.
- file_frame.on('select', function() {
- // We set multiple to false so only get one image from the uploader
- attachment = file_frame.state().get('selection').first().toJSON();
- console.dir(file_frame.state().get('selection'));
- //attachment.url;
- //attachment.title;
- //attachment.description;
- //attachment.id;
- });
- // Finally, open the modal
- file_frame.open();
- }
- /* Upload image */
- $('#field_wrap').on('click', '.field_right .button-add', function() {
- b5f_add_image1( $(this) );
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement