4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-util-Memento'>/**
19 </span> * @class Ext.util.Memento
20 * This class manages a set of captured properties from an object. These captured properties
21 * can later be restored to an object.
23 Ext.define('Ext.util.Memento', function () {
25 function captureOne (src, target, prop) {
26 src[prop] = target[prop];
29 function removeOne (src, target, prop) {
33 function restoreOne (src, target, prop) {
34 var value = src[prop];
35 if (value || src.hasOwnProperty(prop)) {
36 restoreValue(target, prop, value);
40 function restoreValue (target, prop, value) {
41 if (Ext.isDefined(value)) {
48 function doMany (doOne, src, target, props) {
50 if (Ext.isArray(props)) {
51 Ext.each(props, function (prop) {
52 doOne(src, target, prop);
55 doOne(src, target, props);
61 <span id='Ext-util-Memento-property-data'> /**
62 </span> * @property data
63 * The collection of captured properties.
68 <span id='Ext-util-Memento-property-target'> /**
69 </span> * @property target
70 * The default target object for capture/restore (passed to the constructor).
74 <span id='Ext-util-Memento-method-constructor'> /**
75 </span> * Creates a new memento and optionally captures properties from the target object.
76 * @param {Object} target The target from which to capture properties. If specified in the
77 * constructor, this target becomes the default target for all other operations.
78 * @param {String|Array} props The property or array of properties to capture.
80 constructor: function (target, props) {
89 <span id='Ext-util-Memento-method-capture'> /**
90 </span> * Captures the specified properties from the target object in this memento.
91 * @param {String|Array} props The property or array of properties to capture.
92 * @param {Object} target The object from which to capture properties.
94 capture: function (props, target) {
95 doMany(captureOne, this.data || (this.data = {}), target || this.target, props);
98 <span id='Ext-util-Memento-method-remove'> /**
99 </span> * Removes the specified properties from this memento. These properties will not be
100 * restored later without re-capturing their values.
101 * @param {String|Array} props The property or array of properties to remove.
103 remove: function (props) {
104 doMany(removeOne, this.data, null, props);
107 <span id='Ext-util-Memento-method-restore'> /**
108 </span> * Restores the specified properties from this memento to the target object.
109 * @param {String|Array} props The property or array of properties to restore.
110 * @param {Boolean} clear True to remove the restored properties from this memento or
111 * false to keep them (default is true).
112 * @param {Object} target The object to which to restore properties.
114 restore: function (props, clear, target) {
115 doMany(restoreOne, this.data, target || this.target, props);
116 if (clear !== false) {
121 <span id='Ext-util-Memento-method-restoreAll'> /**
122 </span> * Restores all captured properties in this memento to the target object.
123 * @param {Boolean} clear True to remove the restored properties from this memento or
124 * false to keep them (default is true).
125 * @param {Object} target The object to which to restore properties.
127 restoreAll: function (clear, target) {
129 t = target || this.target;
131 Ext.Object.each(me.data, function (prop, value) {
132 restoreValue(t, prop, value);
135 if (clear !== false) {