[Mobile} Pan/Pinch

Cleaned up the variables.
This commit is contained in:
Shivam Dave 2015-08-28 16:01:00 -07:00
parent bdf3e4d8a3
commit a45b09277e
2 changed files with 19 additions and 16 deletions

View File

@ -51,7 +51,7 @@
{ {
"key": "mctPinch", "key": "mctPinch",
"implementation": "directives/MCTPinch.js", "implementation": "directives/MCTPinch.js",
"depends": [ "$log", "agentService" ] "depends": [ "agentService" ]
} }
], ],
"controllers": [ "controllers": [

View File

@ -26,10 +26,9 @@ define(
function () { function () {
"use strict"; "use strict";
function MCTPinch($log, agentService) { function MCTPinch(agentService) {
function link($scope, element, attrs) {
function link($scope, element) {
// Returns position of touch event // Returns position of touch event
function trackPosition(event) { function trackPosition(event) {
return { return {
@ -55,23 +54,25 @@ define(
// On touch start the 'touch' is tracked and // On touch start the 'touch' is tracked and
// the event is emitted through scope // the event is emitted through scope
function touchStart(event) { function touchStart(event) {
var touchPosition;
if (event.changedTouches.length === 2 || if (event.changedTouches.length === 2 ||
event.touches.length === 2) { event.touches.length === 2) {
var touchPositions = [trackPosition(event.touches[0]), touchPosition = [trackPosition(event.touches[0]),
trackPosition(event.touches[1])]; trackPosition(event.touches[1])];
$scope.$emit('mct:pinch:start', { $scope.$emit('mct:pinch:start', {
touches: touchPositions, touches: touchPosition,
bounds: event.target.getBoundingClientRect(), bounds: event.target.getBoundingClientRect(),
midpoint: calculateMidpoint(touchPositions[0], touchPositions[1]), midpoint: calculateMidpoint(touchPosition[0], touchPosition[1]),
distance: calculateDistance(touchPositions[0], touchPositions[1]) distance: calculateDistance(touchPosition[0], touchPosition[1])
}); });
// Stops other gestures/button clicks from being active // Stops other gestures/button clicks from being active
event.preventDefault(); event.preventDefault();
} else if (event.changedTouches.length === 1 || } else if (event.changedTouches.length === 1 ||
event.touches.length === 1) { event.touches.length === 1) {
var touchPosition = trackPosition(event.touches[0]); touchPosition = trackPosition(event.touches[0]);
$scope.$emit('mct:pan:start', { $scope.$emit('mct:pan:start', {
touch: touchPosition, touch: touchPosition,
@ -86,21 +87,23 @@ define(
// As the touch move occurs, the touches are tracked and // As the touch move occurs, the touches are tracked and
// the event is emitted through scope // the event is emitted through scope
function touchChange(event) { function touchChange(event) {
var touchPosition;
if (event.changedTouches.length === 2) { if (event.changedTouches.length === 2) {
var touchPositions = [trackPosition(event.changedTouches[0]), touchPosition = [trackPosition(event.changedTouches[0]),
trackPosition(event.changedTouches[1])]; trackPosition(event.changedTouches[1])];
$scope.$emit('mct:pinch:change', { $scope.$emit('mct:pinch:change', {
touches: touchPositions, touches: touchPosition,
bounds: event.target.getBoundingClientRect(), bounds: event.target.getBoundingClientRect(),
midpoint: calculateMidpoint(touchPositions[0], touchPositions[1]), midpoint: calculateMidpoint(touchPosition[0], touchPosition[1]),
distance: calculateDistance(touchPositions[0], touchPositions[1]) distance: calculateDistance(touchPosition[0], touchPosition[1])
}); });
// Stops other gestures/button clicks from being active // Stops other gestures/button clicks from being active
event.preventDefault(); event.preventDefault();
} else if (event.changedTouches.length === 1) { } else if (event.changedTouches.length === 1) {
var touchPosition = trackPosition(event.changedTouches[0]); touchPosition = trackPosition(event.changedTouches[0]);
$scope.$emit('mct:pan:change', { $scope.$emit('mct:pan:change', {
touch: touchPosition, touch: touchPosition,