Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
YUI.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
 * @package    atto_rtl
20
 * @copyright  2014 Jerome Mouneyrac
21
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22
 */
23
 
24
/**
25
 * @module moodle-atto_rtl-button
26
 */
27
 
28
/**
29
 * Atto text editor rtl plugin.
30
 *
31
 * @namespace M.atto_rtl
32
 * @class button
33
 * @extends M.editor_atto.EditorPlugin
34
 */
35
 
36
Y.namespace('M.atto_rtl').Button = Y.Base.create('button', Y.M.editor_atto.EditorPlugin, [], {
37
    initializer: function() {
38
        var direction;
39
 
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
            tags: '[dir=ltr]'
48
        });
49
 
50
        direction = 'rtl';
51
        this.addButton({
52
            icon: 'e/right_to_left',
53
            title: direction,
54
            buttonName: direction,
55
            callback: this._toggleRTL,
56
            callbackArgs: direction,
57
            tags: '[dir=rtl]'
58
        });
59
    },
60
 
61
    /**
62
     * Toggle the RTL/LTR values based on the supplied direction.
63
     *
64
     * @method _toggleRTL
65
     * @param {EventFacade} e
66
     * @param {String} direction
67
     */
68
    _toggleRTL: function(e, direction) {
69
        var host = this.get('host'),
70
            sourceSelection = window.rangy.saveSelection(),
71
            selection = host.getSelection(),
72
            newDirection = {
73
                rtl: 'ltr',
74
                ltr: 'rtl'
75
            },
76
            directionAlignment = {
77
                rtl: 'right',
78
                ltr: 'left'
79
            };
80
        if (selection) {
81
            // Format the selection to be sure it has a tag parent (not the contenteditable).
82
            var parentNode = host.formatSelectionBlock(),
83
                parentDOMNode = parentNode.getDOMNode();
84
 
85
            var currentDirection = parentDOMNode.getAttribute('dir');
86
            if (currentDirection === direction) {
87
                parentDOMNode.setAttribute("dir", newDirection[direction]);
88
                parentDOMNode.style.textAlign = directionAlignment[newDirection[direction]];
89
            } else {
90
                parentDOMNode.setAttribute("dir", direction);
91
                parentDOMNode.style.textAlign = directionAlignment[direction];
92
            }
93
 
94
            // Change selection from the containing paragraph to the original one.
95
            window.rangy.restoreSelection(sourceSelection);
96
            // Mark the text as having been updated.
97
            this.markUpdated();
98
        }
99
    }
100
});
101
 
102
 
103
}, '@VERSION@', {"requires": ["moodle-editor_atto-plugin"]});