|
| 1 | +--- |
| 2 | +title: Atto |
| 3 | +tags: [] |
| 4 | +--- |
| 5 | + |
| 6 | +<Since versions={["2.7"]} issueNumber="MDL-43841" /> |
| 7 | + |
| 8 | +Atto is a JavaScript text editor built specifically for Moodle. It is the default text editor in Moodle from 2.7 onwards, and is implemented as a standard Moodle [text editor plugin](./../../subsystems/editor/index.md). Most of the code is written in JavaScript using YUI modules. |
| 9 | + |
| 10 | +All of the buttons in Atto are implemented as Moodle subplugins. This means that the subplugins can do anything a subplugin can do including, using language strings, database tables, other JavaScript, and more. |
| 11 | + |
| 12 | +:::caution Sunset of Atto |
| 13 | + |
| 14 | +A new Editor was created for Moodle 4.1 and later using the latest version of TinyMCE. |
| 15 | + |
| 16 | +It is likely that Atto will be removed in Moodle 4.6. |
| 17 | + |
| 18 | +::: |
| 19 | + |
| 20 | +## File structure |
| 21 | + |
| 22 | +import { |
| 23 | + Lang, |
| 24 | + Lib, |
| 25 | + VersionPHP, |
| 26 | +} from '../../_files'; |
| 27 | +import Button from './_examples/button'; |
| 28 | + |
| 29 | +Atto plugins are located in the `/lib/editor/atto/plugins` directory. |
| 30 | + |
| 31 | +Each plugin is in a separate subdirectory and consists of a number of _mandatory files_ and any other files the developer is going to use. |
| 32 | + |
| 33 | +<details> |
| 34 | + <summary>View an example directory layout for the `atto_media` plugin.</summary> |
| 35 | + |
| 36 | +```console |
| 37 | + lib/editor/atto/plugins/media |
| 38 | + |-- db |
| 39 | + | └-- upgrade.php |
| 40 | + |-- lang |
| 41 | + | └-- en |
| 42 | + | └-- atto_media.php |
| 43 | + |-- yui |
| 44 | + | └-- src |
| 45 | + | └-- button |
| 46 | + | └-- atto_media.php |
| 47 | + | ├── build.json |
| 48 | + | ├── js |
| 49 | + | │ └── button.js |
| 50 | + | └── meta |
| 51 | + | └── button.json |
| 52 | + |-- settings.php |
| 53 | + └-- version.php |
| 54 | +``` |
| 55 | + |
| 56 | +</details> |
| 57 | + |
| 58 | +Some of the important files for the Atto plugintype are described below. See the [common plugin files](../commonfiles) documentation for details of other files which may be useful in your plugin. |
| 59 | + |
| 60 | +### version.php |
| 61 | + |
| 62 | +<VersionPHP |
| 63 | + plugintype="atto" |
| 64 | +/> |
| 65 | + |
| 66 | +### lib.php |
| 67 | + |
| 68 | +import LibExample from '!!raw-loader!./_examples/lib.php'; |
| 69 | +import LibDescription from './_examples/lib.md'; |
| 70 | + |
| 71 | +<Lib |
| 72 | + plugintype="atto" |
| 73 | + pluginname="media" |
| 74 | + description={LibDescription} |
| 75 | + example={LibExample} |
| 76 | + legacy={false} |
| 77 | + optional |
| 78 | +/> |
| 79 | + |
| 80 | +### yui/src/button/* |
| 81 | + |
| 82 | +<!-- markdownlint-disable no-inline-html --> |
| 83 | + |
| 84 | +<Button |
| 85 | + pluginname="media" |
| 86 | + modulename="button" |
| 87 | +/> |
| 88 | + |
| 89 | +:::note |
| 90 | + |
| 91 | +It is recommended that you extend the `EditorPlugin` class as described below. |
| 92 | +See: [YUI/Modules](../../../guides/javascript/yui/modules.md) for more information about YUI modules. |
| 93 | + |
| 94 | +::: |
| 95 | + |
| 96 | +The plugin: |
| 97 | + |
| 98 | +- **must** register a class at `Y.M.atto_PLUGINNAME.button`; |
| 99 | +- **must** provide a constructor; and |
| 100 | +- ***should*** extend [Y.M.editor_atto.EditorPlugin](https://github.com/moodle/moodle/blob/MOODLE_37_STABLE/lib/editor/atto/yui/src/editor/js/editor-plugin.js). |
| 101 | + |
| 102 | +#### EditorPlugin |
| 103 | + |
| 104 | +It is up to the plugin author to decide how best to write their plugin, but it is highly advisable to extend `EditorPlugin` class, which provides a number of useful functions for dealing with the Editor, Toolbars, Keyboard Navigation, and other related areas. |
| 105 | + |
| 106 | +Of particular interest are: |
| 107 | + |
| 108 | +- [addBasicButton](https://github.com/moodle/moodle/blob/MOODLE_37_STABLE/lib/editor/atto/yui/src/editor/js/editor-plugin-buttons.js#L293) - to add a basic button which directly uses document.execCommand with minimal effort; |
| 109 | +- [addButton](https://github.com/moodle/moodle/blob/MOODLE_37_STABLE/lib/editor/atto/yui/src/editor/js/editor-plugin-buttons.js#L161) - to add a button giving you a greater degree of control via your own callback; |
| 110 | +- [addToolbarMenu](https://github.com/moodle/moodle/blob/MOODLE_37_STABLE/lib/editor/atto/yui/src/editor/js/editor-plugin-buttons.js#L337) - to add a dropdown toolbar menu; |
| 111 | +- [markUpdated](https://github.com/moodle/moodle/blob/MOODLE_37_STABLE/lib/editor/atto/yui/src/editor/js/editor-plugin.js#L91) - should be called after making changes to the content area; and |
| 112 | +- [getDialogue](https://github.com/moodle/moodle/blob/MOODLE_37_STABLE/lib/editor/atto/yui/src/editor/js/editor-plugin-dialogue.js#L54) - return a standard dialogue, creating one if it does not already exist. |
0 commit comments