Debian Codegraph @

closure-library/closure/goog/editor/plugins/headerformatter.js

raw
1 // Copyright 2008 The Closure Library Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS-IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 /**
16 * @fileoverview Handles applying header styles to text.
17 *
18 */
19
20 goog.provide('goog.editor.plugins.HeaderFormatter');
21
22 goog.require('goog.editor.Command');
23 goog.require('goog.editor.Plugin');
24 goog.require('goog.userAgent');
25
26
27
28 /**
29 * Applies header styles to text.
30 * @constructor
31 * @extends {goog.editor.Plugin}
32 * @final
33 */
34 goog.editor.plugins.HeaderFormatter = function() {
35 goog.editor.Plugin.call(this);
36 };
37 goog.inherits(goog.editor.plugins.HeaderFormatter, goog.editor.Plugin);
38
39
40 /** @override */
41 goog.editor.plugins.HeaderFormatter.prototype.getTrogClassId = function() {
42 return 'HeaderFormatter';
43 };
44
45 // TODO(user): Move execCommand functionality from basictextformatter into
46 // here for headers. I'm not doing this now because it depends on the
47 // switch statements in basictextformatter and we'll need to abstract that out
48 // in order to separate out any of the functions from basictextformatter.
49
50
51 /**
52 * Commands that can be passed as the optional argument to execCommand.
53 * @enum {string}
54 */
55 goog.editor.plugins.HeaderFormatter.HEADER_COMMAND = {
56 H1: 'H1',
57 H2: 'H2',
58 H3: 'H3',
59 H4: 'H4'
60 };
61
62
63 /**
64 * @override
65 */
66 goog.editor.plugins.HeaderFormatter.prototype.handleKeyboardShortcut = function(
67 e, key, isModifierPressed) {
68 if (!isModifierPressed) {
69 return false;
70 }
71 var command = null;
72 switch (key) {
73 case '1':
74 command = goog.editor.plugins.HeaderFormatter.HEADER_COMMAND.H1;
75 break;
76 case '2':
77 command = goog.editor.plugins.HeaderFormatter.HEADER_COMMAND.H2;
78 break;
79 case '3':
80 command = goog.editor.plugins.HeaderFormatter.HEADER_COMMAND.H3;
81 break;
82 case '4':
83 command = goog.editor.plugins.HeaderFormatter.HEADER_COMMAND.H4;
84 break;
85 }
86 if (command) {
87 this.getFieldObject().execCommand(
88 goog.editor.Command.FORMAT_BLOCK, command);
89 // Prevent default isn't enough to cancel tab navigation in FF.
90 if (goog.userAgent.GECKO) {
91 e.stopPropagation();
92 }
93 return true;
94 }
95 return false;
96 };