weekly release 3.0dev
[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
62467795
AN
18/*
19 * @package atto_rtl
fe0d2477
JM
20 * @copyright 2014 Jerome Mouneyrac
21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22 */
fe0d2477 23
62467795
AN
24/**
25 * @module moodle-atto_rtl-button
26 */
fe0d2477 27
62467795
AN
28/**
29 * Atto text editor rtl plugin.
30 *
31 * @namespace M.atto_rtl
32 * @class button
33 * @extends M.editor_atto.EditorPlugin
34 */
fe0d2477 35
62467795
AN
36Y.namespace('M.atto_rtl').Button = Y.Base.create('button', Y.M.editor_atto.EditorPlugin, [], {
37 initializer: function() {
38 var direction;
fe0d2477 39
62467795
AN
40 direction = 'ltr';
41 this.addButton({
42 icon: 'e/left_to_right',
43 title: direction,
44 buttonName: direction,
45 callback: this._toggleRTL,
46 callbackArgs: direction
47 });
fe0d2477 48
62467795
AN
49 direction = 'rtl';
50 this.addButton({
51 icon: 'e/right_to_left',
52 title: direction,
53 buttonName: direction,
54 callback: this._toggleRTL,
55 callbackArgs: direction
56 });
57 },
fe0d2477 58
62467795
AN
59 /**
60 * Toggle the RTL/LTR values based on the supplied direction.
61 *
62 * @method _toggleRTL
63 * @param {EventFacade} e
64 * @param {String} direction
65 */
66 _toggleRTL: function(e, direction) {
67 var host = this.get('host'),
68 selection = host.getSelection();
69 if (selection) {
70 // Format the selection to be sure it has a tag parent (not the contenteditable).
71 var parentNode = host.formatSelectionBlock(),
72 parentDOMNode = parentNode.getDOMNode();
fe0d2477 73
62467795
AN
74 var currentDirection = parentDOMNode.getAttribute('dir');
75 if (currentDirection === direction) {
76 parentDOMNode.removeAttribute("dir");
77 } else {
78 parentDOMNode.setAttribute("dir", direction);
79 }
fe0d2477 80
62467795
AN
81 // Mark the text as having been updated.
82 this.markUpdated();
83 }
fe0d2477 84 }
62467795 85});
fe0d2477
JM
86
87
62467795 88}, '@VERSION@', {"requires": ["moodle-editor_atto-plugin"]});