8
0

text.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /**
  2. * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import Node from './node.js';
  6. /**
  7. * Tree view text node.
  8. *
  9. * @memberOf engine.view
  10. * @extends engine.view.Node
  11. */
  12. export default class Text extends Node {
  13. /**
  14. * Creates a tree view text node.
  15. *
  16. * @param {String} data Text.
  17. */
  18. constructor( data ) {
  19. super();
  20. /**
  21. * The text content.
  22. *
  23. * Setting the data fires the {@link engine.view.Node#event:change change event}.
  24. *
  25. * @private
  26. * @member {String} engine.view.Text#_data
  27. */
  28. this._data = data;
  29. }
  30. /**
  31. * Clones this node.
  32. *
  33. * @returns {engine.view.Text} Text node that is a clone of this node.
  34. */
  35. clone() {
  36. return new Text( this.data );
  37. }
  38. /**
  39. * The text content.
  40. *
  41. * Setting the data fires the {@link view.Node#change change event}.
  42. */
  43. get data() {
  44. return this._data;
  45. }
  46. set data( data ) {
  47. this._fireChange( 'text', this );
  48. this._data = data;
  49. }
  50. /**
  51. * Checks if this text node is similar to other text node.
  52. * Both nodes should have the same data to be considered as similar.
  53. *
  54. * @param {engine.view.Text} otherNode Node to check if it is same as this node.
  55. * @returns {Boolean}
  56. */
  57. isSimilar( otherNode ) {
  58. if ( !( otherNode instanceof Text ) ) {
  59. return false;
  60. }
  61. return this === otherNode || this.data === otherNode.data;
  62. }
  63. }