| 1 |
jQuery('#wpupg_add_custom_image').on('click', function(e) { |
| 2 |
e.preventDefault(); |
| 3 |
|
| 4 |
var button = jQuery(this); |
| 5 |
var input_url = button.parents('#wpupg_form_post').find('#wpupg_custom_image'); |
| 6 |
var input_id = button.parents('#wpupg_form_post').find('#wpupg_custom_image_id'); |
| 7 |
|
| 8 |
if(typeof wp.media == 'function') { |
| 9 |
var custom_uploader = wp.media({ |
| 10 |
title: 'Insert Media', |
| 11 |
button: { |
| 12 |
text: 'Set Custom Image' |
| 13 |
}, |
| 14 |
multiple: false |
| 15 |
}) |
| 16 |
.on('select', function() { |
| 17 |
var attachment = custom_uploader.state().get('selection').first().toJSON(); |
| 18 |
input_url.val(attachment.url); |
| 19 |
input_id.val(attachment.id); |
| 20 |
}) |
| 21 |
.open(); |
| 22 |
} |
| 23 |
}); |
| 24 |
|
| 25 |
jQuery('#wpupg_custom_image').on('keyup change', function() { |
| 26 |
jQuery(this).siblings('#wpupg_custom_image_id').val(''); |
| 27 |
}); |