Skip to content

Commit

Permalink
Create plan-coordinates.js
Browse files Browse the repository at this point in the history
  • Loading branch information
iantrich authored May 17, 2019
1 parent 02abaf3 commit 83fb42b
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions plan-coordinates.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
class PlanCoordinates extends HTMLElement {

constructor() {
super();
this.attachShadow({ mode: 'open' });
}

setConfig(config) {
const root = this.shadowRoot;
if (root.lastChild) root.removeChild(root.lastChild);
this.style.display = 'none';
const card = document.createElement('div');
card.id = "plan-coordinates"
const content = document.createElement('div');
const style = document.createElement('style');
style.textContent = `
#plan-coordinates {
position: absolute;
right: 0px;
top: 16px;
z-index: 1000;
}
#content {
background-color: var(--paper-card-background-color);
border: 1px solid var(--label-badge-blue);
padding: 16px;
}
`;
content.id = "content";
card.appendChild(content);
root.appendChild(style);
root.appendChild(card);
document.addEventListener("mousemove", el => {
let calc_top = 16 - (document.body.querySelector('home-assistant').getBoundingClientRect().top);
card.style.top = `${calc_top}px`;
if (el.path[0] && el.path[0].tagName == 'IMG') {
this.style.display = 'block';
const percentX = Math.ceil((el.clientX - el.path[0].x) * 100 / el.path[0].width);
const percentY = Math.ceil((el.clientY - el.path[0].y) * 100 / el.path[0].height);
content.innerHTML = `left: ${percentX}%<br/>top: ${percentY}%`;
}
});
document.addEventListener('scroll', el => {
let calc_top = 16 - (document.body.querySelector('home-assistant').getBoundingClientRect().top);
card.style.top = `${calc_top}px`;
}, true);
}
set hass(hass) {
}

getCardSize() {
return 1;
}
}
customElements.define('plan-coordinates', PlanCoordinates);

0 comments on commit 83fb42b

Please sign in to comment.