| 1 |
// Copyright 2007 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 generic interface for saving and restoring ranges. |
| 17 |
* |
| 18 |
* @author [email protected] (Robby Walker) |
| 19 |
*/ |
| 20 |
|
| 21 |
|
| 22 |
goog.provide('goog.dom.SavedRange'); |
| 23 |
|
| 24 |
goog.require('goog.Disposable'); |
| 25 |
goog.require('goog.log'); |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
/** |
| 30 |
* Abstract interface for a saved range. |
| 31 |
* @constructor |
| 32 |
* @extends {goog.Disposable} |
| 33 |
*/ |
| 34 |
goog.dom.SavedRange = function() { |
| 35 |
goog.Disposable.call(this); |
| 36 |
}; |
| 37 |
goog.inherits(goog.dom.SavedRange, goog.Disposable); |
| 38 |
|
| 39 |
|
| 40 |
/** |
| 41 |
* Logging object. |
| 42 |
* @type {goog.log.Logger} |
| 43 |
* @private |
| 44 |
*/ |
| 45 |
goog.dom.SavedRange.logger_ = goog.log.getLogger('goog.dom.SavedRange'); |
| 46 |
|
| 47 |
|
| 48 |
/** |
| 49 |
* Restores the range and by default disposes of the saved copy. Take note: |
| 50 |
* this means the by default SavedRange objects are single use objects. |
| 51 |
* @param {boolean=} opt_stayAlive Whether this SavedRange should stay alive |
| 52 |
* (not be disposed) after restoring the range. Defaults to false (dispose). |
| 53 |
* @return {goog.dom.AbstractRange} The restored range. |
| 54 |
*/ |
| 55 |
goog.dom.SavedRange.prototype.restore = function(opt_stayAlive) { |
| 56 |
if (this.isDisposed()) { |
| 57 |
goog.log.error( |
| 58 |
goog.dom.SavedRange.logger_, |
| 59 |
'Disposed SavedRange objects cannot be restored.'); |
| 60 |
} |
| 61 |
|
| 62 |
var range = this.restoreInternal(); |
| 63 |
if (!opt_stayAlive) { |
| 64 |
this.dispose(); |
| 65 |
} |
| 66 |
return range; |
| 67 |
}; |
| 68 |
|
| 69 |
|
| 70 |
/** |
| 71 |
* Internal method to restore the saved range. |
| 72 |
* @return {goog.dom.AbstractRange} The restored range. |
| 73 |
*/ |
| 74 |
goog.dom.SavedRange.prototype.restoreInternal = goog.abstractMethod; |