@@ -29,20 +29,49 @@ import {
29
29
import uploadHandler from "./upload-handler" ;
30
30
import {
31
31
addContextmenuItem ,
32
- addMenubarItem ,
33
- addToolbarButtons ,
34
32
} from 'editor_tiny/utils' ;
35
33
34
+ const configureMenu = ( menu ) => {
35
+ // Replace the standard Media plugin with the Moodle embed.
36
+ if ( menu . insert . items . match ( / \b m e d i a \b / ) ) {
37
+ menu . insert . items = menu . insert . items . replace ( / \b m e d i a \b / , videoButtonName ) ;
38
+ } else {
39
+ menu . insert . items = `${ videoButtonName } ${ menu . insert . items } ` ;
40
+ }
41
+
42
+ // Replace the standard image plugin with the Moodle image.
43
+ if ( menu . insert . items . match ( / \b i m a g e \b / ) ) {
44
+ menu . insert . items = menu . insert . items . replace ( / \b i m a g e \b / , imageButtonName ) ;
45
+ } else {
46
+ menu . insert . items = `${ imageButtonName } ${ menu . insert . items } ` ;
47
+ }
48
+
49
+ // Add the Media Manager to the end of the Tools menu.
50
+ menu . tools . items += ` ${ mediaManagerButtonName } ` ;
51
+
52
+ return menu ;
53
+ } ;
54
+
55
+ const configureToolbar = ( toolbar ) => {
56
+ // The toolbar contains an array of named sections.
57
+ // The Moodle integration ensures that there is a section called 'content'.
58
+
59
+ return toolbar . map ( ( section ) => {
60
+ if ( section . name === 'content' ) {
61
+ // Insert the image, and embed, buttons at the start of it.
62
+ section . items . unshift ( imageButtonName , videoButtonName ) ;
63
+ }
64
+
65
+ return section ;
66
+ } ) ;
67
+ } ;
68
+
36
69
export const configure = ( instanceConfig ) => {
37
70
// Update the instance configuration to add the Media menu option to the menus and toolbars and upload_handler.
38
71
return {
39
72
contextmenu : addContextmenuItem ( instanceConfig . contextmenu , imageButtonName , videoButtonName ) ,
40
- toolbar : addToolbarButtons ( instanceConfig . toolbar , 'content' , [ imageButtonName , videoButtonName ] ) ,
41
- menu : addMenubarItem (
42
- addMenubarItem ( instanceConfig . menu , 'insert' , `${ imageButtonName } ${ videoButtonName } ` ) ,
43
- 'tools' ,
44
- mediaManagerButtonName
45
- ) ,
73
+ menu : configureMenu ( instanceConfig . menu ) ,
74
+ toolbar : configureToolbar ( instanceConfig . toolbar ) ,
46
75
47
76
// eslint-disable-next-line camelcase
48
77
images_upload_handler : ( blobInfo , progress ) => uploadHandler ( window . tinymce . activeEditor , blobInfo , progress )
0 commit comments