MacGapProject / MacGap1

Desktop WebKit wrapper for HTML/CSS/JS applications.
Other
3.55k stars 209 forks source link

window.getX() and getY() methods #91

Closed jeff-h closed 10 years ago

jeff-h commented 10 years ago

Simple addition to allow javascript to read the X,Y coordinates of the window. Amongst other things this is useful to allow javascript to move the window around when an element in the DOM is dragged. I tested this using the following code:

var dragging = false;
document.onmousemove = function() {
  if (!dragging) return;
  macgap.window.move({
    x: macgap.window.getX() + event.clientX - xstart,
    y: macgap.window.getY() +ystart - event.clientY,
  });
}

document.onmousedown = function(){
  dragging = true;
  xstart = event.clientX;
  ystart = event.clientY;
}

document.onmouseup = function(){
  dragging = false;
}

Note, this technique has an unavoidable flaw; you won't be able to drag the app onto another space like you should.