tinymce.js
2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/**
* Handles registration of TinyMCE buttons.
*
* @since 1.4.9
*
* @package Media_Library_Organizer
* @author WP Media Library
*/
/**
* Registers the given shortcode as a TinyMCE Plugin, with a button in
* the Visual Editor toolbar.
*
* @since 1.4.9
*
* @param object block Block
*/
function mediaLibraryOrganizerTinyMCERegisterPlugin( block ) {
( function( $ ) {
tinymce.PluginManager.add(
block.prefix + '_' + block.name.replaceAll( '-', '_' ),
function( editor, url ) {
// Add Button to Visual Editor Toolbar.
editor.addButton(
block.prefix + '_' + block.name.replaceAll( '-', '_' ),
{
title: block.title,
image: block.icon,
cmd: 'media_library_organizer_' + block.name.replaceAll( '-', '_' ),
}
);
// Load View when button clicked.
editor.addCommand(
block.prefix + '_' + block.name.replaceAll( '-', '_' ),
function() {
// Open the TinyMCE Modal.
editor.windowManager.open(
{
id: 'wpzinc-tinymce-modal',
title: block.title,
width: block.modal.width,
height: block.modal.height,
// See dashboard submodule's tinymce-modal.js which handles
// insert and cancel button clicks.
buttons: [
{
text: media_library_organizer_tinymce.labels.cancel,
classes: 'cancel'
},
{
text: media_library_organizer_tinymce.labels.insert,
subtype: 'primary',
classes: 'insert'
}
]
}
);
// Perform an AJAX call to load the modal's view.
$.post(
ajaxurl,
{
'action': 'media_library_organizer_tinymce_output_modal',
'nonce': media_library_organizer_tinymce.nonce,
'editor_type': 'tinymce',
'shortcode': block.name
},
function( response ) {
// Inject HTML into modal.
jQuery( '#wpzinc-tinymce-modal-body' ).html( response );
// Initialize tabbed interface.
wp_zinc_tabs_init();
// Initialize any Selectize instances now.
mediaLibraryOrganizerSelectizeInit();
}
);
}
);
}
);
} )( jQuery );
}