Path: blob/trunk/third_party/closure/goog/editor/contenteditablefield.js
2868 views
// Copyright 2012 The Closure Library Authors. All Rights Reserved.1//2// Licensed under the Apache License, Version 2.0 (the "License");3// you may not use this file except in compliance with the License.4// You may obtain a copy of the License at5//6// http://www.apache.org/licenses/LICENSE-2.07//8// Unless required by applicable law or agreed to in writing, software9// distributed under the License is distributed on an "AS-IS" BASIS,10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.1314/**15* @fileoverview Class to encapsulate an editable field that blends into the16* style of the page and never uses an iframe. The field's height can be17* controlled by CSS styles like min-height, max-height, and overflow. This is18* a goog.editor.Field, but overrides everything iframe related to use19* contentEditable divs. This is essentially a much lighter alternative to20* goog.editor.SeamlessField, but only works in Firefox 3+, and only works21* *well* in Firefox 12+ due to22* https://bugzilla.mozilla.org/show_bug.cgi?id=669026.23*24* @author [email protected] (Garrett Boyer)25* @author [email protected] (Nick Santos)26*/272829goog.provide('goog.editor.ContentEditableField');3031goog.require('goog.asserts');32goog.require('goog.editor.Field');33goog.require('goog.log');34353637/**38* This class encapsulates an editable field that is just a contentEditable39* div.40*41* To see events fired by this object, please see the base class.42*43* @param {string} id An identifer for the field. This is used to find the44* field and the element associated with this field.45* @param {Document=} opt_doc The document that the element with the given46* id can be found in.47* @constructor48* @extends {goog.editor.Field}49*/50goog.editor.ContentEditableField = function(id, opt_doc) {51goog.editor.Field.call(this, id, opt_doc);52};53goog.inherits(goog.editor.ContentEditableField, goog.editor.Field);545556/**57* @override58*/59goog.editor.ContentEditableField.prototype.logger =60goog.log.getLogger('goog.editor.ContentEditableField');616263/** @override */64goog.editor.ContentEditableField.prototype.usesIframe = function() {65// Never uses an iframe in any browser.66return false;67};686970// Overridden to improve dead code elimination only.71/** @override */72goog.editor.ContentEditableField.prototype.turnOnDesignModeGecko =73goog.nullFunction;747576/** @override */77goog.editor.ContentEditableField.prototype.installStyles = function() {78goog.asserts.assert(79!this.cssStyles, 'ContentEditableField does not support' +80' CSS styles; instead just write plain old CSS on the main page.');81};828384/** @override */85goog.editor.ContentEditableField.prototype.makeEditableInternal = function(86opt_iframeSrc) {87var field = this.getOriginalElement();88if (field) {89this.setupFieldObject(field);90// TODO(gboyer): Allow clients/plugins to override with 'plaintext-only'91// for WebKit.92field.contentEditable = true;9394this.injectContents(field.innerHTML, field);9596this.handleFieldLoad();97}98};99100101/**102* @override103*104* ContentEditableField does not make any changes to the DOM when it is made105* editable other than setting contentEditable to true.106*/107goog.editor.ContentEditableField.prototype.restoreDom = goog.nullFunction;108109110