| 1 |
/* global jQuery, $e */ |
| 2 |
|
| 3 |
import { BeyondwordsComponent } from './components'; |
| 4 |
import { BeyondWordsSdk } from '@beyondwords/audio-player'; |
| 5 |
|
| 6 |
export default class BeyondwordsElementorCompatibility { |
| 7 |
constructor() { |
| 8 |
jQuery( window ).on( 'elementor/init', function () { |
| 9 |
$e.components.register( new BeyondwordsComponent() ); |
| 10 |
} ); |
| 11 |
} |
| 12 |
|
| 13 |
/** |
| 14 |
* For now, this has been mostly copied from src/Core/Player.php. |
| 15 |
* |
| 16 |
* @todo Support all player params e.g. `beyondwords_player_size`. |
| 17 |
* |
| 18 |
* @param {*} params Params are NOT being passed at the moment |
| 19 |
* @return {Promise} |
| 20 |
*/ |
| 21 |
async initPlayer( params ) { |
| 22 |
const PLAYER_ID = `beyondwords-elementor-editor-player`; |
| 23 |
const PLAYER_SELECTOR = `div#${ PLAYER_ID }:not([data-beyondwords-init])`; |
| 24 |
|
| 25 |
const el = document.querySelector( PLAYER_SELECTOR ); |
| 26 |
|
| 27 |
const projectId = el.getAttribute( 'data-beyondwords-project-id' ).toString(); |
| 28 |
const contentId = el.getAttribute( 'data-beyondwords-content-id' ).toString(); |
| 29 |
|
| 30 |
const renderNode = PLAYER_ID; |
| 31 |
|
| 32 |
if ( ! projectId || ! contentId ) { |
| 33 |
return false; |
| 34 |
} |
| 35 |
|
| 36 |
// console.log( 'BeyondwordsElementorCompatibility::initPlayer', { |
| 37 |
// projectId, |
| 38 |
// contentId, |
| 39 |
// renderNode, |
| 40 |
// } ); |
| 41 |
|
| 42 |
// console.log('BeyondWordsSdk', BeyondWordsSdk); |
| 43 |
|
| 44 |
return await BeyondWordsSdk.player( { |
| 45 |
projectId, |
| 46 |
podcastId: contentId, |
| 47 |
renderNode, |
| 48 |
processingStatus: true, |
| 49 |
} ).then( ( player ) => { |
| 50 |
el.setAttribute( 'data-beyondwords-init', 'true' ); |
| 51 |
console.log( `🔊 Elementor player #${ PLAYER_ID } is initialized`, player ); |
| 52 |
} ); |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
window.beyondwordsElementorCompatibility = |
| 57 |
new BeyondwordsElementorCompatibility(); |
| 58 |
|