PageRenderTime 71ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/js/closure-library/closure/goog/demos/editor/helloworld.js

https://gitlab.com/gregtyka/napster.fm
JavaScript | 81 lines | 27 code | 14 blank | 40 comment | 1 complexity | 905e80931f1eeecdf18cfab25ec7e870 MD5 | raw file
  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. * @fileoverview A simple plugin that inserts 'Hello World!' on command. This
  16. * plugin is intended to be an example of a very simple plugin for plugin
  17. * developers.
  18. *
  19. * @author gak@google.com (Gregory Kick)
  20. * @see helloworld.html
  21. */
  22. goog.provide('goog.demos.editor.HelloWorld');
  23. goog.require('goog.dom');
  24. goog.require('goog.dom.TagName');
  25. goog.require('goog.editor.Plugin');
  26. /**
  27. * Plugin to insert 'Hello World!' into an editable field.
  28. * @constructor
  29. * @extends {goog.editor.Plugin}
  30. */
  31. goog.demos.editor.HelloWorld = function() {
  32. goog.editor.Plugin.call(this);
  33. };
  34. goog.inherits(goog.demos.editor.HelloWorld, goog.editor.Plugin);
  35. /** @override */
  36. goog.demos.editor.HelloWorld.prototype.getTrogClassId = function() {
  37. return 'HelloWorld';
  38. };
  39. /**
  40. * Commands implemented by this plugin.
  41. * @enum {string}
  42. */
  43. goog.demos.editor.HelloWorld.COMMAND = {
  44. HELLO_WORLD: '+helloWorld'
  45. };
  46. /** @override */
  47. goog.demos.editor.HelloWorld.prototype.isSupportedCommand = function(
  48. command) {
  49. return command == goog.demos.editor.HelloWorld.COMMAND.HELLO_WORLD;
  50. };
  51. /**
  52. * Executes a command. Does not fire any BEFORECHANGE, CHANGE, or
  53. * SELECTIONCHANGE events (these are handled by the super class implementation
  54. * of {@code execCommand}.
  55. * @param {string} command Command to execute.
  56. * @override
  57. * @protected
  58. */
  59. goog.demos.editor.HelloWorld.prototype.execCommandInternal = function(
  60. command) {
  61. var domHelper = this.getFieldObject().getEditableDomHelper();
  62. var range = this.getFieldObject().getRange();
  63. range.removeContents();
  64. var newNode =
  65. domHelper.createDom(goog.dom.TagName.SPAN, null, 'Hello World!');
  66. range.insertNode(newNode, false);
  67. };