1 YUI.add('moodle-atto_italic-button', function (Y, NAME) {
3 // This file is part of Moodle - http://moodle.org/
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.
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/>.
28 * Atto text editor italic plugin.
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
34 M.atto_italic = M.atto_italic || {
35 init : function(params) {
36 var click = function(e, elementid) {
38 if (!M.editor_atto.is_active(elementid)) {
39 M.editor_atto.focus(elementid);
41 document.execCommand('italic', false, null);
42 // Clean the YUI ids from the HTML.
43 M.editor_atto.text_updated(elementid);
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');
57 M.editor_atto.remove_widget_highlight(e.elementid, 'italic');
64 }, '@VERSION@', {"requires": ["node", "moodle-editor_atto-editor-shortcut"]});