Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Atto: Difference between revisions

From MoodleDocs
Line 33: Line 33:
Atto sub plugins can contain a lib.php file with 2 callbacks that will be looked for when the plugin is loaded.
Atto sub plugins can contain a lib.php file with 2 callbacks that will be looked for when the plugin is loaded.


The first is (example taken from atto_table plugin):
The first is "XXX_strings_for_js" (example taken from atto_table plugin):


<pre>
<pre>

Revision as of 04:40, 29 January 2014

Moodle 2.7


Atto is a javascript text editor built specifically for Moodle. Atto is the default text editor in Moodle from 2.7 onwards.

Atto is implemented as a standard Moodle text editor plugin. Most of the code is written in javascript as a standard Moodle YUI module.

Atto Plugins

All of the buttons/menus in Atto are implemented as true Moodle subplugins. This means that the subplugins can do anything a subplugin can do including, lang strings, db tables, yui modules.

There are a couple of extra functions/structure required for an Atto subplugin which are required in order to load a plugin on the toolbar.

Structure of an Atto Plugin

/lib.php Optional. Only required if your plugin needs to implement one of the component callbacks listed below.

/settings.php Optional. Only required if your plugin wants to support custom admin settings. See: https://docs.moodle.org/dev/Admin_settings#Individual_settings for more info on settings.

/version.php Required. Moodle plugin version. See: https://docs.moodle.org/dev/version.php for more info on version files.

/lang/en/atto_pluginname.php Required. Language file. This file is required and must at least define the language string 'pluginname'.

/yui/src/button/ Required. 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 insert itself a class into the M.<plugin name> namespace, with an init function that will be called to initialise the editor. See: https://docs.moodle.org/dev/YUI/Modules for more information about YUI modules.

Atto subplugin Php API

Atto sub plugins can contain a lib.php file with 2 callbacks that will be looked for when the plugin is loaded.

The first is "XXX_strings_for_js" (example taken from atto_table plugin):

/**
 * Initialise the js strings required for this module.
 */
function atto_table_strings_for_js() {
    global $PAGE;

    $PAGE->requires->strings_for_js(array('createtable',
                                          'accessibilityhint',
                                          'headers',
                                          'caption',
                                          'columns',
                                          'rows',
                                          'numberofcolumns',
                                          'numberofrows',
                                          'both',
                                          'edittable',
                                          'addcolumnafter',
                                          'addrowafter',
                                          'movecolumnright',
                                          'movecolumnleft',
                                          'moverowdown',
                                          'moverowup',
                                          'deleterow',
                                          'deletecolumn'),
                                    'atto_table');
}

The purpose of this callback is to allow the plugin to initialise the strings that it will use in it's user interface. Note: that the pluginname string for each plugin is automatically loaded, and if this is the only string your plugin requires, then it is not necessary to implement this callback in your plugin. See: https://docs.moodle.org/dev/JavaScript_guidelines#Getting_Moodle_to_load_your_JavaScript_files for more information on strings_for_js.

Atto subplugin Javascript API