MDL-41235 fix whitespace
[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) {
25 var click_h1 = function(e, elementid) {
26 e.preventDefault();
27 if (!M.editor_atto.is_active(elementid)) {
28 M.editor_atto.focus(elementid);
29 }
30 document.execCommand('formatBlock', false, '<h1>');
31 };
32 var click_h2 = function(e, elementid) {
33 e.preventDefault();
34 if (!M.editor_atto.is_active(elementid)) {
35 M.editor_atto.focus(elementid);
36 }
37 document.execCommand('formatBlock', false, '<h2>');
38 };
39 var click_blockquote = function(e, elementid) {
40 e.preventDefault();
41 if (!M.editor_atto.is_active(elementid)) {
42 M.editor_atto.focus(elementid);
43 }
44 document.execCommand('formatBlock', false, '<blockquote>');
45 };
46 var click_p = function(e, elementid) {
47 e.preventDefault();
48 if (!M.editor_atto.is_active(elementid)) {
49 M.editor_atto.focus(elementid);
50 }
51 document.execCommand('formatBlock', false, '<p>');
52 };
53
54 var h1 = '<h1>' + M.util.get_string('h1', 'atto_title') + '</h1>';
55 var h2 = '<h2>' + M.util.get_string('h2', 'atto_title') + '</h2>';
56 var blockquote = '<p>&nbsp;&nbsp;&nbsp;&nbsp;' + M.util.get_string('blockquote', 'atto_title') + '</p>';
57 var p = '<p>' + M.util.get_string('p', 'atto_title') + '</p>';
58
59 M.editor_atto.add_toolbar_menu(params.elementid,
60 'title',
61 params.icon,
62 [
63 {'text' : h1, 'handler' : click_h1},
64 {'text' : h2, 'handler' : click_h2},
65 {'text' : blockquote, 'handler' : click_blockquote},
66 {'text' : p, 'handler' : click_p}
67 ]);
68 }
69};