lib/capybara/poltergeist/client/compiled/agent.js in poltergeist-1.3.0 vs lib/capybara/poltergeist/client/compiled/agent.js in poltergeist-1.4.0
- old
+ new
@@ -6,11 +6,10 @@
this.nodes = {};
}
PoltergeistAgent.prototype.externalCall = function(name, args) {
var error;
-
try {
return {
value: this[name].apply(this, args)
};
} catch (_error) {
@@ -24,11 +23,10 @@
}
};
PoltergeistAgent.stringify = function(object) {
var error;
-
try {
return JSON.stringify(object, function(key, value) {
if (Array.isArray(this[key])) {
return this[key];
} else {
@@ -44,25 +42,23 @@
}
}
};
PoltergeistAgent.prototype.currentUrl = function() {
- return window.location.toString();
+ return encodeURI(window.location.href);
};
PoltergeistAgent.prototype.find = function(method, selector, within) {
var el, error, i, results, xpath, _i, _len, _results;
-
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));
}
return _results;
@@ -98,17 +94,15 @@
};
};
PoltergeistAgent.prototype.get = function(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);
if (node.isObsolete()) {
throw new PoltergeistAgent.ObsoleteNode;
}
return node[name].apply(node, args);
@@ -168,11 +162,10 @@
};
Node.prototype.isObsolete = function() {
var obsolete,
_this = this;
-
obsolete = function(element) {
if (element.parentNode != null) {
if (element.parentNode === document) {
return false;
} else {
@@ -185,38 +178,34 @@
return obsolete(this.element);
};
Node.prototype.changed = function() {
var event;
-
event = document.createEvent('HTMLEvents');
event.initEvent('change', true, false);
return this.element.dispatchEvent(event);
};
Node.prototype.input = function() {
var event;
-
event = document.createEvent('HTMLEvents');
event.initEvent('input', true, false);
return this.element.dispatchEvent(event);
};
Node.prototype.keyupdowned = function(eventName, keyCode) {
var event;
-
event = document.createEvent('UIEvents');
event.initEvent(eventName, true, true);
event.keyCode = keyCode;
event.which = keyCode;
event.charCode = 0;
return this.element.dispatchEvent(event);
};
Node.prototype.keypressed = function(altKey, ctrlKey, shiftKey, metaKey, keyCode, charCode) {
var event;
-
event = document.createEvent('UIEvents');
event.initEvent('keypress', true, true);
event.window = this.agent.window;
event.altKey = altKey;
event.ctrlKey = ctrlKey;
@@ -256,11 +245,10 @@
return this.element.scrollIntoViewIfNeeded();
};
Node.prototype.value = function() {
var option, _i, _len, _ref, _results;
-
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];
@@ -274,11 +262,10 @@
}
};
Node.prototype.set = function(value) {
var char, keyCode, _i, _len;
-
if (this.element.readOnly) {
return;
}
if (this.element.maxLength >= 0) {
value = value.substr(0, this.element.maxLength);
@@ -340,29 +327,28 @@
Node.prototype.isDisabled = function() {
return this.element.disabled || this.element.tagName === 'OPTION' && this.element.parentNode.disabled;
};
Node.prototype.frameOffset = function() {
- var offset, rect, win;
-
+ var offset, rect, style, win;
win = window;
offset = {
top: 0,
left: 0
};
while (win.frameElement) {
- rect = window.frameElement.getClientRects()[0];
+ rect = win.frameElement.getClientRects()[0];
+ style = win.getComputedStyle(win.frameElement);
win = win.parent;
- offset.top += rect.top;
- offset.left += rect.left;
+ offset.top += rect.top + parseInt(style.getPropertyValue("padding-top"), 10);
+ offset.left += rect.left + parseInt(style.getPropertyValue("padding-left"), 10);
}
return offset;
};
Node.prototype.position = function() {
var frameOffset, pos, rect;
-
rect = this.element.getClientRects()[0];
if (!rect) {
throw new PoltergeistAgent.ObsoleteNode;
}
frameOffset = this.frameOffset();
@@ -377,11 +363,10 @@
return pos;
};
Node.prototype.trigger = function(name) {
var event;
-
if (Node.EVENTS.MOUSE.indexOf(name) !== -1) {
event = document.createEvent('MouseEvent');
event.initMouseEvent(name, true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
} else if (Node.EVENTS.FOCUS.indexOf(name) !== -1) {
event = document.createEvent('HTMLEvents');
@@ -392,11 +377,10 @@
return this.element.dispatchEvent(event);
};
Node.prototype.mouseEventTest = function(x, y) {
var el, frameOffset, origEl;
-
frameOffset = this.frameOffset();
x -= frameOffset.left;
y -= frameOffset.top;
el = origEl = document.elementFromPoint(x, y);
while (el) {
@@ -414,11 +398,10 @@
};
};
Node.prototype.getSelector = function(el) {
var className, selector, _i, _len, _ref;
-
selector = el.tagName !== 'HTML' ? this.getSelector(el.parentNode) + ' ' : '';
selector += el.tagName.toLowerCase();
if (el.id) {
selector += "#" + el.id;
}
@@ -430,10 +413,9 @@
return selector;
};
Node.prototype.characterToKeyCode = function(character) {
var code, specialKeys;
-
code = character.toUpperCase().charCodeAt(0);
specialKeys = {
96: 192,
45: 189,
61: 187,