MDL-44128 Atto: fix keyboard navigation for the dropdowns
[moodle.git] / lib / editor / atto / plugins / rtl / yui / build / moodle-atto_rtl-button / moodle-atto_rtl-button.js
CommitLineData
fe0d2477
JM
1YUI.add('moodle-atto_rtl-button', function (Y, NAME) {
2
3// This file is part of Moodle - http://moodle.org/
4//
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17
18/**
19 * Atto text editor rtl plugin.
20 *
21 * @package editor_atto
22 * @copyright 2014 Jerome Mouneyrac
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 */
25M.atto_rtl = M.atto_rtl || {
26 init : function(params) {
27 var click = function(e, elementid, direction) {
28 e.preventDefault();
29 if (!M.editor_atto.is_active(elementid)) {
30 M.editor_atto.focus(elementid);
31 }
32
33 M.atto_rtl.selection = M.editor_atto.get_selection();
34 if (M.atto_rtl.selection !== false) {
35
36 // Format the selection to be sure it has a tag parent (not the contenteditable).
37 var parentnode = M.editor_atto.format_selection_block(elementid);
38 parentnodeelement = parentnode.getDOMNode();
39
40 var currentdirection = parentnodeelement.getAttribute("dir");
41 if (currentdirection === direction) {
42 parentnodeelement.removeAttribute("dir");
43 } else {
44 parentnodeelement.setAttribute("dir", direction);
45 }
46 }
47
48 // Clean the YUI ids from the HTML.
49 M.editor_atto.text_updated(elementid);
50 };
51
52 var rtlclick = function(e, elementid) {
53 click(e, elementid, 'rtl');
54 };
55
56 var ltrclick = function(e, elementid) {
57 click(e, elementid, 'ltr');
58 };
59
60 var iconurl = M.util.image_url('e/left_to_right', 'core');
5ec54dd1 61 M.editor_atto.add_toolbar_button(params.elementid, 'rtl', iconurl, params.group, ltrclick, 'ltr', M.util.get_string('ltr', 'atto_rtl'));
fe0d2477
JM
62
63 iconurl = M.util.image_url('e/right_to_left', 'core');
5ec54dd1 64 M.editor_atto.add_toolbar_button(params.elementid, 'rtl', iconurl, params.group, rtlclick, 'rtl', M.util.get_string('rtl', 'atto_rtl'));
fe0d2477
JM
65 }
66};
67
68
69}, '@VERSION@', {"requires": ["node"]});