Commit 3742b46f by Tomas Alabes

Merge branch 'fix-touch-events' of github.com:Touchit/raphael into Touchit-fix-touch-events

* 'fix-touch-events' of github.com:Touchit/raphael:
  Fix Touch events selection in dragMove method
  Fix Gruntfile to build in windows environment
  Fix Touch events on Firefox and Chrome

Conflicts:
	raphael-min.js
	raphael.js
parents aad6517f c5ffca37
...@@ -55,7 +55,7 @@ module.exports = function(grunt) { ...@@ -55,7 +55,7 @@ module.exports = function(grunt) {
svgorvmlRegex = /\.(svg|vml)\.js/, svgorvmlRegex = /\.(svg|vml)\.js/,
closureRegex = /window\.Raphael.*\(R\)\s*\{/, closureRegex = /window\.Raphael.*\(R\)\s*\{/,
closureEndRegex = /\}\(window\.Raphael\);\s*$/, closureEndRegex = /\}\(window\.Raphael\);\s*$/,
exposeRegex = /(\n\s*\/\/\s*EXPOSE(?:\n|.)*\}\)\);)/; exposeRegex = /(\r?\n\s*\/\/\s*EXPOSE(?:\r|\n|.)*\}\)\);)/;
// Concatenate src // Concatenate src
src.forEach(function(path) { src.forEach(function(path) {
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -2692,19 +2692,31 @@ ...@@ -2692,19 +2692,31 @@
stopTouch = function () { stopTouch = function () {
return this.originalEvent.stopPropagation(); return this.originalEvent.stopPropagation();
}, },
getEventPosition = function (e) {
var scrollY = g.doc.documentElement.scrollTop || g.doc.body.scrollTop,
scrollX = g.doc.documentElement.scrollLeft || g.doc.body.scrollLeft;
return {
x: e.clientX + scrollX,
y: e.clientY + scrollY
};
},
addEvent = (function () { addEvent = (function () {
if (g.doc.addEventListener) { if (g.doc.addEventListener) {
return function (obj, type, fn, element) { return function (obj, type, fn, element) {
var realName = supportsTouch && touchMap[type] ? touchMap[type] : type, var f = function (e) {
f = function (e) { var pos = getEventPosition(e);
var scrollY = g.doc.documentElement.scrollTop || g.doc.body.scrollTop, return fn.call(element, e, pos.x, pos.y);
scrollX = g.doc.documentElement.scrollLeft || g.doc.body.scrollLeft, };
x = e.clientX + scrollX, obj.addEventListener(type, f, false);
y = e.clientY + scrollY;
if (supportsTouch && touchMap[has](type)) { if (supportsTouch && touchMap[type]) {
var _f = function (e) {
var pos = getEventPosition(e),
olde = e;
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) {
var olde = e;
e = e.targetTouches[i]; e = e.targetTouches[i];
e.originalEvent = olde; e.originalEvent = olde;
e.preventDefault = preventTouch; e.preventDefault = preventTouch;
...@@ -2712,12 +2724,18 @@ ...@@ -2712,12 +2724,18 @@
break; break;
} }
} }
}
return fn.call(element, e, x, y); return fn.call(element, e, pos.x, pos.y);
}; };
obj.addEventListener(realName, f, false); obj.addEventListener(touchMap[type], _f, false);
}
return function () { return function () {
obj.removeEventListener(realName, f, false); obj.removeEventListener(type, f, false);
if (supportsTouch && touchMap[type])
obj.removeEventListener(touchMap[type], f, false);
return true; return true;
}; };
}; };
...@@ -2752,7 +2770,7 @@ ...@@ -2752,7 +2770,7 @@
j = drag.length; j = drag.length;
while (j--) { while (j--) {
dragi = drag[j]; dragi = drag[j];
if (supportsTouch) { if (supportsTouch && e.touches) {
var i = e.touches.length, var i = e.touches.length,
touch; touch;
while (i--) { while (i--) {
......
...@@ -3071,19 +3071,31 @@ ...@@ -3071,19 +3071,31 @@
stopTouch = function () { stopTouch = function () {
return this.originalEvent.stopPropagation(); return this.originalEvent.stopPropagation();
}, },
getEventPosition = function (e) {
var scrollY = g.doc.documentElement.scrollTop || g.doc.body.scrollTop,
scrollX = g.doc.documentElement.scrollLeft || g.doc.body.scrollLeft;
return {
x: e.clientX + scrollX,
y: e.clientY + scrollY
};
},
addEvent = (function () { addEvent = (function () {
if (g.doc.addEventListener) { if (g.doc.addEventListener) {
return function (obj, type, fn, element) { return function (obj, type, fn, element) {
var realName = supportsTouch && touchMap[type] ? touchMap[type] : type, var f = function (e) {
f = function (e) { var pos = getEventPosition(e);
var scrollY = g.doc.documentElement.scrollTop || g.doc.body.scrollTop, return fn.call(element, e, pos.x, pos.y);
scrollX = g.doc.documentElement.scrollLeft || g.doc.body.scrollLeft, };
x = e.clientX + scrollX, obj.addEventListener(type, f, false);
y = e.clientY + scrollY;
if (supportsTouch && touchMap[has](type)) { if (supportsTouch && touchMap[type]) {
var _f = function (e) {
var pos = getEventPosition(e),
olde = e;
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) {
var olde = e;
e = e.targetTouches[i]; e = e.targetTouches[i];
e.originalEvent = olde; e.originalEvent = olde;
e.preventDefault = preventTouch; e.preventDefault = preventTouch;
...@@ -3091,12 +3103,19 @@ ...@@ -3091,12 +3103,19 @@
break; break;
} }
} }
}
return fn.call(element, e, x, y); return fn.call(element, e, pos.x, pos.y);
}; };
obj.addEventListener(realName, f, false);
obj.addEventListener(touchMap[type], _f, false);
}
return function () { return function () {
obj.removeEventListener(realName, f, false); obj.removeEventListener(type, f, false);
if (supportsTouch && touchMap[type])
obj.removeEventListener(touchMap[type], f, false);
return true; return true;
}; };
}; };
...@@ -3131,7 +3150,7 @@ ...@@ -3131,7 +3150,7 @@
j = drag.length; j = drag.length;
while (j--) { while (j--) {
dragi = drag[j]; dragi = drag[j];
if (supportsTouch) { if (supportsTouch && e.touches) {
var i = e.touches.length, var i = e.touches.length,
touch; touch;
while (i--) { while (i--) {
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
<script type="text/javascript"> <script type="text/javascript">
// Initialize container when document is loaded // Initialize container when document is loaded
window.onload = function(){ window.onload = function () {
paper = Raphael(0, 0, 640, 720, "container"); paper = Raphael(0, 0, 640, 720, "container");
}; };
//Work here, in a separate script file or via command line //Work here, in a separate script file or via command line
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
</head> </head>
<body> <body>
<!-- Container for svg/vml root element --> <!-- Container for svg/vml root element -->
<div id="container"></div> <div id="container"></div>
</body> </body>
</html> </html>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment