|
@@ -8,6 +8,7 @@ import Text from './text.js';
|
|
|
import objectToMap from '../../utils/objecttomap.js';
|
|
import objectToMap from '../../utils/objecttomap.js';
|
|
|
import isIterable from '../../utils/isiterable.js';
|
|
import isIterable from '../../utils/isiterable.js';
|
|
|
import isPlainObject from '../../utils/lib/lodash/isPlainObject.js';
|
|
import isPlainObject from '../../utils/lib/lodash/isPlainObject.js';
|
|
|
|
|
+import Matcher from './matcher.js';
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* View element.
|
|
* View element.
|
|
@@ -568,6 +569,29 @@ export default class Element extends Node {
|
|
|
this._fireChange( 'attributes', this );
|
|
this._fireChange( 'attributes', this );
|
|
|
property.forEach( name => this._styles.delete( name ) );
|
|
property.forEach( name => this._styles.delete( name ) );
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Returns ancestor element that match specified pattern.
|
|
|
|
|
+ * Provided patterns should be compatible with {@link engine.view.Matcher Matcher} as it is used internally.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @see engine.view.Matcher
|
|
|
|
|
+ * @param {Object|String|RegExp|function} patterns Patterns used to match correct ancestor. See {@link engine.view.Matcher}.
|
|
|
|
|
+ * @return {engine.view.Element|null} Found element or `null` if no matching ancestor was found.
|
|
|
|
|
+ */
|
|
|
|
|
+ findAncestor( ...patterns ) {
|
|
|
|
|
+ const matcher = new Matcher( ...patterns );
|
|
|
|
|
+ let parent = this.parent;
|
|
|
|
|
+
|
|
|
|
|
+ while ( parent !== null ) {
|
|
|
|
|
+ if ( matcher.match( parent ) ) {
|
|
|
|
|
+ return parent;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ parent = parent.parent;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Parses inline styles and puts property - value pairs into styles map.
|
|
// Parses inline styles and puts property - value pairs into styles map.
|