8
0

getpositionedancestor.js 696 B

12345678910111213141516171819202122232425262728
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /**
  6. * @module utils/dom/getpositionedancestor
  7. */
  8. import global from './global';
  9. /**
  10. * For a given element, returns the nearest ancestor element which CSS position is not "static".
  11. *
  12. * @param {HTMLElement} element Native DOM element to be checked.
  13. * @returns {HTMLElement|null}
  14. */
  15. export default function getPositionedAncestor( element ) {
  16. while ( element && element.tagName.toLowerCase() != 'html' ) {
  17. if ( global.window.getComputedStyle( element ).position != 'static' ) {
  18. return element;
  19. }
  20. element = element.parentElement;
  21. }
  22. return null;
  23. }