Skip to content

Commit

Permalink
chore(sideMenuContent): cleanup element reference
Browse files Browse the repository at this point in the history
Clean up element reference on line 194, and some style() updates.
  • Loading branch information
adamdbradley committed Oct 10, 2014
1 parent bc4c696 commit 5dda980
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions js/angular/directive/sideMenuContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ function($timeout, $ionicGesture, $window) {
require: '^ionSideMenus',
scope: true,
compile: function(element, attr) {
element.addClass('menu-content pane');

return { pre: prelink };
function prelink($scope, $element, $attr, sideMenuCtrl) {
var startCoord = null;
var primaryScrollAxis = null;

$element.addClass('menu-content pane');

if (isDefined(attr.dragContent)) {
$scope.$watch(attr.dragContent, function(value) {
sideMenuCtrl.canDragContent(value);
Expand All @@ -61,27 +61,27 @@ function($timeout, $ionicGesture, $window) {

// Listen for taps on the content to close the menu
function onContentTap(gestureEvt) {
if(sideMenuCtrl.getOpenAmount() !== 0) {
if (sideMenuCtrl.getOpenAmount() !== 0) {
sideMenuCtrl.close();
gestureEvt.gesture.srcEvent.preventDefault();
startCoord = null;
primaryScrollAxis = null;
} else if(!startCoord) {
} else if (!startCoord) {
startCoord = ionic.tap.pointerCoord(gestureEvt.gesture.srcEvent);
}
}

function onDragX(e) {
if(!sideMenuCtrl.isDraggableTarget(e)) return;
if (!sideMenuCtrl.isDraggableTarget(e)) return;

if( getPrimaryScrollAxis(e) == 'x') {
if ( getPrimaryScrollAxis(e) == 'x') {
sideMenuCtrl._handleDrag(e);
e.gesture.srcEvent.preventDefault();
}
}

function onDragY(e) {
if( getPrimaryScrollAxis(e) == 'x' ) {
if ( getPrimaryScrollAxis(e) == 'x' ) {
e.gesture.srcEvent.preventDefault();
}
}
Expand All @@ -97,14 +97,14 @@ function($timeout, $ionicGesture, $window) {
// If a majority of the drag has been on the Y since the start of
// the drag, but the X has moved a little bit, it's still a Y drag

if(primaryScrollAxis) {
if (primaryScrollAxis) {
// we already figured out which way they're scrolling
return primaryScrollAxis;
}

if(gestureEvt && gestureEvt.gesture) {
if (gestureEvt && gestureEvt.gesture) {

if(!startCoord) {
if (!startCoord) {
// get the starting point
startCoord = ionic.tap.pointerCoord(gestureEvt.gesture.srcEvent);

Expand All @@ -117,7 +117,7 @@ function($timeout, $ionicGesture, $window) {

var scrollAxis = ( xDistance < yDistance ? 'y' : 'x' );

if( Math.max(xDistance, yDistance) > 30 ) {
if ( Math.max(xDistance, yDistance) > 30 ) {
// ok, we pretty much know which way they're going
// let's lock it in
primaryScrollAxis = scrollAxis;
Expand All @@ -144,7 +144,7 @@ function($timeout, $ionicGesture, $window) {
});
}),
setMarginLeft: ionic.animationFrameThrottle(function(amount) {
if(amount) {
if (amount) {
amount = parseInt(amount, 10);
$element[0].style[ionic.CSS.TRANSFORM] = 'translate3d(' + amount + 'px,0,0)';
$element[0].style.width = ($window.innerWidth - amount) + 'px';
Expand All @@ -156,7 +156,7 @@ function($timeout, $ionicGesture, $window) {
}
}),
setMarginRight: ionic.animationFrameThrottle(function(amount) {
if(amount) {
if (amount) {
amount = parseInt(amount, 10);
$element[0].style.width = ($window.innerWidth - amount) + 'px';
content.offsetX = amount;
Expand Down Expand Up @@ -191,6 +191,10 @@ function($timeout, $ionicGesture, $window) {

// Cleanup
$scope.$on('$destroy', function() {
if (content) {
content.element = null;
content = null;
}
$ionicGesture.off(dragLeftGesture, 'dragleft', onDragX);
$ionicGesture.off(dragRightGesture, 'dragright', onDragX);
$ionicGesture.off(dragUpGesture, 'dragup', onDragY);
Expand Down

0 comments on commit 5dda980

Please sign in to comment.