element.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. 'use strict';
  6. CKEDITOR.define( [ 'document/node', 'document/nodelist' ], function( Node, NodeList ) {
  7. /**
  8. * Linear data element.
  9. *
  10. * @class document.Element
  11. */
  12. class Element extends Node {
  13. /**
  14. * Creates linear data element.
  15. *
  16. * This constructor should be used only internally by the document.
  17. *
  18. * @param {document.Element|Null} parent Node parent.
  19. * @param {String} name Node name.
  20. * @param {Array} attrs Array of attributes.
  21. */
  22. constructor( name, attrs, children ) {
  23. super( attrs );
  24. /**
  25. * Element name.
  26. *
  27. * @readonly
  28. * @property {String} name
  29. */
  30. this.name = name;
  31. /**
  32. * Array of children nodes.
  33. *
  34. * @property {Array} children
  35. */
  36. this.children = new NodeList();
  37. if ( children ) {
  38. this.insertChildren( 0, children );
  39. }
  40. }
  41. insertChildren( index, nodes ) {
  42. this.children.insert( index, new NodeList( nodes ) );
  43. for ( var node of this.children ) {
  44. node.parent = this;
  45. }
  46. }
  47. }
  48. return Element;
  49. } );