getborderwidths.js 915 B

123456789101112131415161718192021222324252627
  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/getborderwidths
  7. */
  8. /**
  9. * Returns an object containing CSS border widths of a specified HTML element.
  10. *
  11. * @param {HTMLElement} element An element which has CSS borders.
  12. * @param {Object} An object containing `top`, `left`, `right` and `bottom` properties
  13. * with numerical values of the `border-[top,left,right,bottom]-width` CSS styles.
  14. */
  15. export default function getBorderWidths( element ) {
  16. // Call getComputedStyle on the window the element document belongs to.
  17. const style = element.ownerDocument.defaultView.getComputedStyle( element );
  18. return {
  19. top: parseInt( style.borderTopWidth, 10 ),
  20. right: parseInt( style.borderRightWidth, 10 ),
  21. bottom: parseInt( style.borderBottomWidth, 10 ),
  22. left: parseInt( style.borderLeftWidth, 10 )
  23. };
  24. }