PluginProbe
BeyondWords – AI audio for publishers / 4.1.1
BeyondWords – AI audio for publishers v4.1.1
7.1.0 trunk 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.1.0 4.1.1 4.1.2 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.3.0 4.4.0 4.5.0 4.5.1 4.6.0 4.6.1 4.6.2 4.7.0 All 43 releases
speechkit / src / Component / Settings / Preselect / post.js

post.js in BeyondWords – AI audio for publishers 4.1.1, at src/Component/Settings/Preselect/post.js

52 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /* global jQuery, beyondwords */
2
3 'use strict';
4
5 jQuery( document ).ready( function ( $ ) {
6 $( document ).on( 'click', 'input[name="post_category[]"]', function () {
7 const postType = beyondwords.postType;
8 const preselect =
9 typeof beyondwords.preselect === 'object' &&
10 beyondwords.preselect !== null
11 ? beyondwords.preselect
12 : {};
13
14 if ( ! ( postType in preselect ) ) {
15 return;
16 }
17
18 // Exit if Generate audio is not being handled by taxonomies
19 if ( ! ( 'category' in preselect[ postType ] ) ) {
20 return;
21 }
22
23 // Exit if category is not an array
24 if ( ! Array.isArray( preselect[ postType ].category ) ) {
25 return;
26 }
27
28 const $checkbox = $( 'input#beyondwords_generate_audio' );
29
30 if ( ! $checkbox ) {
31 return;
32 }
33
34 // Get ALL currently-checked categories
35 const checkedCategories = $( 'input[name="post_category[]"]:checked' )
36 .map( function () {
37 return this.value;
38 } )
39 .get();
40
41 const intersections = checkedCategories.filter(
42 ( e ) => preselect[ postType ].category.indexOf( e ) !== -1
43 );
44
45 if ( intersections.length ) {
46 $checkbox.prop( 'checked', true );
47 } else {
48 $checkbox.prop( 'checked', false );
49 }
50 } );
51 } );
52