linkshortcutplugin.js 1.7 KB

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