Skip to content

Commit

Permalink
custom menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Phuong committed Feb 14, 2022
1 parent 9af1de4 commit 59ee8d5
Showing 1 changed file with 59 additions and 2 deletions.
61 changes: 59 additions & 2 deletions src/widgets/RoxyMceWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* @time 1:59 SA
* @version 2.0.0
*/

namespace navatech\roxymce\widgets;

use navatech\roxymce\assets\TinyMceAsset;
Expand Down Expand Up @@ -63,6 +64,40 @@ class RoxyMceWidget extends Widget {
*/
public $action;

/**
* @var string function callback of setup.
* @see https://www.tiny.cloud/docs-4x/demo/custom-toolbar-menu-button/
*/
public $setup = null;

/**
* @var array function callback of setup.
* @see https://www.tiny.cloud/docs-4x/demo/custom-toolbar-menu-button/
* @example menu: { custom: { title: 'Custom Menu', items: 'undo redo myCustomMenuItem' }}
*/
public $menu = null;

/**
* @var array function callback of setup.
* @see https://www.tiny.cloud/docs-4x/demo/custom-toolbar-menu-button/
* @example menu: 'mybutton'
*/
public $toolbar1 = null;

/**
* @var array function callback of setup.
* @see https://www.tiny.cloud/docs-4x/demo/custom-toolbar-menu-button/
* @example menu: 'mybutton'
*/
public $toolbar2 = null;

/**
* @var array function callback of setup.
* @see https://www.tiny.cloud/docs-4x/demo/custom-toolbar-menu-button/
* @example menu: 'mybutton'
*/
public $toolbar3 = null;

/**
* Initializes the object.
* This method is invoked at the end of the constructor after the object is initialized with the
Expand Down Expand Up @@ -99,13 +134,35 @@ public function init() {
'plugins' => [
'advlist autolink autosave autoresize link image lists charmap print preview hr anchor pagebreak spellchecker',
'searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking',
'table contextmenu directionality emoticons template textcolor paste fullpage textcolor colorpicker textpattern'
'table contextmenu directionality emoticons template textcolor paste fullpage textcolor colorpicker textpattern',
],
'theme' => 'modern',
'toolbar1' => 'newdocument fullpage | undo redo | styleselect formatselect fontselect fontsizeselect',
'toolbar2' => 'print preview media | forecolor backcolor emoticons | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image media code',
'image_advtab' => true,
]);
if ($this->menu != null) {
$menu_bar = [];
foreach ($this->menu as $menu_name => $menu_config) {
$menu_bar[] = $menu_name;
if (isset($menu_config['items'])) {
$menu_config['items'] = implode(' ', $menu_config['items']);
} else {
$menu_config['items'] = '';
}
$this->clientOptions['menu'][$menu_name] = $menu_config;
}
$this->clientOptions['menubar'] = implode(' ', $menu_bar);
}
if ($this->toolbar1 != null) {
$this->clientOptions['toolbar1'] .= ' | ' . trim(implode(' ', $this->toolbar1));
}
if ($this->toolbar2 != null) {
$this->clientOptions['toolbar2'] .= ' | ' . trim(implode(' ', $this->toolbar2));
}
if ($this->toolbar3 != null) {
$this->clientOptions['toolbar3'] = implode(' ', $this->toolbar3);
}
if ($this->action === null) {
$this->action = Url::to(['roxymce/default']);
}
Expand All @@ -118,7 +175,7 @@ public function init() {
*/
public function run() {
$this->view->registerJs('$(function() {
tinyMCE.init({' . substr(Json::encode($this->clientOptions), 1, - 1) . ',"file_browser_callback": RoxyFileBrowser});
tinyMCE.init({' . substr(Json::encode($this->clientOptions), 1, - 1) . ', "setup": ' . $this->setup . ', "file_browser_callback": RoxyFileBrowser});
});', View::POS_HEAD);
$this->view->registerJs('function RoxyFileBrowser(field_name, url, type, win) {
var roxyMce = "' . $this->action . '";
Expand Down

0 comments on commit 59ee8d5

Please sign in to comment.