| 1 |
/** |
| 2 |
* Handles registration of TinyMCE buttons. |
| 3 |
* |
| 4 |
* @since 1.9.6 |
| 5 |
* |
| 6 |
* @package ConvertKit |
| 7 |
* @author ConvertKit |
| 8 |
*/ |
| 9 |
|
| 10 |
/** |
| 11 |
* Registers the given block as a TinyMCE Plugin, with a button in |
| 12 |
* the Visual Editor toolbar. |
| 13 |
* |
| 14 |
* @since 1.9.6 |
| 15 |
* |
| 16 |
* @param object block Block |
| 17 |
*/ |
| 18 |
function convertKitTinyMCERegisterPlugin( block ) { |
| 19 |
|
| 20 |
( function( $ ) { |
| 21 |
|
| 22 |
tinymce.PluginManager.add( |
| 23 |
'convertkit_' + block.name, |
| 24 |
function( editor, url ) { |
| 25 |
|
| 26 |
// Add Button to Visual Editor Toolbar. |
| 27 |
editor.addButton( |
| 28 |
'convertkit_' + block.name, |
| 29 |
{ |
| 30 |
title: block.title, |
| 31 |
image: url + '../../../../' + block.icon, |
| 32 |
cmd: 'convertkit_' + block.name, |
| 33 |
} |
| 34 |
); |
| 35 |
|
| 36 |
// Load View when button clicked. |
| 37 |
editor.addCommand( |
| 38 |
'convertkit_' + block.name, |
| 39 |
function() { |
| 40 |
|
| 41 |
// Open the TinyMCE Modal. |
| 42 |
editor.windowManager.open( |
| 43 |
{ |
| 44 |
id: 'convertkit-modal-body', |
| 45 |
title: block.title, |
| 46 |
width: block.modal.width, |
| 47 |
height: block.modal.height, |
| 48 |
inline: 1, |
| 49 |
buttons:[], |
| 50 |
} |
| 51 |
); |
| 52 |
|
| 53 |
// Perform an AJAX call to load the modal's view. |
| 54 |
$.post( |
| 55 |
ajaxurl, |
| 56 |
{ |
| 57 |
'action': 'convertkit_admin_tinymce_output_modal', |
| 58 |
'nonce': convertkit_admin_tinymce.nonce, |
| 59 |
'editor_type': 'tinymce', |
| 60 |
'shortcode': block.name |
| 61 |
}, |
| 62 |
function( response ) { |
| 63 |
|
| 64 |
// Inject HTML into modal. |
| 65 |
$( '#convertkit-modal-body-body' ).html( response ); |
| 66 |
|
| 67 |
// Initialize color pickers. |
| 68 |
$( '.convertkit-color-picker' ).wpColorPicker(); |
| 69 |
|
| 70 |
} |
| 71 |
); |
| 72 |
|
| 73 |
} |
| 74 |
); |
| 75 |
|
| 76 |
} |
| 77 |
); |
| 78 |
|
| 79 |
} )( jQuery ); |
| 80 |
|
| 81 |
} |
| 82 |
|