text.js 1.3 KB

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