Skip to content

Commit 4cedc53

Browse files
committed
Add support to inject a transcript div.
1 parent 720a75c commit 4cedc53

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/assets/js/media.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,14 @@ if ( ablePlayers ) {
4242
el.setAttribute( 'data-hide-controls', 'true' );
4343
}
4444
}
45+
if ( 'true' === ableplayer.settings.render_transcript ) {
46+
if ( ! el.hasAttribute( 'data-transcript-div' ) ) {
47+
el.setAttribute( 'data-transcript-div', 'ableplayer-transcript-' + el.getAttribute( 'id' ) );
48+
let transcriptContainer = document.createElement( 'div' );
49+
transcriptContainer.setAttribute( 'id', 'ableplayer-transcript-' + el.getAttribute( 'id' ) );
50+
transcriptContainer.classList.add( 'ableplayer-transcript' );
51+
el.insertAdjacentElement( 'afterend', transcriptContainer );
52+
}
53+
}
4554
});
4655
}

src/inc/settings.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ function ableplayer_update_settings( $post ) {
257257
$replace_audio = ( ! empty( $post['replace_audio'] ) && 'on' === $post['replace_audio'] ) ? 'true' : 'false';
258258
$replace_playlists = ( ! empty( $post['replace_playlists'] ) && 'on' === $post['replace_playlists'] ) ? 'true' : 'false';
259259
$youtube_nocookie = ( ! empty( $post['youtube_nocookie'] ) && 'on' === $post['youtube_nocookie'] ) ? 'true' : 'false';
260+
$render_transcript = ( ! empty( $post['render_transcript'] ) && 'on' === $post['render_transcript'] ) ? 'true' : 'false';
260261
$hide_controls = ( ! empty( $post['hide_controls'] ) && 'on' === $post['hide_controls'] ) ? 'true' : 'false';
261262
$default_speed = ( isset( $post['default_speed'] ) ) ? $post['default_speed'] : 'animals';
262263
$default_heading = ( isset( $post['default_heading'] ) ) ? $post['default_heading'] : 'auto';
@@ -266,6 +267,7 @@ function ableplayer_update_settings( $post ) {
266267
$settings['replace_audio'] = $replace_audio;
267268
$settings['replace_playlists'] = $replace_playlists;
268269
$settings['youtube_nocookie'] = $youtube_nocookie;
270+
$settings['render_transcript'] = $render_transcript;
269271
$settings['hide_controls'] = $hide_controls;
270272
$settings['default_speed'] = $default_speed;
271273
$settings['default_heading'] = $default_heading;
@@ -356,6 +358,17 @@ function ableplayer_settings_form() {
356358
?>
357359
</p>
358360
<p>
361+
<?php
362+
ableplayer_settings_field(
363+
array(
364+
'name' => 'render_transcript',
365+
'label' => __( 'Insert interactive transcript container.', 'ableplayer' ),
366+
'type' => 'checkbox-single',
367+
)
368+
);
369+
?>
370+
</p>
371+
<p>
359372
<?php
360373
ableplayer_settings_field(
361374
array(
@@ -534,6 +547,7 @@ function ableplayer_default_settings() {
534547
'replace_audio' => 'false',
535548
'replace_playlists' => 'false',
536549
'youtube_nocookie' => 'false',
550+
'render_transcript' => 'true',
537551
'default_poster' => '',
538552
'default_speed' => 'animals',
539553
'hide_controls' => 'false',

0 commit comments

Comments
 (0)