8
0

viewlistitemelement.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /**
  6. * @module list/viewlistitemelement
  7. */
  8. import ViewContainerElement from '@ckeditor/ckeditor5-engine/src/view/containerelement';
  9. /**
  10. * View element class representing list item (`<li>`). It extends {@link module:engine/view/containerelement~ContainerElement}
  11. * and overwrites {@link module:list/viewlistitemelement~ViewListItemElement#getFillerOffset evaluating whether filler offset}
  12. * is needed.
  13. *
  14. * @extends module:engine/view/containerelement~ContainerElement
  15. */
  16. export default class ViewListItemElement extends ViewContainerElement {
  17. /**
  18. * Creates `<li>` view item.
  19. *
  20. * @param {Object|Iterable} [attrs] Collection of attributes.
  21. * @param {module:engine/view/node~Node|Iterable.<module:engine/view/node~Node>} [children] List of nodes to be inserted
  22. * into created element.
  23. */
  24. constructor( attrs, children ) {
  25. super( 'li', attrs, children );
  26. /**
  27. * @inheritDoc
  28. */
  29. this.getFillerOffset = getFillerOffset;
  30. }
  31. }
  32. // Implementation of getFillerOffset for ViewListItemElements.
  33. //
  34. // @returns {Number|null} Block filler offset or `null` if block filler is not needed.
  35. function getFillerOffset() {
  36. /*jshint validthis:true */
  37. const hasOnlyLists = !this.isEmpty && ( this.getChild( 0 ).name == 'ul' || this.getChild( 0 ).name == 'ol' );
  38. return this.isEmpty || hasOnlyLists ? 0 : null;
  39. }