Cache DomField parent element
* src/ui/field/DomField.js (getParentElement): Renamed from getParent. Cache parent element in memory so that we have a reference for re-attaching fields to the DOM. (getParent): Public API addition; call getParentElementmaster
parent
fa37850408
commit
782e4832af
|
@ -45,6 +45,12 @@ module.exports = Class( 'DomField' )
|
||||||
*/
|
*/
|
||||||
'private _styles': {},
|
'private _styles': {},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cached immediate parent
|
||||||
|
* @type {HTMLElement}
|
||||||
|
*/
|
||||||
|
'private _parent': null,
|
||||||
|
|
||||||
|
|
||||||
__construct: function( field, element )
|
__construct: function( field, element )
|
||||||
{
|
{
|
||||||
|
@ -101,6 +107,11 @@ module.exports = Class( 'DomField' )
|
||||||
}
|
}
|
||||||
|
|
||||||
_self._element = element;
|
_self._element = element;
|
||||||
|
|
||||||
|
// parent is cached in case we're detached (allows us to
|
||||||
|
// re-attach)
|
||||||
|
_self._parent = element.parentElement;
|
||||||
|
|
||||||
callback( element );
|
callback( element );
|
||||||
|
|
||||||
// if we have any queued requests, process them when we're not
|
// if we have any queued requests, process them when we're not
|
||||||
|
@ -232,19 +243,36 @@ module.exports = Class( 'DomField' )
|
||||||
return [ this._element ];
|
return [ this._element ];
|
||||||
}
|
}
|
||||||
|
|
||||||
var dd = this.getParent( this._element, 'dd' ),
|
var dd = this.getParent( 'dd' ),
|
||||||
dt = ( dd ) ? this.getPrecedingSibling( dd, 'dt' ) : null;
|
dt = ( dd ) ? this.getPrecedingSibling( dd, 'dt' ) : null;
|
||||||
|
|
||||||
return ( dt )
|
return ( dt )
|
||||||
? [ dd, dt ]
|
? [ dd, dt ]
|
||||||
: [ this.getParent( this._element ) ];
|
: [ this.getParent() ];
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
'protected getParent': function( element, type )
|
'public getParent': function( type )
|
||||||
|
{
|
||||||
|
return this.getElementParent( this._element, type );
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
'protected getElementParent': function( element, type )
|
||||||
{
|
{
|
||||||
var parent = element.parentElement;
|
var parent = element.parentElement;
|
||||||
|
|
||||||
|
if ( element === this._element )
|
||||||
|
{
|
||||||
|
parent = parent || this._parent;
|
||||||
|
|
||||||
|
// update parent reference if it's since changed
|
||||||
|
if ( this._parent !== parent )
|
||||||
|
{
|
||||||
|
this._parent = parent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ( parent === null )
|
if ( parent === null )
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
|
@ -261,7 +289,7 @@ module.exports = Class( 'DomField' )
|
||||||
}
|
}
|
||||||
|
|
||||||
// otherwise, keep looking
|
// otherwise, keep looking
|
||||||
return this.getParent( parent, type );
|
return this.getElementParent( parent, type );
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue