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