Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge remote-tracking branch 'sobrinho/master'
Conflicts:
	README.md
  • Loading branch information
jonleighton committed Jul 11, 2012
2 parents 45c8b43 + 3f2ca0d commit 0df2110
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -229,6 +229,8 @@ makes debugging easier). Running `rake autocompile` will watch the
* Added an option ":phantomjs_options", allowing users to specify
additional command-line options passed to phantomjs executable.
(wynst) [Issue #97]
* Scroll element into viewport if needed on click (Gabriel Sobrinho)
[Issue #83]

#### Bug fixes ###

Expand Down
3 changes: 3 additions & 0 deletions lib/capybara/poltergeist/client/agent.coffee
Expand Up @@ -156,6 +156,9 @@ class PoltergeistAgent.Node
else
@element.getAttribute(name)

scrollIntoView: ->
@element.scrollIntoViewIfNeeded()

value: ->
if @element.tagName == 'SELECT' && @element.multiple
option.value for option in @element.children when option.selected
Expand Down
4 changes: 4 additions & 0 deletions lib/capybara/poltergeist/client/compiled/agent.js
Expand Up @@ -224,6 +224,10 @@ PoltergeistAgent.Node = (function() {
}
};

Node.prototype.scrollIntoView = function() {
return this.element.scrollIntoViewIfNeeded();
};

Node.prototype.value = function() {
var option, _i, _len, _ref, _results;
if (this.element.tagName === 'SELECT' && this.element.multiple) {
Expand Down
3 changes: 2 additions & 1 deletion lib/capybara/poltergeist/client/compiled/node.js
Expand Up @@ -4,7 +4,7 @@ Poltergeist.Node = (function() {
var name, _fn, _i, _len, _ref,
_this = this;

Node.DELEGATES = ['text', 'getAttribute', 'value', 'set', 'setAttribute', 'isObsolete', 'removeAttribute', 'isMultiple', 'select', 'tagName', 'find', 'isVisible', 'position', 'trigger', 'parentId', 'clickTest'];
Node.DELEGATES = ['text', 'getAttribute', 'value', 'set', 'setAttribute', 'isObsolete', 'removeAttribute', 'isMultiple', 'select', 'tagName', 'find', 'isVisible', 'position', 'trigger', 'parentId', 'clickTest', 'scrollIntoView'];

function Node(page, id) {
this.page = page;
Expand Down Expand Up @@ -67,6 +67,7 @@ Poltergeist.Node = (function() {

Node.prototype.click = function() {
var pos, test;
this.scrollIntoView();
pos = this.clickPosition();
test = this.clickTest(pos.x, pos.y);
if (test.status === 'success') {
Expand Down
4 changes: 3 additions & 1 deletion lib/capybara/poltergeist/client/node.coffee
Expand Up @@ -3,7 +3,7 @@
class Poltergeist.Node
@DELEGATES = ['text', 'getAttribute', 'value', 'set', 'setAttribute', 'isObsolete',
'removeAttribute', 'isMultiple', 'select', 'tagName', 'find',
'isVisible', 'position', 'trigger', 'parentId', 'clickTest']
'isVisible', 'position', 'trigger', 'parentId', 'clickTest', 'scrollIntoView']

constructor: (@page, @id) ->

Expand Down Expand Up @@ -53,6 +53,8 @@ class Poltergeist.Node
}

click: ->
this.scrollIntoView()

pos = this.clickPosition()
test = this.clickTest(pos.x, pos.y)

Expand Down
11 changes: 11 additions & 0 deletions spec/integration/session_spec.rb
Expand Up @@ -70,6 +70,17 @@
end
end

context "when the element is not in the viewport of parent element" do
before do
@session.visit("/poltergeist/scroll")
end

it "scrolls into view" do
@session.click_link "Link outside viewport"
@session.current_path.should eq '/'
end
end

describe 'Node#set' do
before do
@session.visit('/poltergeist/with_js')
Expand Down
17 changes: 17 additions & 0 deletions spec/support/views/scroll.erb
@@ -0,0 +1,17 @@
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<title>scroll</title>
</head>

<body>
<div style="height: 100px; overflow-y: auto">
<div style="height: 300px;">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin lacus odio, dapibus id bibendum in, rhoncus sed dolor. In quis nulla at diam euismod suscipit vitae vitae sapien. Nam viverra hendrerit augue a accumsan. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Fusce fermentum tortor at neque malesuada sodales. Nunc quis augue a quam venenatis pharetra sit amet et risus. Nulla pharetra enim a leo varius scelerisque aliquam urna vestibulum. Sed felis eros, iaculis convallis fermentum ac, condimentum ac lacus. Sed turpis magna, tristique eu faucibus non, faucibus vitae elit. Morbi venenatis adipiscing aliquam.</p>
</div>

<p>
<a href="/">Link outside viewport</a>
</p>
</div>
</body>
</html>

0 comments on commit 0df2110

Please sign in to comment.