Debian Codegraph @

closure-library/closure/goog/editor/contenteditablefield.js

raw
1 // Copyright 2012 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 Class to encapsulate an editable field that blends into the
17 * style of the page and never uses an iframe. The field's height can be
18 * controlled by CSS styles like min-height, max-height, and overflow. This is
19 * a goog.editor.Field, but overrides everything iframe related to use
20 * contentEditable divs. This is essentially a much lighter alternative to
21 * goog.editor.SeamlessField, but only works in Firefox 3+, and only works
22 * *well* in Firefox 12+ due to
23 * https://bugzilla.mozilla.org/show_bug.cgi?id=669026.
24 *
25 * @author [email protected] (Garrett Boyer)
26 * @author [email protected] (Nick Santos)
27 */
28
29
30 goog.provide('goog.editor.ContentEditableField');
31
32 goog.require('goog.asserts');
33 goog.require('goog.editor.Field');
34 goog.require('goog.log');
35
36
37
38 /**
39 * This class encapsulates an editable field that is just a contentEditable
40 * div.
41 *
42 * To see events fired by this object, please see the base class.
43 *
44 * @param {string} id An identifer for the field. This is used to find the
45 * field and the element associated with this field.
46 * @param {Document=} opt_doc The document that the element with the given
47 * id can be found in.
48 * @constructor
49 * @extends {goog.editor.Field}
50 */
51 goog.editor.ContentEditableField = function(id, opt_doc) {
52 goog.editor.Field.call(this, id, opt_doc);
53 };
54 goog.inherits(goog.editor.ContentEditableField, goog.editor.Field);
55
56
57 /**
58 * @override
59 */
60 goog.editor.ContentEditableField.prototype.logger =
61 goog.log.getLogger('goog.editor.ContentEditableField');
62
63
64 /** @override */
65 goog.editor.ContentEditableField.prototype.usesIframe = function() {
66 // Never uses an iframe in any browser.
67 return false;
68 };
69
70
71 // Overridden to improve dead code elimination only.
72 /** @override */
73 goog.editor.ContentEditableField.prototype.turnOnDesignModeGecko =
74 goog.nullFunction;
75
76
77 /** @override */
78 goog.editor.ContentEditableField.prototype.installStyles = function() {
79 goog.asserts.assert(
80 !this.cssStyles.getTypedStringValue(),
81 'ContentEditableField does not support CSS styles; instead just write ' +
82 'plain old CSS on the main page.');
83 };
84
85
86 /** @override */
87 goog.editor.ContentEditableField.prototype.makeEditableInternal = function(
88 opt_iframeSrc) {
89 var field = this.getOriginalElement();
90 if (field) {
91 this.setupFieldObject(field);
92 // TODO(gboyer): Allow clients/plugins to override with 'plaintext-only'
93 // for WebKit.
94 field.contentEditable = true;
95
96 this.injectContents(field.innerHTML, field);
97
98 this.handleFieldLoad();
99 }
100 };
101
102
103 /**
104 * @override
105 *
106 * ContentEditableField does not make any changes to the DOM when it is made
107 * editable other than setting contentEditable to true.
108 */
109 goog.editor.ContentEditableField.prototype.restoreDom = goog.nullFunction;