MDL-41237 Atto - Adjusting the text styles for the editor
[moodle.git] / lib / editor / atto / plugins / title / yui / src / button / js / button.js
CommitLineData
c90641fa
DW
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 * Atto text editor title plugin.
18 *
19 * @package editor-atto
20 * @copyright 2013 Damyon Wiese <damyon@moodle.com>
21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22 */
23M.atto_title = M.atto_title || {
24 init : function(params) {
2b636130
JF
25 var click_h3 = function(e, elementid) {
26 M.atto_title.change_title(e, elementid, '<h3>');
c90641fa 27 };
2b636130
JF
28 var click_h4 = function(e, elementid) {
29 M.atto_title.change_title(e, elementid, '<h4>');
30 };
31 var click_h5 = function(e, elementid) {
32 M.atto_title.change_title(e, elementid, '<h5>');
33 };
34 var click_pre = function(e, elementid) {
35 M.atto_title.change_title(e, elementid, '<pre>');
c90641fa
DW
36 };
37 var click_blockquote = function(e, elementid) {
2b636130 38 M.atto_title.change_title(e, elementid, '<blockquote>');
c90641fa
DW
39 };
40 var click_p = function(e, elementid) {
2b636130 41 M.atto_title.change_title(e, elementid, '<p>');
c90641fa
DW
42 };
43
2b636130
JF
44 var h3 = '<h3>' + M.util.get_string('h3', 'atto_title') + '</h3>';
45 var h4 = '<h4>' + M.util.get_string('h4', 'atto_title') + '</h4>';
46 var h5 = '<h5>' + M.util.get_string('h5', 'atto_title') + '</h5>';
47 var pre = '<pre>' + M.util.get_string('pre', 'atto_title') + '</pre>';
48 var blockquote = '<p>&nbsp;&nbsp;&nbsp;&nbsp;' + M.util.get_string('blockquote', 'atto_title') + '</p>';
49 var p = '<p>' + M.util.get_string('p', 'atto_title') + '</p>';
c90641fa
DW
50
51 M.editor_atto.add_toolbar_menu(params.elementid,
52 'title',
53 params.icon,
54 [
2b636130
JF
55 {'text' : h3, 'handler' : click_h3},
56 {'text' : h4, 'handler' : click_h4},
57 {'text' : h5, 'handler' : click_h5},
58 {'text' : pre, 'handler' : click_pre},
c90641fa
DW
59 {'text' : blockquote, 'handler' : click_blockquote},
60 {'text' : p, 'handler' : click_p}
61 ]);
2b636130
JF
62 },
63
64 change_title : function(e, elementid, node) {
65 e.preventDefault();
66 if (!M.editor_atto.is_active(elementid)) {
67 M.editor_atto.focus(elementid);
68 }
69 document.execCommand('formatBlock', false, node);
c90641fa
DW
70 }
71};
2b636130 72