function addImage(id) {
var dbaGoogleMapsFrame;
// If the media frame already exists, reopen it.
if (dbaGoogleMapsFrame) {
dbaGoogleMapsFrame.open();
return;
}
// Create the media frame.
dbaGoogleMapsFrame = wp.media.frames.dbaGoogleMapsFrame = wp.media({
state: 'insert',
frame: 'post',
multiple: false
});
// When an image is selected, run a callback.
dbaGoogleMapsFrame.on('insert', function () {
// Get media attachment details from the frame state
var attachment = dbaGoogleMapsFrame.state().get('selection').first().toJSON();
// Clear out the preview image
jQuery('#andreadb-google-maps-icon-marker-' + id + ' img').remove();
// Send the attachment URL to our custom image input field.
jQuery('#andreadb-google-maps-icon-marker-' + id).append('');
// Send the attachment id to our hidden input
jQuery('#andreadb-google-maps-icon-id-' + id).val(attachment.id);
// Show remove button
jQuery('#andreadb-remove-image-' + id).removeClass('hidden');
});
// Finally, open the modal.
dbaGoogleMapsFrame.open();
}
function removeImage(id) {
// Clear out the preview image
jQuery('#andreadb-google-maps-icon-marker-' + id + ' img').remove();
// Delete the image id from the hidden input
jQuery('#andreadb-google-maps-icon-id-' + id).val('');
// Hide remove button
jQuery('#andreadb-remove-image-' + id).addClass('hidden');
}
function openPreview(id) {
var url = andreadb_google_maps.iframeurl + '&andreadb_google_maps_id=' + id;
jQuery('body').append('