Merge pull request #98 from jakeswenson/dev

fix issues with transformation parsing and issues with touch items when ...
master
Dmitry Baranovskiy 2013-11-26 22:09:32 -08:00
commit c3134f596b
2 changed files with 34 additions and 26 deletions

View File

@ -45,27 +45,37 @@ Snap.plugin(function (Snap, Element, Paper, glob) {
if (glob.doc.addEventListener) { if (glob.doc.addEventListener) {
return function (obj, type, fn, element) { return function (obj, type, fn, element) {
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, if (supportsTouch && touchMap[has](type)) {
y = e.clientY + scrollY; for (var i = 0, ii = e.targetTouches && e.targetTouches.length; i < ii; i++) {
if (supportsTouch && touchMap[has](type)) { if (e.targetTouches[i].target == obj || obj.contains(e.targetTouches[i].target)) {
for (var i = 0, ii = e.targetTouches && e.targetTouches.length; i < ii; i++) { var olde = e;
if (e.targetTouches[i].target == obj) { e = e.targetTouches[i];
var olde = e; e.originalEvent = olde;
e = e.targetTouches[i]; e.preventDefault = preventTouch;
e.originalEvent = olde; e.stopPropagation = stopTouch;
e.preventDefault = preventTouch; break;
e.stopPropagation = stopTouch; }
break; }
}
} }
} var x = e.clientX + scrollX,
return fn.call(element, e, x, y); y = e.clientY + scrollY;
}; 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});

View File

@ -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);
} }