Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
// This file is part of Moodle - http://moodle.org/
2
//
3
// Moodle is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, either version 3 of the License, or
6
// (at your option) any later version.
7
//
8
// Moodle is distributed in the hope that it will be useful,
9
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
// GNU General Public License for more details.
12
//
13
// You should have received a copy of the GNU General Public License
14
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
15
 
16
/*
17
 * @package    atto_align
18
 * @copyright  2014 Frédéric Massart
19
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
20
 */
21
 
22
/**
23
 * @module moodle-atto_align-button
24
 */
25
 
26
/**
27
 * Atto text editor align plugin.
28
 *
29
 * @namespace M.atto_align
30
 * @class button
31
 * @extends M.editor_atto.EditorPlugin
32
 */
33
 
34
Y.namespace('M.atto_align').Button = Y.Base.create('button', Y.M.editor_atto.EditorPlugin, [], {
35
    initializer: function() {
36
        var alignment;
37
 
38
        alignment = 'justifyLeft';
39
        this.addButton({
40
            icon: 'e/align_left',
41
            title: 'leftalign',
42
            buttonName: alignment,
43
            callback: this._changeStyle,
44
            callbackArgs: alignment
45
        });
46
 
47
        alignment = 'justifyCenter';
48
        this.addButton({
49
            icon: 'e/align_center',
50
            title: 'center',
51
            buttonName: alignment,
52
            callback: this._changeStyle,
53
            callbackArgs: alignment
54
        });
55
 
56
        alignment = 'justifyRight';
57
        this.addButton({
58
            icon: 'e/align_right',
59
            title: 'rightalign',
60
            buttonName: alignment,
61
            callback: this._changeStyle,
62
            callbackArgs: alignment
63
        });
64
    },
65
 
66
 
67
    /**
68
     * Change the alignment to the specified justification.
69
     *
70
     * @method _changeStyle
71
     * @param {EventFacade} e
72
     * @param {string} justification The execCommand for the new justification.
73
     * @private
74
     */
75
    _changeStyle: function(e, justification) {
76
        var host = this.get('host');
77
 
78
        // We temporarily re-enable CSS styling to try to have the most consistency.
79
        // Though, IE, as always, is stubborn and will do its own thing...
80
        host.enableCssStyling();
81
 
82
        document.execCommand(justification, false, null);
83
 
84
        // To clean up IE's mess.
85
        this.editor.all('*[align]').each(function(node) {
86
            var align = node.get('align');
87
            if (align) {
88
                node.setStyle('text-align', align);
89
                node.removeAttribute('align');
90
            }
91
        }, this);
92
 
93
        // Re-disable the CSS styling after making the change.
94
        host.disableCssStyling();
95
 
96
        // Mark the text as having been updated.
97
        this.markUpdated();
98
 
99
        this.editor.focus();
100
    }
101
});