logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://anongit.hacktivis.me/git/pleroma-fe.git/

offset_finder.service.js (1221B)


  1. export const findOffset = (child, parent, { top = 0, left = 0 } = {}, ignorePadding = true) => {
  2. const result = {
  3. top: top + child.offsetTop,
  4. left: left + child.offsetLeft
  5. }
  6. if (!ignorePadding && child !== window) {
  7. const { topPadding, leftPadding } = findPadding(child)
  8. result.top += ignorePadding ? 0 : topPadding
  9. result.left += ignorePadding ? 0 : leftPadding
  10. }
  11. if (child.offsetParent && window.getComputedStyle(child.offsetParent).position !== 'sticky' && (parent === window || parent.contains(child.offsetParent) || parent === child.offsetParent)) {
  12. return findOffset(child.offsetParent, parent, result, false)
  13. } else {
  14. if (parent !== window) {
  15. const { topPadding, leftPadding } = findPadding(parent)
  16. result.top += topPadding
  17. result.left += leftPadding
  18. }
  19. return result
  20. }
  21. }
  22. const findPadding = (el) => {
  23. const topPaddingStr = window.getComputedStyle(el)['padding-top']
  24. const topPadding = Number(topPaddingStr.substring(0, topPaddingStr.length - 2))
  25. const leftPaddingStr = window.getComputedStyle(el)['padding-left']
  26. const leftPadding = Number(leftPaddingStr.substring(0, leftPaddingStr.length - 2))
  27. return { topPadding, leftPadding }
  28. }