| 1 |
jQuery(document).ready(function ($) { |
| 2 |
jQuery('#wpupg_add_custom_image').on('click', function(e) { |
| 3 |
e.preventDefault(); |
| 4 |
|
| 5 |
var button = jQuery(this); |
| 6 |
var input_url = button.parents('#wpupg_form_post').find('#wpupg_custom_image'); |
| 7 |
var input_id = button.parents('#wpupg_form_post').find('#wpupg_custom_image_id'); |
| 8 |
|
| 9 |
if(typeof wp.media == 'function') { |
| 10 |
var custom_uploader = wp.media({ |
| 11 |
title: 'Insert Media', |
| 12 |
button: { |
| 13 |
text: 'Set Custom Image' |
| 14 |
}, |
| 15 |
multiple: false |
| 16 |
}) |
| 17 |
.on('select', function() { |
| 18 |
var attachment = custom_uploader.state().get('selection').first().toJSON(); |
| 19 |
input_url.val(attachment.url); |
| 20 |
input_id.val(attachment.id); |
| 21 |
}) |
| 22 |
.open(); |
| 23 |
} |
| 24 |
}); |
| 25 |
|
| 26 |
jQuery('#wpupg_custom_image').on('keyup change', function() { |
| 27 |
jQuery(this).siblings('#wpupg_custom_image_id').val(''); |
| 28 |
}); |
| 29 |
|
| 30 |
jQuery('.term-custom-image').on('click', '#wpupg_custom_image_button.button-add', function (e) { |
| 31 |
console.log(wp.media); |
| 32 |
if(typeof wp.media == 'function') { |
| 33 |
var custom_uploader = wp.media({ |
| 34 |
title: wpupg_admin_post.text_add_grid_image, |
| 35 |
button: { |
| 36 |
text: wpupg_admin_post.text_add_grid_image |
| 37 |
}, |
| 38 |
multiple: false |
| 39 |
}) |
| 40 |
.on('select', function() { |
| 41 |
var attachment = custom_uploader.state().get('selection').first().toJSON(); |
| 42 |
jQuery('#wpupg_custom_image_img').attr('src', attachment.url); |
| 43 |
jQuery('#wpupg_custom_image').val(attachment.id); |
| 44 |
jQuery('#wpupg_custom_image_button') |
| 45 |
.removeClass('button-add') |
| 46 |
.addClass('button-remove') |
| 47 |
.val(wpupg_admin_post.text_remove_grid_image); |
| 48 |
}) |
| 49 |
.open(); |
| 50 |
} |
| 51 |
}); |
| 52 |
|
| 53 |
jQuery('.term-custom-image').on('click', '#wpupg_custom_image_button.button-remove', function (e) { |
| 54 |
jQuery('#wpupg_custom_image_img').attr('src', ''); |
| 55 |
jQuery('#wpupg_custom_image').val(''); |
| 56 |
jQuery('#wpupg_custom_image_button') |
| 57 |
.removeClass('button-remove') |
| 58 |
.addClass('button-add') |
| 59 |
.val(wpupg_admin_post.text_add_grid_image); |
| 60 |
}); |
| 61 |
}); |