diff --git a/js/utils/gestures.js b/js/utils/gestures.js index 0ed1ef442a6..99b48aa4480 100644 --- a/js/utils/gestures.js +++ b/js/utils/gestures.js @@ -391,7 +391,7 @@ } // make fake touchlist from mouse position else { - ev.indentifier = 1; + ev.identifier = 1; return [ev]; } }, diff --git a/js/views/scrollView.js b/js/views/scrollView.js index 6efce93ebe2..101ed152975 100644 --- a/js/views/scrollView.js +++ b/js/views/scrollView.js @@ -848,7 +848,7 @@ ionic.views.Scroll = ionic.views.View.inherit({ self.hintResize(); self.scrollBy( - e.wheelDeltaX/self.options.wheelDampen, + e.wheelDeltaX/self.options.wheelDampen, -e.wheelDeltaY/self.options.wheelDampen ); @@ -1585,6 +1585,9 @@ ionic.views.Scroll = ionic.views.View.inherit({ self.__initialTouchLeft = currentTouchLeft; self.__initialTouchTop = currentTouchTop; + // Store initial touchList for scale calculation + self.__initialTouches = touches; + // Store current zoom level self.__zoomLevelStart = self.__zoomLevel; @@ -1644,6 +1647,11 @@ ionic.views.Scroll = ionic.views.View.inherit({ if (touches.length === 2) { currentTouchLeft = Math.abs(touches[0].pageX + touches[1].pageX) / 2; currentTouchTop = Math.abs(touches[0].pageY + touches[1].pageY) / 2; + + // Calculate scale when not present and only when touches are used + if (!scale && self.options.zooming) { + scale = self.__getScale(self.__initialTouches, touches); + } } else { currentTouchLeft = touches[0].pageX; currentTouchTop = touches[0].pageY; @@ -2255,6 +2263,39 @@ ionic.views.Scroll = ionic.views.View.inherit({ } } } + }, + + + /** + * calculate the distance between two touches + * @param {Touch} touch1 + * @param {Touch} touch2 + * @returns {Number} distance + */ + __getDistance: function getDistance(touch1, touch2) { + var x = touch2.pageX - touch1.pageX, + y = touch2.pageY - touch1.pageY; + return Math.sqrt((x*x) + (y*y)); + }, + + + /** + * calculate the scale factor between two touchLists (fingers) + * no scale is 1, and goes down to 0 when pinched together, and bigger when pinched out + * @param {Array} start + * @param {Array} end + * @returns {Number} scale + */ + __getScale: function getScale(start, end) { + + var self = this; + + // need two fingers... + if(start.length >= 2 && end.length >= 2) { + return self.__getDistance(end[0], end[1]) / + self.__getDistance(start[0], start[1]); + } + return 1; } });