PluginProbe
BeyondWords – AI audio for publishers / 4.5.0
BeyondWords – AI audio for publishers v4.5.0
7.2.0 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 All 44 releases
speechkit / src / Compatibility / Elementor / js / components / beyondwords / hooks / init-players-after-document-save.js

init-players-after-document-save.js in BeyondWords – AI audio for publishers 4.5.0, at src/Compatibility/Elementor/js/components/beyondwords/hooks/init-players-after-document-save.js

78 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /* global jQuery, $e, elementor */
2
3 // UI hook, fired after the command runs.
4 // Important: Available to run in the console but depends on $e.components example#1.
5
6 export class InitPlayersAfterDocumentSave extends $e.modules.hookData.After {
7 getCommand() {
8 // Command to hook.
9 return 'document/save/save';
10 }
11
12 getId() {
13 // Unique id for the hook.
14 return 'beyondwords-init-players-after-document-save';
15 }
16
17 /*
18 * The actual hook logic.
19 */
20 apply( args ) {
21 const { document = elementor.documents.getCurrent(), status } = args;
22
23 if ( status === 'autosave' ) {
24 return;
25 }
26
27 window.elementorCommon.ajax
28 .addRequest( 'get_beyondwords_data', {
29 error: ( data ) => this.onRequestError( data, document ),
30 } )
31 .then( ( data ) => this.onRequestSuccess( data, document ) );
32 }
33
34 onRequestSuccess( data, document ) {
35 const { beyondwords_project_id, beyondwords_content_id } = data;
36
37 // Remove document cache.
38 elementor.documents.invalidateCache( document.id );
39
40 // Update Elementor controls
41 $e.run( 'document/elements/settings', {
42 container: elementor.settings.page.getEditedView().getContainer(),
43 settings: {
44 control_beyondwords_project_id: beyondwords_project_id,
45 control_beyondwords_content_id: beyondwords_content_id,
46 },
47 options: {
48 external: true,
49 },
50 } );
51
52 jQuery( '#beyondwords-elementor-editor-player' ).attr(
53 'data-beyondwords-project-id',
54 beyondwords_project_id
55 );
56
57 jQuery( '#beyondwords-elementor-editor-player' ).attr(
58 'data-beyondwords-content-id',
59 beyondwords_content_id
60 );
61
62 setTimeout( function () {
63 window.beyondwordsElementorCompatibility.initPlayer();
64 }, 250 );
65
66 return {
67 data,
68 };
69 }
70
71 onRequestError() {
72 elementor.notifications.showToast( {
73 message:
74 'Unable to retrieve BeyondWords data. Please refresh the page to see the player.',
75 } );
76 }
77 }
78