| 1 |
/* |
| 2 |
* WpStream TinyMCE shortcode buttons. |
| 3 |
* |
| 4 |
* Registers the player toolbar button for the WordPress Classic Editor. |
| 5 |
*/ |
| 6 |
|
| 7 |
// Register the "WpStream Player" shortcode button. |
| 8 |
(function () { |
| 9 |
"use strict"; |
| 10 |
// Define the TinyMCE plugin that provides the player-insertion button. |
| 11 |
tinymce.create('tinymce.plugins.wpstream_player', { |
| 12 |
/** |
| 13 |
* TinyMCE plugin init: add the toolbar button to the editor. |
| 14 |
* |
| 15 |
* @param {object} ed The TinyMCE editor instance. |
| 16 |
* @param {string} url Base URL of this plugin's asset folder (for images). |
| 17 |
*/ |
| 18 |
init: function (ed, url) { |
| 19 |
// Register the toolbar button and its click behaviour. |
| 20 |
ed.addButton('wpstream_player', { |
| 21 |
title: 'WpStream Player', // tooltip shown on hover |
| 22 |
image: url + '/button.png', // button icon, resolved against the asset URL |
| 23 |
onclick: function () { |
| 24 |
// Insert an empty player shortcode skeleton at the cursor. |
| 25 |
ed.selection.setContent('[wpstream_player id="Add here the live stream id or the video id" ][/wpstream_player]'); |
| 26 |
} |
| 27 |
}); |
| 28 |
}, |
| 29 |
/** |
| 30 |
* TinyMCE plugin createControl hook: no custom control is provided. |
| 31 |
* |
| 32 |
* @param {string} n Control name requested by TinyMCE. |
| 33 |
* @param {object} cm Control manager. |
| 34 |
* @return {null} Always null (this plugin only adds a button). |
| 35 |
*/ |
| 36 |
createControl: function (n, cm) { |
| 37 |
return null; |
| 38 |
} |
| 39 |
}); |
| 40 |
// Register the completed plugin definition with TinyMCE. |
| 41 |
tinymce.PluginManager.add('wpstream_player', tinymce.plugins.wpstream_player); |
| 42 |
})(); |
| 43 |
|