Merge pull request #98 from jakeswenson/dev
fix issues with transformation parsing and issues with touch items when ...master
commit
c3134f596b
32
src/mouse.js
32
src/mouse.js
|
@ -47,12 +47,10 @@ Snap.plugin(function (Snap, Element, Paper, glob) {
|
||||||
var realName = supportsTouch && touchMap[type] ? touchMap[type] : type,
|
var realName = supportsTouch && touchMap[type] ? touchMap[type] : type,
|
||||||
f = function (e) {
|
f = function (e) {
|
||||||
var scrollY = getScroll("y"),
|
var scrollY = getScroll("y"),
|
||||||
scrollX = getScroll("x"),
|
scrollX = getScroll("x");
|
||||||
x = e.clientX + scrollX,
|
|
||||||
y = e.clientY + scrollY;
|
|
||||||
if (supportsTouch && touchMap[has](type)) {
|
if (supportsTouch && touchMap[has](type)) {
|
||||||
for (var i = 0, ii = e.targetTouches && e.targetTouches.length; i < ii; i++) {
|
for (var i = 0, ii = e.targetTouches && e.targetTouches.length; i < ii; i++) {
|
||||||
if (e.targetTouches[i].target == obj) {
|
if (e.targetTouches[i].target == obj || obj.contains(e.targetTouches[i].target)) {
|
||||||
var olde = e;
|
var olde = e;
|
||||||
e = e.targetTouches[i];
|
e = e.targetTouches[i];
|
||||||
e.originalEvent = olde;
|
e.originalEvent = olde;
|
||||||
|
@ -62,10 +60,22 @@ Snap.plugin(function (Snap, Element, Paper, glob) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
var x = e.clientX + scrollX,
|
||||||
|
y = e.clientY + scrollY;
|
||||||
return fn.call(element, e, x, y);
|
return fn.call(element, e, x, y);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (type !== realName) {
|
||||||
|
obj.addEventListener(type, f, false);
|
||||||
|
}
|
||||||
|
|
||||||
obj.addEventListener(realName, f, false);
|
obj.addEventListener(realName, f, false);
|
||||||
|
|
||||||
return function () {
|
return function () {
|
||||||
|
if (type !== realName) {
|
||||||
|
obj.removeEventListener(type, f, false);
|
||||||
|
}
|
||||||
|
|
||||||
obj.removeEventListener(realName, f, false);
|
obj.removeEventListener(realName, f, false);
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
@ -102,11 +112,11 @@ Snap.plugin(function (Snap, Element, Paper, glob) {
|
||||||
while (j--) {
|
while (j--) {
|
||||||
dragi = drag[j];
|
dragi = drag[j];
|
||||||
if (supportsTouch) {
|
if (supportsTouch) {
|
||||||
var i = e.touches.length,
|
var i = e.touches && e.touches.length,
|
||||||
touch;
|
touch;
|
||||||
while (i--) {
|
while (i--) {
|
||||||
touch = e.touches[i];
|
touch = e.touches[i];
|
||||||
if (touch.identifier == dragi.el._drag.id) {
|
if (touch.identifier == dragi.el._drag.id || dragi.el.node.contains(touch.target)) {
|
||||||
x = touch.clientX;
|
x = touch.clientX;
|
||||||
y = touch.clientY;
|
y = touch.clientY;
|
||||||
(e.originalEvent ? e.originalEvent : e).preventDefault();
|
(e.originalEvent ? e.originalEvent : e).preventDefault();
|
||||||
|
@ -430,19 +440,17 @@ Snap.plugin(function (Snap, Element, Paper, glob) {
|
||||||
origTransform = this.transform().local;
|
origTransform = this.transform().local;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function start(e) {
|
function start(e, x, y) {
|
||||||
(e.originalEvent || e).preventDefault();
|
(e.originalEvent || e).preventDefault();
|
||||||
var scrollY = getScroll("y"),
|
this._drag.x = x;
|
||||||
scrollX = getScroll("x");
|
this._drag.y = y;
|
||||||
this._drag.x = e.clientX + scrollX;
|
|
||||||
this._drag.y = e.clientY + scrollY;
|
|
||||||
this._drag.id = e.identifier;
|
this._drag.id = e.identifier;
|
||||||
!drag.length && Snap.mousemove(dragMove).mouseup(dragUp);
|
!drag.length && Snap.mousemove(dragMove).mouseup(dragUp);
|
||||||
drag.push({el: this, move_scope: move_scope, start_scope: start_scope, end_scope: end_scope});
|
drag.push({el: this, move_scope: move_scope, start_scope: start_scope, end_scope: end_scope});
|
||||||
onstart && eve.on("snap.drag.start." + this.id, onstart);
|
onstart && eve.on("snap.drag.start." + this.id, onstart);
|
||||||
onmove && eve.on("snap.drag.move." + this.id, onmove);
|
onmove && eve.on("snap.drag.move." + this.id, onmove);
|
||||||
onend && eve.on("snap.drag.end." + this.id, onend);
|
onend && eve.on("snap.drag.end." + this.id, onend);
|
||||||
eve("snap.drag.start." + this.id, start_scope || move_scope || this, e.clientX + scrollX, e.clientY + scrollY, e);
|
eve("snap.drag.start." + this.id, start_scope || move_scope || this, x, y, e);
|
||||||
}
|
}
|
||||||
this._drag = {};
|
this._drag = {};
|
||||||
draggable.push({el: this, start: start});
|
draggable.push({el: this, start: start});
|
||||||
|
|
|
@ -1124,7 +1124,7 @@ var parseTransformString = Snap.parseTransformString = function (TString) {
|
||||||
function svgTransform2string(tstr) {
|
function svgTransform2string(tstr) {
|
||||||
var res = [];
|
var res = [];
|
||||||
tstr = tstr.replace(/(?:^|\s)(\w+)\(([^)]+)\)/g, function (all, name, params) {
|
tstr = tstr.replace(/(?:^|\s)(\w+)\(([^)]+)\)/g, function (all, name, params) {
|
||||||
params = params.split(/\s*,\s*/);
|
params = params.split(/\s*,\s*|\s+/);
|
||||||
if (name == "rotate" && params.length == 1) {
|
if (name == "rotate" && params.length == 1) {
|
||||||
params.push(0, 0);
|
params.push(0, 0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue