| 1 |
(function ( $ ) { |
| 2 |
|
| 3 |
// On change taxonomy |
| 4 |
$('body').on('change', '.automatorwp-action-wordpress-create-post .cmb2-id-taxonomy select, ' |
| 5 |
+ '.automatorwp-action-wordpress-update-post .cmb2-id-taxonomy select, ' |
| 6 |
+ '.automatorwp-action-wordpress-update-multiple-posts .cmb2-id-taxonomy select, ' |
| 7 |
+ '.automatorwp-action-posts-create-post .cmb2-id-taxonomy select, ' |
| 8 |
+ '.automatorwp-action-posts-update-post .cmb2-id-taxonomy select, ' |
| 9 |
+ '.automatorwp-action-posts-update-multiple-posts .cmb2-id-taxonomy select', function(e) { |
| 10 |
var taxonomy = $(this).closest('.cmb-row'); |
| 11 |
var taxonomy_term = taxonomy.next('.cmb2-id-post-terms'); |
| 12 |
|
| 13 |
var taxonomy_id = $(this).val(); |
| 14 |
|
| 15 |
var first_change = taxonomy.hasClass('is-option-change'); |
| 16 |
|
| 17 |
if( taxonomy_id === 'any' || taxonomy_id === '' ) { |
| 18 |
// Hide the term selector |
| 19 |
if( first_change ) { |
| 20 |
taxonomy_term.hide(); |
| 21 |
} else { |
| 22 |
taxonomy_term.slideUp('fast'); |
| 23 |
} |
| 24 |
} else { |
| 25 |
var term_selector = taxonomy_term.find('select.select2-hidden-accessible'); |
| 26 |
|
| 27 |
// Remove Select2 element |
| 28 |
term_selector.next('.select2').remove(); |
| 29 |
|
| 30 |
// Update the taxonomy (since we do not use the table attribute, lets to use it as taxonomy) |
| 31 |
term_selector.data( 'table', taxonomy_id ); |
| 32 |
|
| 33 |
// Reset the selector |
| 34 |
term_selector.removeAttr('data-select2-id'); |
| 35 |
|
| 36 |
// Init it again |
| 37 |
automatorwp_ajax_selector( term_selector ); |
| 38 |
|
| 39 |
// Show the term selector |
| 40 |
if( first_change ) { |
| 41 |
taxonomy_term.show(); |
| 42 |
} else { |
| 43 |
taxonomy_term.slideDown('fast'); |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
taxonomy.removeClass('is-option-change'); |
| 48 |
}); |
| 49 |
|
| 50 |
// On click on an option, check if form contains the taxonomy selector |
| 51 |
$('body').on('click', '.automatorwp-automation-item-label > .automatorwp-option', function(e) { |
| 52 |
|
| 53 |
var item = $(this).closest('.automatorwp-automation-item'); |
| 54 |
var option = $(this).data('option'); |
| 55 |
var option_form = item.find('.automatorwp-option-form-container[data-option="' + option + '"]'); |
| 56 |
var taxonomy_selector = option_form.find('.cmb2-id-taxonomy'); |
| 57 |
|
| 58 |
if( taxonomy_selector !== undefined ) { |
| 59 |
taxonomy_selector.addClass('is-option-change'); |
| 60 |
taxonomy_selector.find('select.select2-hidden-accessible').trigger('change'); |
| 61 |
} |
| 62 |
|
| 63 |
}); |
| 64 |
|
| 65 |
})( jQuery ); |