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

- old
+ new

@@ -88,12 +88,32 @@ var event; event = document.createEvent('HTMLEvents'); event.initEvent("change", true, false); return this.element.dispatchEvent(event); }; + Node.prototype.insideBody = function() { + return this.element === this.agent.document.body || this.agent.document.evaluate('ancestor::body', this.element, null, XPathResult.BOOLEAN_TYPE, null).booleanValue; + }; Node.prototype.text = function() { - return this.element.textContent; + var el, i, node, results, text, _ref; + if (!this.isVisible()) { + return ''; + } + if (this.insideBody()) { + el = this.element; + } else { + el = this.agent.document.body; + } + results = this.agent.document.evaluate('.//text()[not(ancestor::script)]', el, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); + text = ''; + for (i = 0, _ref = results.snapshotLength; 0 <= _ref ? i < _ref : i > _ref; 0 <= _ref ? i++ : i--) { + node = results.snapshotItem(i); + if (this.isVisible(node.parentNode)) { + text += node.textContent; + } + } + return text; }; Node.prototype.getAttribute = function(name) { if (name === 'checked' || name === 'selected') { return this.element[name]; } else { @@ -142,25 +162,23 @@ } }; Node.prototype.tagName = function() { return this.element.tagName; }; - Node.prototype.elementVisible = function(element) {}; - Node.prototype.isVisible = function(id) { - var visible; - visible = function(element) { - if (this.window.getComputedStyle(element).display === 'none') { - return false; - } else if (element.parentElement) { - return visible(element.parentElement); - } else { - return true; - } - }; - return visible(this.element); + Node.prototype.isVisible = function(element) { + if (!element) { + element = this.element; + } + if (this.agent.window.getComputedStyle(element).display === 'none') { + return false; + } else if (element.parentElement) { + return this.isVisible(element.parentElement); + } else { + return true; + } }; - Node.prototype.position = function(id) { + Node.prototype.position = function() { var pos; pos = function(element) { var parentPos, x, y; x = element.offsetLeft; y = element.offsetTop; @@ -192,7 +210,6 @@ return Node; })(); window.__poltergeist = new PoltergeistAgent; document.addEventListener('DOMContentLoaded', function() { return console.log('__DOMContentLoaded'); -}); -true; +}); \ No newline at end of file