mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
chore(sideMenuContent): cleanup element reference
Clean up element reference on line 194, and some style() updates.
This commit is contained in:
30
js/angular/directive/sideMenuContent.js
vendored
30
js/angular/directive/sideMenuContent.js
vendored
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user