fixing js conflicts

ajax still is not working, although at this point it is doing something.
just exchanges for an empty list. also still conflicts with jo.
This commit is contained in:
Robin Cornett
2015-01-05 23:26:44 -05:00
parent 37cbcc7210
commit 920e782609
3 changed files with 32 additions and 32 deletions
@@ -181,10 +181,11 @@ class Display_Featured_Image_Genesis {
$check = strpos( get_current_screen()->id, 'displayfeaturedimagegenesis' );
wp_register_script( 'displayfeaturedimage-upload', plugins_url( '/includes/js/settings-upload.js', dirname( __FILE__ ) ), array( 'jquery', 'media-upload', 'thickbox' ), $version );
wp_register_script( 'widget-selector', plugins_url( '/includes/js/widget-selector.js', dirname( __FILE__ ) ), array( 'jquery' ), $version );
wp_register_script( 'widget_selector', plugins_url( '/includes/js/widget-selector.js', dirname( __FILE__ ) ), array( 'jquery' ), $version );
$screen = get_current_screen();
if ( 'appearance_page_displayfeaturedimagegenesis' === get_current_screen()->id || ! empty( get_current_screen()->taxonomy ) ) {
if ( 'appearance_page_displayfeaturedimagegenesis' === $screen->id || ! empty( $screen->taxonomy ) ) {
// if ( false !== $check || ! empty( get_current_screen()->taxonomy ) ) {
wp_enqueue_media();
wp_enqueue_script( 'displayfeaturedimage-upload' );
@@ -193,10 +194,9 @@ class Display_Featured_Image_Genesis {
) );
}
$screen = get_current_screen()->id;
if ( $screen === 'widgets' || $screen === 'customize' ) {
wp_enqueue_script( 'widget-selector' );
wp_localize_script( 'widget-selector', 'ajax_object', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );
if ( in_array( $screen->id, array( 'widgets', 'customize' ) ) ) {
wp_enqueue_script( 'widget_selector' );
wp_localize_script( 'widget_selector', 'displayfeaturedimagegenesis_ajax_object', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );
}
}
+22 -22
View File
@@ -1,25 +1,25 @@
function tax_term_postback( select_id, taxonomy ) {
var data = {
action: 'tax_term_action',
taxonomy: taxonomy
};
jQuery.post(ajax_object.ajax_url, data, function(response) {
// Decode the data received.
var terms = jQuery.parseJSON(response);
function term_postback( select_id, taxonomy ) {
var data = {
action: 'widget_selector',
taxonomy: taxonomy
};
jQuery.post(displayfeaturedimagegenesis_ajax_object.ajax_url, data, function(response) {
// Decode the data received.
var list = jQuery.parseJSON(response);
// Keep track of what was previously selected
var select_ctrl = jQuery('#' + select_id);
var old_term = select_ctrl.val();
// Keep track of what was previously selected
var control = jQuery('#' + select_id);
var old_value = control.val();
// Clear out the old options, build up the new
select_ctrl.empty();
jQuery.each(terms, function(key, value) {
var new_option = jQuery('<option></option>')
.attr('value', key).text(value);
if (value == old_term) {
new_option.attr('selected', true);
}
select_ctrl.append(new_option);
// Clear out the old options, build up the new
control.empty();
jQuery.each(list, function(key, value) {
var new_option = jQuery('<option></option>')
.attr('value', key).text(value);
if (value == old_value) {
new_option.attr('selected', true);
}
control.append(new_option);
});
});
});
}
}
@@ -275,12 +275,11 @@ class Display_Featured_Image_Genesis_Widget extends WP_Widget {
/**
* Handles the callback to populate the custom term dropdown. The
* selected post type is provided in $_POST['post_type'], and the
* selected post type is provided in $_POST['taxonomy'], and the
* calling script expects a JSON array of term objects.
*/
function tax_term_action_callback() {
function term_action_callback() {
// And from there, a list of available terms in that tax
$args = array(
'orderby' => 'name',
'order' => 'ASC',
@@ -288,9 +287,10 @@ class Display_Featured_Image_Genesis_Widget extends WP_Widget {
);
$terms = get_terms( $_POST['taxonomy'], $args );
$list = array();
// Build an appropriate JSON response containing this info
foreach ( $terms as $term ) {
$list[$term->slug] = $term->name;
$list[$term->term_id] = $term->name;
}
// And emit it