| 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_backcolor
|
|
|
18 |
* @copyright 2014 Rossiani Wijaya <rwijaya@moodle.com>
|
|
|
19 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
20 |
*/
|
|
|
21 |
|
|
|
22 |
/**
|
|
|
23 |
* @module moodle-atto_backcolor-button
|
|
|
24 |
*/
|
|
|
25 |
|
|
|
26 |
/**
|
|
|
27 |
* Atto text editor backcolor plugin.
|
|
|
28 |
*
|
|
|
29 |
* @namespace M.atto_backcolor
|
|
|
30 |
* @class button
|
|
|
31 |
* @extends M.editor_atto.EditorPlugin
|
|
|
32 |
*/
|
|
|
33 |
|
|
|
34 |
var colors = [
|
|
|
35 |
{
|
|
|
36 |
name: 'white',
|
|
|
37 |
color: '#FFFFFF'
|
|
|
38 |
}, {
|
|
|
39 |
name: 'red',
|
|
|
40 |
color: '#EF4540'
|
|
|
41 |
}, {
|
|
|
42 |
name: 'yellow',
|
|
|
43 |
color: '#FFCF35'
|
|
|
44 |
}, {
|
|
|
45 |
name: 'green',
|
|
|
46 |
color: '#98CA3E'
|
|
|
47 |
}, {
|
|
|
48 |
name: 'blue',
|
|
|
49 |
color: '#7D9FD3'
|
|
|
50 |
}, {
|
|
|
51 |
name: 'black',
|
|
|
52 |
color: '#333333'
|
|
|
53 |
}
|
|
|
54 |
];
|
|
|
55 |
|
|
|
56 |
Y.namespace('M.atto_backcolor').Button = Y.Base.create('button', Y.M.editor_atto.EditorPlugin, [], {
|
|
|
57 |
initializer: function() {
|
|
|
58 |
var items = [];
|
|
|
59 |
Y.Array.each(colors, function(color) {
|
|
|
60 |
var colorLabel = M.util.get_string('color_' + color.name, 'atto_backcolor');
|
|
|
61 |
items.push({
|
|
|
62 |
text: '<div class="coloroption" style="background-color: '
|
|
|
63 |
+ color.color + '" aria-label="' + colorLabel + '" title="' + colorLabel + '"></div>',
|
|
|
64 |
callbackArgs: color.color
|
|
|
65 |
});
|
|
|
66 |
});
|
|
|
67 |
|
|
|
68 |
this.addToolbarMenu({
|
|
|
69 |
icon: 'e/text_highlight',
|
|
|
70 |
overlayWidth: '4',
|
|
|
71 |
globalItemConfig: {
|
|
|
72 |
inlineFormat: true,
|
|
|
73 |
callback: this._changeStyle
|
|
|
74 |
},
|
|
|
75 |
items: items
|
|
|
76 |
});
|
|
|
77 |
},
|
|
|
78 |
|
|
|
79 |
/**
|
|
|
80 |
* Change the background color to the specified color.
|
|
|
81 |
*
|
|
|
82 |
* @method _changeStyle
|
|
|
83 |
* @param {EventFacade} e
|
|
|
84 |
* @param {string} color The new background color
|
|
|
85 |
* @private
|
|
|
86 |
*/
|
|
|
87 |
_changeStyle: function(e, color) {
|
|
|
88 |
this.get('host').formatSelectionInlineStyle({
|
|
|
89 |
backgroundColor: color
|
|
|
90 |
});
|
|
|
91 |
}
|
|
|
92 |
});
|