mirror of
https://github.com/konvajs/konva.git
synced 2026-01-23 21:34:50 +08:00
small refactoring
This commit is contained in:
131
test/runner.js
131
test/runner.js
@@ -89,7 +89,7 @@ function addStats() {
|
||||
|
||||
function addStage(attrs) {
|
||||
var container = document.createElement('div');
|
||||
const props = Object.assign(
|
||||
const props = Konva.Util._assign(
|
||||
{
|
||||
container: container,
|
||||
width: 578,
|
||||
@@ -292,16 +292,20 @@ Konva.Stage.prototype.simulateTouchStart = function(pos, changed) {
|
||||
var touches;
|
||||
var changedTouches;
|
||||
if (Array.isArray(pos)) {
|
||||
touches = pos.map(touch => ({
|
||||
identifier: touch.id,
|
||||
clientX: touch.x,
|
||||
clientY: touch.y + top
|
||||
}));
|
||||
changedTouches = (changed || pos).map(touch => ({
|
||||
identifier: touch.id,
|
||||
clientX: touch.x,
|
||||
clientY: touch.y + top
|
||||
}));
|
||||
touches = pos.map(function(touch) {
|
||||
return {
|
||||
identifier: touch.id,
|
||||
clientX: touch.x,
|
||||
clientY: touch.y + top
|
||||
}
|
||||
});
|
||||
changedTouches = (changed || pos).map(function(touch) {
|
||||
return {
|
||||
identifier: touch.id,
|
||||
clientX: touch.x,
|
||||
clientY: touch.y + top
|
||||
}
|
||||
});
|
||||
} else {
|
||||
changedTouches = touches = [
|
||||
{
|
||||
@@ -325,16 +329,20 @@ Konva.Stage.prototype.simulateTouchMove = function(pos, changed) {
|
||||
var touches;
|
||||
var changedTouches;
|
||||
if (Array.isArray(pos)) {
|
||||
touches = pos.map(touch => ({
|
||||
identifier: touch.id,
|
||||
clientX: touch.x,
|
||||
clientY: touch.y + top
|
||||
}));
|
||||
changedTouches = (changed || pos).map(touch => ({
|
||||
identifier: touch.id,
|
||||
clientX: touch.x,
|
||||
clientY: touch.y + top
|
||||
}));
|
||||
touches = pos.map(function(touch) {
|
||||
return {
|
||||
identifier: touch.id,
|
||||
clientX: touch.x,
|
||||
clientY: touch.y + top
|
||||
}
|
||||
});
|
||||
changedTouches = (changed || pos).map(function(touch) {
|
||||
return {
|
||||
identifier: touch.id,
|
||||
clientX: touch.x,
|
||||
clientY: touch.y + top
|
||||
}
|
||||
});
|
||||
} else {
|
||||
changedTouches = touches = [
|
||||
{
|
||||
@@ -359,16 +367,20 @@ Konva.Stage.prototype.simulateTouchEnd = function(pos, changed) {
|
||||
var touches;
|
||||
var changedTouches;
|
||||
if (Array.isArray(pos)) {
|
||||
touches = pos.map(touch => ({
|
||||
identifier: touch.id,
|
||||
clientX: touch.x,
|
||||
clientY: touch.y + top
|
||||
}));
|
||||
changedTouches = (changed || pos).map(touch => ({
|
||||
identifier: touch.id,
|
||||
clientX: touch.x,
|
||||
clientY: touch.y + top
|
||||
}));
|
||||
touches = pos.map(function(touch) {
|
||||
return {
|
||||
identifier: touch.id,
|
||||
clientX: touch.x,
|
||||
clientY: touch.y + top
|
||||
}
|
||||
});
|
||||
changedTouches = (changed || pos).map(function(touch) {
|
||||
return {
|
||||
identifier: touch.id,
|
||||
clientX: touch.x,
|
||||
clientY: touch.y + top
|
||||
}
|
||||
});
|
||||
} else {
|
||||
changedTouches = touches = [
|
||||
{
|
||||
@@ -429,3 +441,60 @@ Konva.Stage.prototype.simulatePointerUp = function(pos) {
|
||||
};
|
||||
|
||||
init();
|
||||
|
||||
|
||||
// polyfills
|
||||
if (!Array.prototype.find) {
|
||||
Object.defineProperty(Array.prototype, 'find', {
|
||||
value: function(predicate) {
|
||||
// 1. Let O be ? ToObject(this value).
|
||||
if (this == null) {
|
||||
throw TypeError('"this" is null or not defined');
|
||||
}
|
||||
|
||||
var o = Object(this);
|
||||
|
||||
// 2. Let len be ? ToLength(? Get(O, "length")).
|
||||
var len = o.length >>> 0;
|
||||
|
||||
// 3. If IsCallable(predicate) is false, throw a TypeError exception.
|
||||
if (typeof predicate !== 'function') {
|
||||
throw TypeError('predicate must be a function');
|
||||
}
|
||||
|
||||
// 4. If thisArg was supplied, let T be thisArg; else let T be undefined.
|
||||
var thisArg = arguments[1];
|
||||
|
||||
// 5. Let k be 0.
|
||||
var k = 0;
|
||||
|
||||
// 6. Repeat, while k < len
|
||||
while (k < len) {
|
||||
// a. Let Pk be ! ToString(k).
|
||||
// b. Let kValue be ? Get(O, Pk).
|
||||
// c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)).
|
||||
// d. If testResult is true, return kValue.
|
||||
var kValue = o[k];
|
||||
if (predicate.call(thisArg, kValue, k, o)) {
|
||||
return kValue;
|
||||
}
|
||||
// e. Increase k by 1.
|
||||
k++;
|
||||
}
|
||||
|
||||
// 7. Return undefined.
|
||||
return undefined;
|
||||
},
|
||||
configurable: true,
|
||||
writable: true
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
String.prototype.trimRight = String.prototype.trimRight || function polyfill() {
|
||||
return this.replace(/[\s\xa0]+$/, '');
|
||||
}
|
||||
|
||||
String.prototype.trimLeft = String.prototype.trimLeft || function polyfill() {
|
||||
return this.replace(/^\s+/, '');
|
||||
}
|
||||
Reference in New Issue
Block a user