1 // This file is part of Moodle - http://moodle.org/
3 // Moodle is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
8 // Moodle is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
26 * Atto text editor superscript plugin.
28 * @package editor-atto
29 * @copyright 2014 Rossiani Wijaya <rwijaya@moodle.com>
30 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
32 M.atto_superscript = M.atto_superscript || {
33 init : function(params) {
34 var click = function(e, elementid) {
36 if (!M.editor_atto.is_active(elementid)) {
37 M.editor_atto.focus(elementid);
39 document.execCommand('superscript', false, null);
40 // Clean the YUI ids from the HTML.
41 M.editor_atto.text_updated(elementid);
44 var iconurl = M.util.image_url('e/superscript', 'core');
45 M.editor_atto.add_toolbar_button(params.elementid, 'superscript', iconurl, params.group, click);
47 // Attach an event listner to watch for "changes" in the contenteditable.
48 // This includes cursor changes, we check if the button should be active or not, based
49 // on the text selection.
50 M.editor_atto.on('atto:selectionchanged', function(e) {
51 if (M.editor_atto.selection_filter_matches(e.elementid, SELECTORS.TAGS, e.selectedNodes)) {
52 M.editor_atto.add_widget_highlight(e.elementid, 'sup');
54 M.editor_atto.remove_widget_highlight(e.elementid, 'sup');