From 5dda9802726ed556423862c985a9546c91d3e9d0 Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Thu, 9 Oct 2014 21:02:16 -0500 Subject: [PATCH] chore(sideMenuContent): cleanup element reference Clean up element reference on line 194, and some style() updates. --- js/angular/directive/sideMenuContent.js | 30 ++++++++++++++----------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/js/angular/directive/sideMenuContent.js b/js/angular/directive/sideMenuContent.js index 13ed207124..0f286717a8 100644 --- a/js/angular/directive/sideMenuContent.js +++ b/js/angular/directive/sideMenuContent.js @@ -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); @@ -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(); } } @@ -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); @@ -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; @@ -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'; @@ -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; @@ -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);