MDL-44128 Atto: fix keyboard navigation for the dropdowns
[moodle.git] / lib / editor / atto / plugins / italic / yui / build / moodle-atto_italic-button / moodle-atto_italic-button-debug.js
blob5c095951e0fec98b62158dd168a9d1f3738653eb
1 YUI.add('moodle-atto_italic-button', function (Y, NAME) {
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.
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/>.
18 /**
19  * Selectors.
20  *
21  * @type {Object}
22  */
23 var SELECTORS = {
24     TAGS : 'i'
27 /**
28  * Atto text editor italic plugin.
29  *
30  * @package    editor-atto
31  * @copyright  2013 Damyon Wiese  <damyon@moodle.com>
32  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
33  */
34 M.atto_italic = M.atto_italic || {
35     init : function(params) {
36         var click = function(e, elementid) {
37             e.preventDefault();
38             if (!M.editor_atto.is_active(elementid)) {
39                 M.editor_atto.focus(elementid);
40             }
41             document.execCommand('italic', false, null);
42             // Clean the YUI ids from the HTML.
43             M.editor_atto.text_updated(elementid);
44         };
46         var iconurl = M.util.image_url('e/italic', 'core');
47         M.editor_atto.add_toolbar_button(params.elementid, 'italic', iconurl, params.group, click);
48         M.editor_atto.add_button_shortcut({action: 'italic', keys: 73});
50         // Attach an event listner to watch for "changes" in the contenteditable.
51         // This includes cursor changes, we check if the button should be active or not, based
52         // on the text selection.
53         M.editor_atto.on('atto:selectionchanged', function(e) {
54             if (M.editor_atto.selection_filter_matches(e.elementid, SELECTORS.TAGS, e.selectedNodes)) {
55                 M.editor_atto.add_widget_highlight(e.elementid, 'italic');
56             } else {
57                 M.editor_atto.remove_widget_highlight(e.elementid, 'italic');
58             }
59         });
60     }
64 }, '@VERSION@', {"requires": ["node", "moodle-editor_atto-editor-shortcut"]});