GazePoint.js 992 Bytes
Newer Older
Alexander Bazo committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
class GazePoint {

  constructor(screenX, screenY) {
    this.screenX = screenX;
    this.screenY = screenY;
    this.createdAt = Date.now();
    this.id = this.createdAt;
  }

  linkTo(node) {
    let bb = node.getBoundingClientRect(),
      // Difference between height of browser window (including menus and decoration) and actual viewport height
      yOffSet = window.outerHeight - window.innerHeight,
      elementLeft = window.screenX + bb.left,
      elementTop = window.screenY + bb.top + yOffSet,
      elementRight = window.screenX + bb.right,
      elementBottom = window.screenY + bb.bottom + yOffSet,
      coordinates;
    if (this.screenX >= elementLeft && this.screenX <= elementRight && this
      .screenY >=
      elementTop && this.screenY <= elementBottom) {
      this.hasLink = true;
      this.link = node;
      this.targetX = this.screenX - elementLeft;
      this.targetY = this.screenY - elementTop;
    }
    return coordinates;
  }

}

export default GazePoint;