Update dynamic term selector for widget

This commit is contained in:
Robin Cornett
2019-11-17 15:05:29 -05:00
parent f7c070f775
commit 50cb27d8f4
2 changed files with 15 additions and 13 deletions
+14 -12
View File
@@ -1,26 +1,28 @@
function term_postback( select_id, taxonomy ) {
function term_postback ( select_id, taxonomy ) {
'use strict';
var data = {
action: 'widget_selector',
taxonomy: taxonomy
};
jQuery.post(displayfeaturedimagegenesis_ajax_object.ajax_url, data, function(response) {
jQuery.post( displayfeaturedimagegenesis_ajax_object.ajax_url, data, function ( response ) {
// Decode the data received.
var list = jQuery.parseJSON(response);
var list = jQuery.parseJSON( response );
// Keep track of what was previously selected
var control = jQuery('#' + select_id);
var control = jQuery( '#' + select_id );
var old_value = control.val();
// 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);
jQuery.each( list, function ( key, value ) {
var new_option = jQuery( '<option />' )
.val( key ).text( value );
control.val( '' );
if ( value === old_value ) {
control.val( old_value );
}
control.append(new_option);
});
});
var method = !key ? 'prepend' : 'append';
control[ method ]( new_option );
} );
} );
}
+1 -1
View File
@@ -1 +1 @@
function term_postback(e,t){"use strict";var a={action:"widget_selector",taxonomy:t};jQuery.post(displayfeaturedimagegenesis_ajax_object.ajax_url,a,(function(t){var a=jQuery.parseJSON(t),r=jQuery("#"+e),o=r.val();r.empty(),jQuery.each(a,(function(e,t){var a=jQuery("<option></option>").attr("value",e).text(t);t==o&&a.attr("selected",!0),r.append(a)}))}))}
function term_postback(e,a){"use strict";var t={action:"widget_selector",taxonomy:a};jQuery.post(displayfeaturedimagegenesis_ajax_object.ajax_url,t,(function(a){var t=jQuery.parseJSON(a),r=jQuery("#"+e),n=r.val();r.empty(),jQuery.each(t,(function(e,a){var t=jQuery("<option />").val(e).text(a);r.val(""),a===n&&r.val(n),r[e?"append":"prepend"](t)}))}))}