8
0

viewlistitemelement.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 a 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 a `<li>` view item.
  19. *
  20. * @param {Object|Iterable} [attrs] A collection of attributes.
  21. * @param {module:engine/view/node~Node|Iterable.<module:engine/view/node~Node>} [children] The list of nodes to be inserted
  22. * into the 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. const hasOnlyLists = !this.isEmpty && ( this.getChild( 0 ).name == 'ul' || this.getChild( 0 ).name == 'ol' );
  37. return this.isEmpty || hasOnlyLists ? 0 : null;
  38. }