fixed js to handle multiple buttons

needed to set a global variable, apparently
This commit is contained in:
Robin Cornett
2015-01-06 20:45:37 -05:00
parent 3ec0be7c0b
commit a635fd0524
2 changed files with 6 additions and 5 deletions
@@ -215,8 +215,8 @@ class Display_Featured_Image_Genesis_Settings {
echo '<img src="' . esc_url( $preview[0] ) . '" />';
echo '</div>';
}
echo '<input type="url" class="upload_image_url" id="default_image_url" name="displayfeaturedimagegenesis[default]" value="' . esc_url( $this->displaysetting['default'] ) . '" />';
echo '<input id="upload_default_image" type="button" class="upload_default_image button-primary" value="' . __( 'Select Image', 'display-featured-image-genesis' ) . '" />';
echo '<input type="url" class="upload_image_url" id="displayfeaturedimagegenesis[default]" name="displayfeaturedimagegenesis[default]" value="' . esc_url( $this->displaysetting['default'] ) . '" />';
echo '<input type="button" class="upload_default_image button-primary" value="' . __( 'Select Image', 'display-featured-image-genesis' ) . '" />';
echo '<p class="description">' . sprintf(
__( 'If you would like to use a default image for the featured image, upload it here. Must be at least %1$s pixels wide.', 'display-featured-image-genesis' ),
absint( $item->large + 1 )
@@ -293,7 +293,7 @@ class Display_Featured_Image_Genesis_Settings {
echo '</div>';
}
echo '<input type="url" class="upload_image_url" id="displayfeaturedimagegenesis[post_type][' . $post_type . ']" name="displayfeaturedimagegenesis[post_type][' . $post_type . ']" value="' . esc_url( $this->displaysetting['post_type'][$post_type] ) . '" />';
echo '<input id="displayfeaturedimagegenesis[post_type][' . $post_type . ']" type="button" class="upload_default_image button" value="' . __( 'Select Image', 'display-featured-image-genesis' ) . '" />';
echo '<input type="button" class="upload_default_image button" value="' . __( 'Select Image', 'display-featured-image-genesis' ) . '" />';
}
+3 -2
View File
@@ -1,10 +1,11 @@
jQuery(document).ready(function($){
var custom_uploader;
var target_input;
$('.upload_default_image').click(function(e) {
var target_input = $(this).prev('.upload_image_url');
target_input = $(this).prev('.upload_image_url');
e.preventDefault();
@@ -25,8 +26,8 @@ jQuery(document).ready(function($){
//When a file is selected, grab the URL and set it as the text field's value
custom_uploader.on('select', function() {
attachment = custom_uploader.state().get('selection').first().toJSON();
// $('input[name=' + target_input + ']').val(attachment.url);
$(target_input).val(attachment.url);
});