2011-07-20 14:23:04 +08:00
|
|
|
|
if (!Array.prototype.map) {
|
2015-09-25 20:37:07 +08:00
|
|
|
|
Array.prototype.map = function (fun) {
|
2013-11-08 05:54:33 +08:00
|
|
|
|
"use strict";
|
2011-07-20 14:23:04 +08:00
|
|
|
|
|
2015-09-04 23:46:55 +08:00
|
|
|
|
if (this === undefined || this === null) {
|
2013-11-08 05:54:33 +08:00
|
|
|
|
throw new TypeError();
|
|
|
|
|
}
|
2011-07-20 14:23:04 +08:00
|
|
|
|
|
2013-11-08 05:54:33 +08:00
|
|
|
|
var t = Object(this);
|
|
|
|
|
var len = t.length >>> 0;
|
|
|
|
|
if (typeof fun !== "function") {
|
|
|
|
|
throw new TypeError();
|
|
|
|
|
}
|
2011-07-20 14:23:04 +08:00
|
|
|
|
|
2013-11-08 05:54:33 +08:00
|
|
|
|
var res = new Array(len);
|
|
|
|
|
var thisp = arguments[1];
|
|
|
|
|
for (var i = 0; i < len; i++) {
|
|
|
|
|
if (i in t) {
|
|
|
|
|
res[i] = fun.call(thisp, t[i], i, t);
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-07-20 14:23:04 +08:00
|
|
|
|
|
2013-11-08 05:54:33 +08:00
|
|
|
|
return res;
|
|
|
|
|
};
|
2013-09-10 15:03:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-08 05:54:33 +08:00
|
|
|
|
expect.Assertion.prototype.near = function (expected, delta) {
|
|
|
|
|
delta = delta || 1;
|
|
|
|
|
expect(this.obj.x).to
|
|
|
|
|
.be.within(expected.x - delta, expected.x + delta);
|
|
|
|
|
expect(this.obj.y).to
|
|
|
|
|
.be.within(expected.y - delta, expected.y + delta);
|
2013-09-10 15:03:59 +08:00
|
|
|
|
};
|
|
|
|
|
|
2013-11-08 05:54:33 +08:00
|
|
|
|
expect.Assertion.prototype.nearLatLng = function (expected, delta) {
|
|
|
|
|
delta = delta || 1e-4;
|
|
|
|
|
expect(this.obj.lat).to
|
|
|
|
|
.be.within(expected.lat - delta, expected.lat + delta);
|
|
|
|
|
expect(this.obj.lng).to
|
|
|
|
|
.be.within(expected.lng - delta, expected.lng + delta);
|
|
|
|
|
};
|
2015-07-16 23:01:44 +08:00
|
|
|
|
|
|
|
|
|
happen.at = function (what, x, y, props) {
|
|
|
|
|
this.once(document.elementFromPoint(x, y), L.Util.extend({
|
2015-09-25 18:55:37 +08:00
|
|
|
|
type: what,
|
|
|
|
|
clientX: x,
|
|
|
|
|
clientY: y,
|
|
|
|
|
screenX: x,
|
|
|
|
|
screenY: y,
|
|
|
|
|
which: 1,
|
|
|
|
|
button: 0
|
|
|
|
|
}, props || {}));
|
2015-07-16 23:01:44 +08:00
|
|
|
|
};
|
|
|
|
|
happen.drag = function (fromX, fromY, toX, toY, then, duration) {
|
|
|
|
|
happen.at('mousemove', fromX, fromY);
|
|
|
|
|
happen.at('mousedown', fromX, fromY);
|
|
|
|
|
var moveX = function () {
|
|
|
|
|
if (fromX <= toX) {
|
|
|
|
|
happen.at('mousemove', fromX++, fromY);
|
|
|
|
|
window.setTimeout(moveX, 5);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
moveX();
|
|
|
|
|
var moveY = function () {
|
|
|
|
|
if (fromY <= toY) {
|
|
|
|
|
happen.at('mousemove', fromX, fromY++);
|
|
|
|
|
window.setTimeout(moveY, 5);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
moveY();
|
|
|
|
|
window.setTimeout(function () {
|
|
|
|
|
happen.at('mouseup', toX, toY);
|
|
|
|
|
happen.at('click', toX, toY);
|
|
|
|
|
if (then) { then(); }
|
|
|
|
|
}, duration || 100);
|
|
|
|
|
};
|