# speechkit/4.0.0/src/Component/Settings/Preselect/post.js

BeyondWords – AI audio for publishers, version 4.0.0. 52 lines.

- Page: https://pluginprobe.com/plugins/speechkit/4.0.0/code/src/Component/Settings/Preselect/post.js
- Raw: https://pluginprobe.com/plugins/speechkit/4.0.0/raw/src/Component/Settings/Preselect/post.js
- Modified: 2023-07-26T14:25:00+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/speechkit/4.0.0/code/src/Component/Settings/Preselect/post.js#L10-L20`.

```javascript
/* global jQuery, beyondwords */

'use strict';

jQuery( document ).ready( function ( $ ) {
	$( document ).on( 'click', 'input[name="post_category[]"]', function () {
		const postType = beyondwords.postType;
		const preselect =
			typeof beyondwords.preselect === 'object' &&
			beyondwords.preselect !== null
				? beyondwords.preselect
				: {};

		if ( ! ( postType in preselect ) ) {
			return;
		}

		// Exit if Generate audio is not being handled by taxonomies
		if ( ! ( 'category' in preselect[ postType ] ) ) {
			return;
		}

		// Exit if category is not an array
		if ( ! Array.isArray( preselect[ postType ].category ) ) {
			return;
		}

		const $checkbox = $( 'input#beyondwords_generate_audio' );

		if ( ! $checkbox ) {
			return;
		}

		// Get ALL currently-checked categories
		const checkedCategories = $( 'input[name="post_category[]"]:checked' )
			.map( function () {
				return this.value;
			} )
			.get();

		const intersections = checkedCategories.filter(
			( e ) => preselect[ postType ].category.indexOf( e ) !== -1
		);

		if ( intersections.length ) {
			$checkbox.prop( 'checked', true );
		} else {
			$checkbox.prop( 'checked', false );
		}
	} );
} );

```
