/** * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved. * For licensing, see LICENSE.md or http://ckeditor.com/license */ /** * @fileOverview Defines the {@link CKEDITOR.dom.node} class which is the base * class for classes that represent DOM nodes. */ /** * Base class for classes representing DOM nodes. This constructor may return * an instance of a class that inherits from this class, like * {@link CKEDITOR.dom.element} or {@link CKEDITOR.dom.text}. * * @class * @extends CKEDITOR.dom.domObject * @constructor Creates a node class instance. * @param {Object} domNode A native DOM node. * @see CKEDITOR.dom.element * @see CKEDITOR.dom.text */ CKEDITOR.dom.node = function( domNode ) { if ( domNode ) { var type = domNode.nodeType == CKEDITOR.NODE_DOCUMENT ? 'document' : domNode.nodeType == CKEDITOR.NODE_ELEMENT ? 'element' : domNode.nodeType == CKEDITOR.NODE_TEXT ? 'text' : domNode.nodeType == CKEDITOR.NODE_COMMENT ? 'comment' : domNode.nodeType == CKEDITOR.NODE_DOCUMENT_FRAGMENT ? 'documentFragment' : 'domObject'; // Call the base constructor otherwise. return new CKEDITOR.dom[ type ]( domNode ); } return this; }; CKEDITOR.dom.node.prototype = new CKEDITOR.dom.domObject(); /** * Element node type. * * @readonly * @property {Number} [=1] * @member CKEDITOR */ CKEDITOR.NODE_ELEMENT = 1; /** * Document node type. * * @readonly * @property {Number} [=9] * @member CKEDITOR */ CKEDITOR.NODE_DOCUMENT = 9; /** * Text node type. * * @readonly * @property {Number} [=3] * @member CKEDITOR */ CKEDITOR.NODE_TEXT = 3; /** * Comment node type. * * @readonly * @property {Number} [=8] * @member CKEDITOR */ CKEDITOR.NODE_COMMENT = 8; /** * Document fragment node type. * * @readonly * @property {Number} [=11] * @member CKEDITOR */ CKEDITOR.NODE_DOCUMENT_FRAGMENT = 11; /** * Indicates that positions of both nodes are identical (this is the same node). See {@link CKEDITOR.dom.node#getPosition}. * * @readonly * @property {Number} [=0] * @member CKEDITOR */ CKEDITOR.POSITION_IDENTICAL = 0; /** * Indicates that nodes are in different (detached) trees. See {@link CKEDITOR.dom.node#getPosition}. * * @readonly * @property {Number} [=1] * @member CKEDITOR */ CKEDITOR.POSITION_DISCONNECTED = 1; /** * Indicates that the context node follows the other node. See {@link CKEDITOR.dom.node#getPosition}. * * @readonly * @property {Number} [=2] * @member CKEDITOR */ CKEDITOR.POSITION_FOLLOWING = 2; /** * Indicates that the context node precedes the other node. See {@link CKEDITOR.dom.node#getPosition}. * * @readonly * @property {Number} [=4] * @member CKEDITOR */ CKEDITOR.POSITION_PRECEDING = 4; /** * Indicates that the context node is a descendant of the other node. See {@link CKEDITOR.dom.node#getPosition}. * * @readonly * @property {Number} [=8] * @member CKEDITOR */ CKEDITOR.POSITION_IS_CONTAINED = 8; /** * Indicates that the context node contains the other node. See {@link CKEDITOR.dom.node#getPosition}. * * @readonly * @property {Number} [=16] * @member CKEDITOR */ CKEDITOR.POSITION_CONTAINS = 16; CKEDITOR.tools.extend( CKEDITOR.dom.node.prototype, { /** * Makes this node a child of another element. * * var p = new CKEDITOR.dom.element( 'p' ); * var strong = new CKEDITOR.dom.element( 'strong' ); * strong.appendTo( p ); * * // Result: '
'. * * @param {CKEDITOR.dom.element} element The target element to which this node will be appended. * @returns {CKEDITOR.dom.element} The target element. */ appendTo: function( element, toStart ) { element.append( this, toStart ); return element; }, /** * Clones this node. * * **Note**: Values set by {#setCustomData} will not be available in the clone. * * @param {Boolean} [includeChildren=false] If `true` then all node's * children will be cloned recursively. * @param {Boolean} [cloneId=false] Whether ID attributes should be cloned, too. * @returns {CKEDITOR.dom.node} Clone of this node. */ clone: function( includeChildren, cloneId ) { var $clone = this.$.cloneNode( includeChildren ); // The "id" attribute should never be cloned to avoid duplication. removeIds( $clone ); var node = new CKEDITOR.dom.node( $clone ); // On IE8 we need to fixed HTML5 node name, see details below. if ( CKEDITOR.env.ie && CKEDITOR.env.version < 9 && ( this.type == CKEDITOR.NODE_ELEMENT || this.type == CKEDITOR.NODE_DOCUMENT_FRAGMENT ) ) { renameNodes( node ); } return node; function removeIds( node ) { // Reset data-cke-expando only when has been cloned (IE and only for some types of objects). if ( node[ 'data-cke-expando' ] ) node[ 'data-cke-expando' ] = false; if ( node.nodeType != CKEDITOR.NODE_ELEMENT && node.nodeType != CKEDITOR.NODE_DOCUMENT_FRAGMENT ) return; if ( !cloneId && node.nodeType == CKEDITOR.NODE_ELEMENT ) node.removeAttribute( 'id', false ); if ( includeChildren ) { var childs = node.childNodes; for ( var i = 0; i < childs.length; i++ ) removeIds( childs[ i ] ); } } // IE8 rename HTML5 nodes by adding `:` at the begging of the tag name when the node is cloned, // so `