8
0

editablecollection.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. 'use strict';
  6. import mix from './utils/mix.js';
  7. import Collection from './utils/collection.js';
  8. import ObservableMixin from './utils/observablemixin.js';
  9. /**
  10. * A collection of {@link ckeditor5.Editable editables}.
  11. *
  12. * @memberOf ckeditor5
  13. * @mixes utils.ObservaleMixin
  14. * @extends utils.Collection
  15. */
  16. export default class EditableCollection extends Collection {
  17. /**
  18. * Creates a new instance of EditableCollection.
  19. */
  20. constructor() {
  21. super( { idProperty: 'name' } );
  22. /**
  23. * The currently focused editable.
  24. *
  25. * @readonly
  26. * @observable
  27. * @member {ckeditor5.Editable} ckeditor5.EditableCollection#current
  28. */
  29. this.set( 'current', null );
  30. this.on( 'add', ( evt, editable ) => {
  31. this.listenTo( editable, 'change:isFocused', ( evt, name, value ) => {
  32. this.current = value ? editable : null;
  33. } );
  34. } );
  35. this.on( 'remove', ( evt, editable ) => {
  36. this.stopListening( editable );
  37. } );
  38. }
  39. /**
  40. * Destroys the collection.
  41. */
  42. destroy() {
  43. this.stopListening();
  44. for ( let editable of this ) {
  45. editable.destroy();
  46. }
  47. this.clear();
  48. }
  49. }
  50. mix( EditableCollection, ObservableMixin );