lib/capybara/poltergeist/client/compiled/node.js in poltergeist-0.3.0 vs lib/capybara/poltergeist/client/compiled/node.js in poltergeist-0.4.0
- old
+ new
@@ -27,49 +27,44 @@
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
name = _ref[_i];
_fn(name);
}
Node.prototype.scrollIntoView = function() {
- var dimensions, document, pos, scroll, viewport, _ref2, _ref3;
+ var adjust, dimensions, document, pos, scroll, viewport;
dimensions = this.page.validatedDimensions();
document = dimensions.document;
viewport = dimensions.viewport;
pos = this.position();
scroll = {
left: dimensions.left,
top: dimensions.top
};
- if (!((dimensions.left <= (_ref2 = pos.x) && _ref2 < dimensions.right))) {
- scroll.left = Math.min(pos.x, document.width - viewport.width);
- }
- if (!((dimensions.top <= (_ref3 = pos.y) && _ref3 < dimensions.bottom))) {
- scroll.top = Math.min(pos.y, document.height - viewport.height);
- }
+ adjust = function(coord, measurement) {
+ if (pos[coord] < 0) {
+ return scroll[coord] = Math.max(0, scroll[coord] + pos[coord] - (viewport[measurement] / 2));
+ } else if (pos[coord] >= viewport[measurement]) {
+ return scroll[coord] = Math.min(document[measurement] - viewport[measurement], scroll[coord] + pos[coord] - viewport[measurement] + (viewport[measurement] / 2));
+ }
+ };
+ adjust('left', 'width');
+ adjust('top', 'height');
if (scroll.left !== dimensions.left || scroll.top !== dimensions.top) {
this.page.setScrollPosition(scroll);
+ pos = this.position();
}
- return {
- position: this.relativePosition(pos, scroll),
- scroll: scroll
- };
+ return pos;
};
- Node.prototype.relativePosition = function(position, scroll) {
- return {
- x: position.x - scroll.left,
- y: position.y - scroll.top
- };
- };
Node.prototype.click = function() {
var position;
- position = this.scrollIntoView().position;
- return this.page.sendEvent('click', position.x, position.y);
+ position = this.scrollIntoView();
+ return this.page.sendEvent('click', position.left, position.top);
};
Node.prototype.dragTo = function(other) {
- var otherPosition, position, scroll, _ref2;
- _ref2 = this.scrollIntoView(), position = _ref2.position, scroll = _ref2.scroll;
- otherPosition = this.relativePosition(other.position(), scroll);
- this.page.sendEvent('mousedown', position.x, position.y);
- this.page.sendEvent('mousemove', otherPosition.x, otherPosition.y);
- return this.page.sendEvent('mouseup', otherPosition.x, otherPosition.y);
+ var otherPosition, position;
+ position = this.scrollIntoView();
+ otherPosition = other.position();
+ this.page.sendEvent('mousedown', position.left, position.top);
+ this.page.sendEvent('mousemove', otherPosition.left, otherPosition.top);
+ return this.page.sendEvent('mouseup', otherPosition.left, otherPosition.top);
};
return Node;
}).call(this);
\ No newline at end of file