MDL-44128 Atto: fix keyboard navigation for the dropdowns
[moodle.git] / lib / editor / atto / plugins / superscript / yui / src / button / js / button.js
blob368c65f9de8ebaa0a3e20b284b335c09330bda0b
1 // This file is part of Moodle - http://moodle.org/
2 //
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.
7 //
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/>.
16 /**
17  * Selectors.
18  *
19  * @type {Object}
20  */
21 var SELECTORS = {
22     TAGS : 'sup'
25 /**
26  * Atto text editor superscript plugin.
27  *
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
31  */
32 M.atto_superscript = M.atto_superscript || {
33     init : function(params) {
34         var click = function(e, elementid) {
35             e.preventDefault();
36             if (!M.editor_atto.is_active(elementid)) {
37                 M.editor_atto.focus(elementid);
38             }
39             document.execCommand('superscript', false, null);
40             // Clean the YUI ids from the HTML.
41             M.editor_atto.text_updated(elementid);
42         };
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');
53             } else {
54                 M.editor_atto.remove_widget_highlight(e.elementid, 'sup');
55             }
56         });
57     }