Atto
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. Most of the code is written in JavaScript using YUI modules.
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.
A new Editor was created for Moodle 4.1 and later using the latest version of TinyMCE.
It is likely that Atto will be removed in Moodle 4.6.
File structure
Atto plugins are located in the /lib/editor/atto/plugins
directory.
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.
View an example directory layout for the atto_media
plugin.
Some of the important files for the Atto plugintype are described below. See the common plugin files documentation for details of other files which may be useful in your plugin.
version.php
Version metadata
File path: /version.php
The version.php contains metadata about the plugin.
It is used during the installation and upgrade of the plugin.
This file contains metadata used to describe the plugin, and includes information such as:
- the version number
- a list of dependencies
- the minimum Moodle version required
- maturity of the plugin
View example
lib.php
Global plugin functions
File path: /lib.php
An optional file which can be used to implement optional component callbacks.
The available callbacks are:
atto_[pluginname]_strings_for_js
- To add strings required by the YUI codeatto_[pluginname]_params_for_js
- To get the parameters required to instantiate the plugin
View example
yui/src/button/*
Example Button JavaScript
File path: /yui/src/button/js/button.js
The plugin must implement a YUI module that will be included by the editor when the page loads.
That YUI module must be named button
and must create a namespaced class in Y.M.[plugin name]
.
View example
It is recommended that you extend the EditorPlugin
class as described below.
See: YUI/Modules for more information about YUI modules.
The plugin:
- must register a class at
Y.M.atto_PLUGINNAME.button
; - must provide a constructor; and
- should extend Y.M.editor_atto.EditorPlugin.
EditorPlugin
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.
Of particular interest are:
- addBasicButton - to add a basic button which directly uses document.execCommand with minimal effort;
- addButton - to add a button giving you a greater degree of control via your own callback;
- addToolbarMenu - to add a dropdown toolbar menu;
- markUpdated - should be called after making changes to the content area; and
- getDialogue - return a standard dialogue, creating one if it does not already exist.