* Executes a specific command on the currently active editor. * * @method execCommand * @param {String} cmd Command to perform for example Bold. * @param {Boolean} ui Optional boolean state if a UI should be presented for the command or not. * @param {Object/String/Number/Boolean} val
(cmd, ui, value)
| 651 | * @return {Boolean} true/false if the command was executed or not. |
| 652 | */ |
| 653 | execCommand(cmd, ui, value) { |
| 654 | const self = this; |
| 655 | const editorId = Type.isObject(value) ? value.id ?? value.index : value; |
| 656 | |
| 657 | // Manager commands |
| 658 | switch (cmd) { |
| 659 | case 'mceAddEditor': { |
| 660 | if (!self.get(editorId)) { |
| 661 | const editorOptions = value.options; |
| 662 | new Editor(editorId, editorOptions, self).render(); |
| 663 | } |
| 664 | |
| 665 | return true; |
| 666 | } |
| 667 | |
| 668 | case 'mceRemoveEditor': { |
| 669 | const editor = self.get(editorId); |
| 670 | if (editor) { |
| 671 | editor.remove(); |
| 672 | } |
| 673 | |
| 674 | return true; |
| 675 | } |
| 676 | |
| 677 | case 'mceToggleEditor': { |
| 678 | const editor = self.get(editorId); |
| 679 | if (!editor) { |
| 680 | self.execCommand('mceAddEditor', false, value); |
| 681 | return true; |
| 682 | } |
| 683 | |
| 684 | if (editor.isHidden()) { |
| 685 | editor.show(); |
| 686 | } else { |
| 687 | editor.hide(); |
| 688 | } |
| 689 | |
| 690 | return true; |
| 691 | } |
| 692 | } |
| 693 | |
| 694 | // Run command on active editor |
| 695 | if (self.activeEditor) { |
| 696 | return self.activeEditor.execCommand(cmd, ui, value); |
| 697 | } |
| 698 | |
| 699 | return false; |
| 700 | }, |
| 701 | |
| 702 | /** |
| 703 | * Calls the save method on all editor instances in the collection. This can be useful when a form is to be submitted. |