lib/capybara/poltergeist/client/agent.coffee in poltergeist-0.2.0 vs lib/capybara/poltergeist/client/agent.coffee in poltergeist-0.3.0

- old
+ new

@@ -79,13 +79,30 @@ changed: -> event = document.createEvent('HTMLEvents') event.initEvent("change", true, false) @element.dispatchEvent(event) + insideBody: -> + @element == @agent.document.body || + @agent.document.evaluate('ancestor::body', @element, null, XPathResult.BOOLEAN_TYPE, null).booleanValue + text: -> - @element.textContent + return '' unless this.isVisible() + if this.insideBody() + el = @element + else + el = @agent.document.body + + results = @agent.document.evaluate('.//text()[not(ancestor::script)]', el, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null) + text = '' + + for i in [0...results.snapshotLength] + node = results.snapshotItem(i) + text += node.textContent if this.isVisible(node.parentNode) + text + getAttribute: (name) -> if name == 'checked' || name == 'selected' @element[name] else @element.getAttribute(name) @@ -121,23 +138,21 @@ true tagName: -> @element.tagName - elementVisible: (element) -> + isVisible: (element) -> + element = @element unless element - isVisible: (id) -> - visible = (element) -> - if @window.getComputedStyle(element).display == 'none' - false - else if element.parentElement - visible element.parentElement - else - true - visible @element + if @agent.window.getComputedStyle(element).display == 'none' + false + else if element.parentElement + this.isVisible element.parentElement + else + true - position: (id) -> + position: -> pos = (element) -> x = element.offsetLeft y = element.offsetTop if element.offsetParent @@ -168,8 +183,5 @@ document.addEventListener( 'DOMContentLoaded', -> console.log('__DOMContentLoaded') ) - -# Important to return true here - Phantom seems to choke otherwise -true