Debian Codegraph @

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

raw
1 // Copyright 2011 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 Adds a keyboard shortcut for the link command.
17 *
18 */
19
20 goog.provide('goog.editor.plugins.LinkShortcutPlugin');
21
22 goog.require('goog.editor.Command');
23 goog.require('goog.editor.Plugin');
24
25
26
27 /**
28 * Plugin to add a keyboard shortcut for the link command
29 * @constructor
30 * @extends {goog.editor.Plugin}
31 * @final
32 */
33 goog.editor.plugins.LinkShortcutPlugin = function() {
34 goog.editor.plugins.LinkShortcutPlugin.base(this, 'constructor');
35 };
36 goog.inherits(goog.editor.plugins.LinkShortcutPlugin, goog.editor.Plugin);
37
38
39 /** @override */
40 goog.editor.plugins.LinkShortcutPlugin.prototype.getTrogClassId = function() {
41 return 'LinkShortcutPlugin';
42 };
43
44
45 /**
46 * @override
47 */
48 goog.editor.plugins.LinkShortcutPlugin.prototype.handleKeyboardShortcut =
49 function(e, key, isModifierPressed) {
50 if (isModifierPressed && key == 'k' && !e.shiftKey) {
51 var link = /** @type {goog.editor.Link?} */ (
52 this.getFieldObject().execCommand(goog.editor.Command.LINK));
53 if (link) {
54 link.finishLinkCreation(this.getFieldObject());
55 }
56 return true;
57 }
58
59 return false;
60 };