lib/capybara/poltergeist/client/compiled/agent.js in poltergeist-1.7.0 vs lib/capybara/poltergeist/client/compiled/agent.js in poltergeist-1.8.0
- old
+ new
@@ -1,42 +1,47 @@
var PoltergeistAgent;
PoltergeistAgent = (function() {
+ PoltergeistAgent.JSON || (PoltergeistAgent.JSON = {
+ parse: JSON.parse,
+ stringify: JSON.stringify
+ });
+
function PoltergeistAgent() {
this.elements = [];
this.nodes = {};
}
PoltergeistAgent.prototype.externalCall = function(name, args) {
- var error;
+ var error, error1;
try {
return {
value: this[name].apply(this, args)
};
- } catch (_error) {
- error = _error;
+ } catch (error1) {
+ error = error1;
return {
error: {
message: error.toString(),
stack: error.stack
}
};
}
};
PoltergeistAgent.stringify = function(object) {
- var error;
+ var error, error1;
try {
- return JSON.stringify(object, function(key, value) {
+ return PoltergeistAgent.JSON.stringify(object, function(key, value) {
if (Array.isArray(this[key])) {
return this[key];
} else {
return value;
}
});
- } catch (_error) {
- error = _error;
+ } catch (error1) {
+ error = error1;
if (error instanceof TypeError) {
return '"(cyclic structure)"';
} else {
throw error;
}
@@ -46,36 +51,36 @@
PoltergeistAgent.prototype.currentUrl = function() {
return window.location.href.replace(/\ /g, '%20');
};
PoltergeistAgent.prototype.find = function(method, selector, within) {
- var el, error, i, results, xpath, _i, _len, _results;
+ var el, error, error1, i, j, len, results, results1, xpath;
if (within == null) {
within = document;
}
try {
if (method === "xpath") {
xpath = document.evaluate(selector, within, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
results = (function() {
- var _i, _ref, _results;
- _results = [];
- for (i = _i = 0, _ref = xpath.snapshotLength; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
- _results.push(xpath.snapshotItem(i));
+ var j, ref, results1;
+ results1 = [];
+ for (i = j = 0, ref = xpath.snapshotLength; 0 <= ref ? j < ref : j > ref; i = 0 <= ref ? ++j : --j) {
+ results1.push(xpath.snapshotItem(i));
}
- return _results;
+ return results1;
})();
} else {
results = within.querySelectorAll(selector);
}
- _results = [];
- for (_i = 0, _len = results.length; _i < _len; _i++) {
- el = results[_i];
- _results.push(this.register(el));
+ results1 = [];
+ for (j = 0, len = results.length; j < len; j++) {
+ el = results[j];
+ results1.push(this.register(el));
}
- return _results;
- } catch (_error) {
- error = _error;
+ return results1;
+ } catch (error1) {
+ error = error1;
if (error.code === DOMException.SYNTAX_ERR || error.code === 51) {
throw new PoltergeistAgent.InvalidSelector;
} else {
throw error;
}
@@ -93,12 +98,12 @@
width: document.documentElement.scrollWidth || document.documentElement.clientWidth
};
};
PoltergeistAgent.prototype.get = function(id) {
- var _base;
- return (_base = this.nodes)[id] || (_base[id] = new PoltergeistAgent.Node(this, this.elements[id]));
+ var base;
+ return (base = this.nodes)[id] || (base[id] = new PoltergeistAgent.Node(this, this.elements[id]));
};
PoltergeistAgent.prototype.nodeCall = function(id, name, args) {
var node;
node = this.get(id);
@@ -151,13 +156,13 @@
FOCUS: ['blur', 'focus', 'focusin', 'focusout'],
MOUSE: ['click', 'dblclick', 'mousedown', 'mouseenter', 'mouseleave', 'mousemove', 'mouseover', 'mouseout', 'mouseup', 'contextmenu'],
FORM: ['submit']
};
- function Node(agent, element) {
+ function Node(agent, element1) {
this.agent = agent;
- this.element = element;
+ this.element = element1;
}
Node.prototype.parentId = function() {
return this.agent.register(this.element.parentNode);
};
@@ -176,32 +181,37 @@
Node.prototype.find = function(method, selector) {
return this.agent.find(method, selector, this.element);
};
Node.prototype.isObsolete = function() {
- var obsolete,
- _this = this;
- obsolete = function(element) {
- if (element.parentNode != null) {
- if (element.parentNode === document) {
- return false;
+ var obsolete;
+ obsolete = (function(_this) {
+ return function(element) {
+ if (element.parentNode != null) {
+ if (element.parentNode === document) {
+ return false;
+ } else {
+ return obsolete(element.parentNode);
+ }
} else {
- return obsolete(element.parentNode);
+ return true;
}
- } else {
- return true;
- }
- };
+ };
+ })(this);
return obsolete(this.element);
};
Node.prototype.changed = function() {
var element, event;
event = document.createEvent('HTMLEvents');
event.initEvent('change', true, false);
if (this.element.nodeName === 'OPTION') {
element = this.element.parentNode;
+ if (element.nodeName === 'OPTGROUP') {
+ element = element.parentNode;
+ }
+ element;
} else {
element = this.element;
}
return element.dispatchEvent(event);
};
@@ -263,16 +273,20 @@
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
return window.getSelection().deleteFromDocument();
};
+ Node.prototype.getProperty = function(name) {
+ return this.element[name];
+ };
+
Node.prototype.getAttributes = function() {
- var attr, attrs, i, _i, _len, _ref;
+ var attr, attrs, j, len, ref;
attrs = {};
- _ref = this.element.attributes;
- for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
- attr = _ref[i];
+ ref = this.element.attributes;
+ for (j = 0, len = ref.length; j < len; j++) {
+ attr = ref[j];
attrs[attr.name] = attr.value.replace("\n", "\\n");
}
return attrs;
};
@@ -283,45 +297,48 @@
return this.element.getAttribute(name);
}
};
Node.prototype.scrollIntoView = function() {
- return this.element.scrollIntoViewIfNeeded();
+ this.element.scrollIntoViewIfNeeded();
+ if (!this.isInViewport()) {
+ return this.element.scrollIntoView();
+ }
};
Node.prototype.value = function() {
- var option, _i, _len, _ref, _results;
+ var j, len, option, ref, results1;
if (this.element.tagName === 'SELECT' && this.element.multiple) {
- _ref = this.element.children;
- _results = [];
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
- option = _ref[_i];
+ ref = this.element.children;
+ results1 = [];
+ for (j = 0, len = ref.length; j < len; j++) {
+ option = ref[j];
if (option.selected) {
- _results.push(option.value);
+ results1.push(option.value);
}
}
- return _results;
+ return results1;
} else {
return this.element.value;
}
};
Node.prototype.set = function(value) {
- var char, keyCode, _i, _len;
+ var char, j, keyCode, len;
if (this.element.readOnly) {
return;
}
if (this.element.maxLength >= 0) {
value = value.substr(0, this.element.maxLength);
}
- this.element.value = '';
this.trigger('focus');
+ this.element.value = '';
if (this.element.type === 'number') {
this.element.value = value;
} else {
- for (_i = 0, _len = value.length; _i < _len; _i++) {
- char = value[_i];
+ for (j = 0, len = value.length; j < len; j++) {
+ char = value[j];
keyCode = this.characterToKeyCode(char);
this.keyupdowned('keydown', keyCode);
this.element.value += char;
this.keypressed(false, false, false, false, char.charCodeAt(0), char.charCodeAt(0));
this.keyupdowned('keyup', keyCode);
@@ -361,37 +378,44 @@
Node.prototype.tagName = function() {
return this.element.tagName;
};
Node.prototype.isVisible = function(element) {
- if (!element) {
- element = this.element;
+ var style;
+ element || (element = this.element);
+ while (element) {
+ style = window.getComputedStyle(element);
+ if (style.display === 'none' || style.visibility === 'hidden' || parseFloat(style.opacity) === 0) {
+ return false;
+ }
+ element = element.parentElement;
}
- if (window.getComputedStyle(element).display === 'none') {
- return false;
- } else if (element.parentElement) {
- return this.isVisible(element.parentElement);
- } else {
- return true;
- }
+ return true;
};
+ Node.prototype.isInViewport = function() {
+ var rect;
+ rect = this.element.getBoundingClientRect();
+ return rect.top >= 0 && rect.left >= 0 && rect.bottom <= window.innerHeight && rect.right <= window.innerWidth;
+ };
+
Node.prototype.isDisabled = function() {
return this.element.disabled || this.element.tagName === 'OPTION' && this.element.parentNode.disabled;
};
Node.prototype.path = function() {
- var elements, selectors,
- _this = this;
- elements = this.parentIds().reverse().map(function(id) {
- return _this.agent.get(id);
- });
+ var elements, selectors;
+ elements = this.parentIds().reverse().map((function(_this) {
+ return function(id) {
+ return _this.agent.get(id);
+ };
+ })(this));
elements.push(this);
selectors = elements.map(function(el) {
var prev_siblings;
prev_siblings = el.find('xpath', "./preceding-sibling::" + (el.tagName()));
- return "" + (el.tagName()) + "[" + (prev_siblings.length + 1) + "]";
+ return (el.tagName()) + "[" + (prev_siblings.length + 1) + "]";
});
return "//" + selectors.join('/');
};
Node.prototype.containsSelection = function() {
@@ -486,19 +510,21 @@
selector: origEl && this.getSelector(origEl)
};
};
Node.prototype.getSelector = function(el) {
- var className, selector, _i, _len, _ref;
+ var className, classes, j, len, ref, ref1, selector;
selector = el.tagName !== 'HTML' ? this.getSelector(el.parentNode) + ' ' : '';
selector += el.tagName.toLowerCase();
if (el.id) {
selector += "#" + el.id;
}
- _ref = el.classList;
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
- className = _ref[_i];
- selector += "." + className;
+ classes = el.classList || ((ref = el.getAttribute('class')) != null ? (ref1 = ref.trim()) != null ? ref1.split(/\s+/) : void 0 : void 0) || [];
+ for (j = 0, len = classes.length; j < len; j++) {
+ className = classes[j];
+ if (className !== '') {
+ selector += "." + className;
+ }
}
return selector;
};
Node.prototype.characterToKeyCode = function(character) {