Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/third_party/closure/goog/editor/contenteditablefield.js
2868 views
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, 'ContentEditableField does not support' +
81
' CSS styles; instead just write plain old CSS on the main page.');
82
};
83
84
85
/** @override */
86
goog.editor.ContentEditableField.prototype.makeEditableInternal = function(
87
opt_iframeSrc) {
88
var field = this.getOriginalElement();
89
if (field) {
90
this.setupFieldObject(field);
91
// TODO(gboyer): Allow clients/plugins to override with 'plaintext-only'
92
// for WebKit.
93
field.contentEditable = true;
94
95
this.injectContents(field.innerHTML, field);
96
97
this.handleFieldLoad();
98
}
99
};
100
101
102
/**
103
* @override
104
*
105
* ContentEditableField does not make any changes to the DOM when it is made
106
* editable other than setting contentEditable to true.
107
*/
108
goog.editor.ContentEditableField.prototype.restoreDom = goog.nullFunction;
109
110