|
|
@@ -147,22 +147,32 @@ export default class Element extends Node {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Checks whether this view object is of the given type.
|
|
|
+ * Method verifies if the checked object belongs to a given a type. Type's name might be prefixed with a `view:` string,
|
|
|
+ * for example `view:element`. Type is a string which usually equal to a name of the class written in camelCase convention.
|
|
|
+ * If the object is a class instance, which has a parent class with `is()` method, then type verification returns `true`
|
|
|
+ * for any type match for an entire child-parent chain.
|
|
|
*
|
|
|
+ * There is also possibility to check element's {@link #name} rather than just type. Name might be provided as second attribute
|
|
|
+ * or might replace the type.
|
|
|
+ *
|
|
|
+ * // obj is a `li` element
|
|
|
* obj.is( 'element' ); // true
|
|
|
+ * obj.is( 'view:element' ); // true
|
|
|
* obj.is( 'li' ); // true
|
|
|
* obj.is( 'element', 'li' ); // true
|
|
|
* obj.is( 'text' ); // false
|
|
|
* obj.is( 'element', 'img' ); // false
|
|
|
*
|
|
|
- * Read more in {@link module:engine/view/node~Node#is `Node#is()`}.
|
|
|
+ * Acceptable type for this class is `element` and its prefixed version, element's name or combination of both arguments.
|
|
|
+ *
|
|
|
+ * See also: {@link module:engine/view/node~Node#is `Node#is()`}.
|
|
|
*
|
|
|
* @param {String} type
|
|
|
* @param {String} [name] Element name.
|
|
|
* @returns {Boolean}
|
|
|
*/
|
|
|
is( type, name = null ) {
|
|
|
- const cutType = type.replace( 'view:', '' );
|
|
|
+ const cutType = type.replace( /^view:/, '' );
|
|
|
if ( !name ) {
|
|
|
return cutType == 'element' || cutType == this.name || super.is( type );
|
|
|
} else {
|