3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.3.0
11 * Copyright(c) 2006-2010 Ext JS, Inc.
13 * http://www.extjs.com/license
15 <div id="cls-Ext.Editor"></div>/**
17 * @extends Ext.Component
18 * A base editor field that handles displaying/hiding on demand and has some built-in sizing and event handling logic.
21 * @param {Object} config The config object
24 Ext.Editor = function(field, config){
26 this.field = Ext.create(field.field, 'textfield');
27 config = Ext.apply({}, field); // copy so we don't disturb original config
32 Ext.Editor.superclass.constructor.call(this, config);
35 Ext.extend(Ext.Editor, Ext.Component, {
36 <div id="cfg-Ext.Editor-field"></div>/**
37 * @cfg {Ext.form.Field} field
38 * The Field object (or descendant) or config object for field
40 <div id="cfg-Ext.Editor-allowBlur"></div>/**
41 * @cfg {Boolean} allowBlur
42 * True to {@link #completeEdit complete the editing process} if in edit mode when the
43 * field is blurred. Defaults to <tt>true</tt>.
46 <div id="cfg-Ext.Editor-autoSize"></div>/**
47 * @cfg {Boolean/String} autoSize
48 * True for the editor to automatically adopt the size of the underlying field, "width" to adopt the width only,
49 * or "height" to adopt the height only, "none" to always use the field dimensions. (defaults to false)
51 <div id="cfg-Ext.Editor-revertInvalid"></div>/**
52 * @cfg {Boolean} revertInvalid
53 * True to automatically revert the field value and cancel the edit when the user completes an edit and the field
54 * validation fails (defaults to true)
56 <div id="cfg-Ext.Editor-ignoreNoChange"></div>/**
57 * @cfg {Boolean} ignoreNoChange
58 * True to skip the edit completion process (no save, no events fired) if the user completes an edit and
59 * the value has not changed (defaults to false). Applies only to string values - edits for other data types
60 * will never be ignored.
62 <div id="cfg-Ext.Editor-hideEl"></div>/**
63 * @cfg {Boolean} hideEl
64 * False to keep the bound element visible while the editor is displayed (defaults to true)
66 <div id="cfg-Ext.Editor-value"></div>/**
68 * The data value of the underlying field (defaults to "")
71 <div id="cfg-Ext.Editor-alignment"></div>/**
72 * @cfg {String} alignment
73 * The position to align to (see {@link Ext.Element#alignTo} for more details, defaults to "c-c?").
76 <div id="cfg-Ext.Editor-offsets"></div>/**
77 * @cfg {Array} offsets
78 * The offsets to use when aligning (see {@link Ext.Element#alignTo} for more details. Defaults to <tt>[0, 0]</tt>.
81 <div id="cfg-Ext.Editor-shadow"></div>/**
82 * @cfg {Boolean/String} shadow "sides" for sides/bottom only, "frame" for 4-way shadow, and "drop"
83 * for bottom-right shadow (defaults to "frame")
86 <div id="cfg-Ext.Editor-constrain"></div>/**
87 * @cfg {Boolean} constrain True to constrain the editor to the viewport
90 <div id="cfg-Ext.Editor-swallowKeys"></div>/**
91 * @cfg {Boolean} swallowKeys Handle the keydown/keypress events so they don't propagate (defaults to true)
94 <div id="cfg-Ext.Editor-completeOnEnter"></div>/**
95 * @cfg {Boolean} completeOnEnter True to complete the edit when the enter key is pressed. Defaults to <tt>true</tt>.
97 completeOnEnter : true,
98 <div id="cfg-Ext.Editor-cancelOnEsc"></div>/**
99 * @cfg {Boolean} cancelOnEsc True to cancel the edit when the escape key is pressed. Defaults to <tt>true</tt>.
102 <div id="cfg-Ext.Editor-updateEl"></div>/**
103 * @cfg {Boolean} updateEl True to update the innerHTML of the bound element when the update completes (defaults to false)
107 initComponent : function(){
108 Ext.Editor.superclass.initComponent.call(this);
110 <div id="event-Ext.Editor-beforestartedit"></div>/**
111 * @event beforestartedit
112 * Fires when editing is initiated, but before the value changes. Editing can be canceled by returning
113 * false from the handler of this event.
114 * @param {Editor} this
115 * @param {Ext.Element} boundEl The underlying element bound to this editor
116 * @param {Mixed} value The field value being set
119 <div id="event-Ext.Editor-startedit"></div>/**
121 * Fires when this editor is displayed
122 * @param {Ext.Element} boundEl The underlying element bound to this editor
123 * @param {Mixed} value The starting field value
126 <div id="event-Ext.Editor-beforecomplete"></div>/**
127 * @event beforecomplete
128 * Fires after a change has been made to the field, but before the change is reflected in the underlying
129 * field. Saving the change to the field can be canceled by returning false from the handler of this event.
130 * Note that if the value has not changed and ignoreNoChange = true, the editing will still end but this
131 * event will not fire since no edit actually occurred.
132 * @param {Editor} this
133 * @param {Mixed} value The current field value
134 * @param {Mixed} startValue The original field value
137 <div id="event-Ext.Editor-complete"></div>/**
139 * Fires after editing is complete and any changed value has been written to the underlying field.
140 * @param {Editor} this
141 * @param {Mixed} value The current field value
142 * @param {Mixed} startValue The original field value
145 <div id="event-Ext.Editor-canceledit"></div>/**
147 * Fires after editing has been canceled and the editor's value has been reset.
148 * @param {Editor} this
149 * @param {Mixed} value The user-entered field value that was discarded
150 * @param {Mixed} startValue The original field value that was set back into the editor after cancel
153 <div id="event-Ext.Editor-specialkey"></div>/**
155 * Fires when any key related to navigation (arrows, tab, enter, esc, etc.) is pressed. You can check
156 * {@link Ext.EventObject#getKey} to determine which key was pressed.
157 * @param {Ext.form.Field} this
158 * @param {Ext.EventObject} e The event object
165 onRender : function(ct, position){
166 this.el = new Ext.Layer({
171 shadowOffset: this.shadowOffset || 4,
173 constrain: this.constrain
176 this.el.setZIndex(this.zIndex);
178 this.el.setStyle("overflow", Ext.isGecko ? "auto" : "hidden");
179 if(this.field.msgTarget != 'title'){
180 this.field.msgTarget = 'qtip';
182 this.field.inEditor = true;
183 this.mon(this.field, {
186 specialkey: this.onSpecialKey
189 this.mon(this.field, "autosize", this.el.sync, this.el, {delay:1});
191 this.field.render(this.el).show();
192 this.field.getEl().dom.name = '';
193 if(this.swallowKeys){
194 this.field.el.swallowEvent([
195 'keypress', // *** Opera
196 'keydown' // *** all other browsers
202 onSpecialKey : function(field, e){
203 var key = e.getKey(),
204 complete = this.completeOnEnter && key == e.ENTER,
205 cancel = this.cancelOnEsc && key == e.ESC;
206 if(complete || cancel){
213 if(field.triggerBlur){
217 this.fireEvent('specialkey', field, e);
220 <div id="method-Ext.Editor-startEdit"></div>/**
221 * Starts the editing process and shows the editor.
222 * @param {Mixed} el The element to edit
223 * @param {String} value (optional) A value to initialize the editor with. If a value is not provided, it defaults
224 * to the innerHTML of el.
226 startEdit : function(el, value){
230 this.boundEl = Ext.get(el);
231 var v = value !== undefined ? value : this.boundEl.dom.innerHTML;
233 this.render(this.parentEl || document.body);
235 if(this.fireEvent("beforestartedit", this, this.boundEl, v) !== false){
238 this.field.setValue(v);
246 doAutoSize : function(){
248 var sz = this.boundEl.getSize(),
249 fs = this.field.getSize();
251 switch(this.autoSize){
253 this.setSize(sz.width, fs.height);
256 this.setSize(fs.width, sz.height);
259 this.setSize(fs.width, fs.height);
262 this.setSize(sz.width, sz.height);
267 <div id="method-Ext.Editor-setSize"></div>/**
268 * Sets the height and width of this editor.
269 * @param {Number} width The new width
270 * @param {Number} height The new height
272 setSize : function(w, h){
273 delete this.field.lastSize;
274 this.field.setSize(w, h);
276 // IE7 in strict mode doesn't size properly.
277 if(Ext.isGecko2 || Ext.isOpera || (Ext.isIE7 && Ext.isStrict)){
278 // prevent layer scrollbars
279 this.el.setSize(w, h);
285 <div id="method-Ext.Editor-realign"></div>/**
286 * Realigns the editor to the bound field based on the current alignment config value.
287 * @param {Boolean} autoSize (optional) True to size the field to the dimensions of the bound element.
289 realign : function(autoSize){
290 if(autoSize === true){
293 this.el.alignTo(this.boundEl, this.alignment, this.offsets);
296 <div id="method-Ext.Editor-completeEdit"></div>/**
297 * Ends the editing process, persists the changed value to the underlying field, and hides the editor.
298 * @param {Boolean} remainVisible Override the default behavior and keep the editor visible after edit (defaults to false)
300 completeEdit : function(remainVisible){
304 // Assert combo values first
305 if (this.field.assertValue) {
306 this.field.assertValue();
308 var v = this.getValue();
309 if(!this.field.isValid()){
310 if(this.revertInvalid !== false){
311 this.cancelEdit(remainVisible);
315 if(String(v) === String(this.startValue) && this.ignoreNoChange){
316 this.hideEdit(remainVisible);
319 if(this.fireEvent("beforecomplete", this, v, this.startValue) !== false){
321 if(this.updateEl && this.boundEl){
322 this.boundEl.update(v);
324 this.hideEdit(remainVisible);
325 this.fireEvent("complete", this, v, this.startValue);
332 if(this.hideEl !== false){
335 this.field.show().focus(false, true);
336 this.fireEvent("startedit", this.boundEl, this.startValue);
339 <div id="method-Ext.Editor-cancelEdit"></div>/**
340 * Cancels the editing process and hides the editor without persisting any changes. The field value will be
341 * reverted to the original starting value.
342 * @param {Boolean} remainVisible Override the default behavior and keep the editor visible after
343 * cancel (defaults to false)
345 cancelEdit : function(remainVisible){
347 var v = this.getValue();
348 this.setValue(this.startValue);
349 this.hideEdit(remainVisible);
350 this.fireEvent("canceledit", this, v, this.startValue);
355 hideEdit: function(remainVisible){
356 if(remainVisible !== true){
357 this.editing = false;
364 // selectSameEditor flag allows the same editor to be started without onBlur firing on itself
365 if(this.allowBlur === true && this.editing && this.selectSameEditor !== true){
377 if(this.field.collapse){
378 this.field.collapse();
381 if(this.hideEl !== false){
386 <div id="method-Ext.Editor-setValue"></div>/**
387 * Sets the data value of the editor
388 * @param {Mixed} value Any valid value supported by the underlying field
390 setValue : function(v){
391 this.field.setValue(v);
394 <div id="method-Ext.Editor-getValue"></div>/**
395 * Gets the data value of the editor
396 * @return {Mixed} The data value
398 getValue : function(){
399 return this.field.getValue();
402 beforeDestroy : function(){
403 Ext.destroyMembers(this, 'field');
405 delete this.parentEl;
409 Ext.reg('editor', Ext.Editor);