| 1 |
/* global tinymce */ |
| 2 |
/* jshint unused:false */ |
| 3 |
(function($) { |
| 4 |
tinymce.PluginManager.add('visualizer_mce_button', function( editor, url ) { |
| 5 |
editor.addButton( 'visualizer_mce_button', { |
| 6 |
title: getTranslation( editor, 'plugin_label' ), |
| 7 |
label: getTranslation( editor, 'plugin_label' ), |
| 8 |
icon: 'visualizer-icon', |
| 9 |
onclick: function() { |
| 10 |
var frame = wp.media({ |
| 11 |
frame:'post', |
| 12 |
state:'visualizer' |
| 13 |
}); |
| 14 |
frame.open( ); |
| 15 |
} |
| 16 |
}); |
| 17 |
}); |
| 18 |
|
| 19 |
/** |
| 20 |
* Gets the translation from the editor (when classic editor is enabled) |
| 21 |
* OR |
| 22 |
* from the settings array inside the editor (when classic block inside gutenberg) |
| 23 |
*/ |
| 24 |
function getTranslation(editor, slug){ |
| 25 |
var string = editor.getLang('visualizer_tinymce_plugin.' + slug); |
| 26 |
// if the string is the same as the slug being requested for, look in the settings. |
| 27 |
if(string === '{#visualizer_tinymce_plugin.' + slug + '}'){ |
| 28 |
string = editor.settings.visualizer_tinymce_plugin[slug]; |
| 29 |
} |
| 30 |
return string; |
| 31 |
} |
| 32 |
|
| 33 |
})(jQuery); |
| 34 |
|