You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
consul/ui-v2/app/helpers/dom-position.js

29 lines
773 B

import Helper from '@ember/component/helper';
import { inject as service } from '@ember/service';
export default Helper.extend({
dom: service('dom'),
compute: function([selector, id], hash) {
const $el = this.dom.element(selector);
const $refs = [$el.offsetParent, $el];
// TODO: helper probably needs to accept a `reference=` option
// with a selector to use as reference/root
if (selector.startsWith('#resolver:')) {
$refs.unshift($refs[0].offsetParent);
}
return $refs.reduce(
function(prev, item) {
prev.x += item.offsetLeft;
prev.y += item.offsetTop;
return prev;
},
{
x: 0,
y: 0,
height: $el.offsetHeight,
width: $el.offsetWidth,
}
);
},
});