Skip to content

Commit 3ee71b4

Browse files
committed
Add video JS handler to apply Able Player on all video elements.
See: #14
1 parent 02e8390 commit 3ee71b4

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/ableplayer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ function ableplayer_enqueue_scripts() {
4747
// Register/enqueue other dependencies.
4848
wp_enqueue_script( 'js-cookie', plugins_url( 'thirdparty', __FILE__ ) . '/js.cookie.js', array( 'jquery' ), ABLEPLAYER_VERSION, true );
4949
wp_enqueue_script( 'vimeo', 'https://player.vimeo.com/api/player.js', array(), ABLEPLAYER_VERSION, true );
50+
wp_register_script( 'ableplayer-video', plugins_url( 'assets', __FILE__ ) . '/js/video.js', array(), ABLEPLAYER_VERSION, true );
5051

5152
// if the environment is production, use minified files. Otherwise, inherit the value of SCRIPT_DEBUG.
5253
$is_production = ( function_exists( 'wp_get_environment_type' ) && wp_get_environment_type() === 'production' ) ? true : SCRIPT_DEBUG;
@@ -77,7 +78,7 @@ function ableplayer_enqueue_scripts() {
7778
$css_dir = apply_filters( 'able_player_css', plugins_url( 'build', __FILE__ ) . '/' . $css_file, $is_production );
7879

7980
// Enqueue Able Player script and CSS.
80-
wp_enqueue_script( 'ableplayer', $js_dir, array( 'jquery' ), ABLEPLAYER_VERSION, true );
81+
wp_enqueue_script( 'ableplayer', $js_dir, array( 'jquery', 'ableplayer-video' ), ABLEPLAYER_VERSION, true );
8182
wp_enqueue_style( 'ableplayer', $css_dir, array(), ABLEPLAYER_VERSION );
8283
}
8384
add_action( 'wp_enqueue_scripts', 'ableplayer_enqueue_scripts' );

src/assets/js/video.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const videoEls = document.querySelectorAll( 'video, audio' );
2+
if ( videoEls ) {
3+
videoEls.forEach((el,index,listObj) => {
4+
if ( ! el.hasAttribute( 'data-able-player' ) ) {
5+
el.setAttribute( 'data-able-player', 'true' );
6+
}
7+
if ( ! el.hasAttribute( 'id' ) ) {
8+
el.setAttribute( 'id', 'able-player-id-' + index );
9+
}
10+
});
11+
}

0 commit comments

Comments
 (0)