Side menu content scoping fix

This commit is contained in:
Max Lynch
2013-10-04 10:16:50 -05:00
parent 48c716af1e
commit 1212945df8
5 changed files with 147 additions and 104 deletions

View File

@ -17,13 +17,15 @@
this._leftShowing = false;
this._isDragging = false;
this.content.onDrag = function(e) {
self._handleDrag(e);
};
if(this.content) {
this.content.onDrag = function(e) {
self._handleDrag(e);
};
this.content.endDrag = function(e) {
self._endDrag(e);
};
this.content.endDrag = function(e) {
self._endDrag(e);
};
}
};
ionic.controllers.SideMenuController.prototype = {
@ -33,7 +35,17 @@
* @param {object} content
*/
setContent: function(content) {
var self = this;
this.content = content;
this.content.onDrag = function(e) {
self._handleDrag(e);
};
this.content.endDrag = function(e) {
self._endDrag(e);
};
},
/**

View File

@ -25,33 +25,6 @@ angular.module('ionic.ui.sideMenu', [])
bringUp: function() {
$scope.rightZIndex = 0;
}
},
content: {
onDrag: function(e) {},
endDrag: function(e) {},
getTranslateX: function() {
/*
var r = /translate3d\((-?.+)px/;
var d = r.exec(this.el.style.webkitTransform);
if(d && d.length > 0) {
return parseFloat(d[1]);
}
*/
return $scope.contentTranslateX || 0;
},
setTranslateX: function(amount) {
$scope.contentTranslateX = amount;
$scope.$apply();
},
enableAnimation: function() {
//this.el.classList.add(this.animateClass);
$scope.animationEnabled = true;
},
disableAnimation: function() {
//this.el.classList.remove(this.animateClass);
$scope.animationEnabled = false;
}
}
});
@ -64,7 +37,7 @@ angular.module('ionic.ui.sideMenu', [])
controller: 'SideMenuCtrl',
replace: true,
transclude: true,
template: '<div class="view"><div ng-transclude></div></div>',
template: '<div class="view" ng-transclude></div>',
}
})
@ -72,6 +45,7 @@ angular.module('ionic.ui.sideMenu', [])
return {
restrict: 'CA',
require: '^sideMenuCtrl',
scope: true,
compile: function(element, attr, transclude) {
return function($scope, $element, $attr, sideMenuCtrl) {
window.ionic.onGesture('drag', function(e) {
@ -82,17 +56,27 @@ angular.module('ionic.ui.sideMenu', [])
sideMenuCtrl._endDrag(e);
}, $element[0]);
$scope.$watch('contentTranslateX', function(value) {
$element[0].style.webkitTransform = 'translate3d(' + value + 'px, 0, 0)';
});
$scope.$watch('animationEnabled', function(isAnimationEnabled) {
if(isAnimationEnabled) {
sideMenuCtrl.setContent({
onDrag: function(e) {},
endDrag: function(e) {},
getTranslateX: function() {
return $scope.contentTranslateX || 0;
},
setTranslateX: function(amount) {
$scope.contentTranslateX = amount;
$scope.$apply();
$element[0].style.webkitTransform = 'translate3d(' + amount + 'px, 0, 0)';
},
enableAnimation: function() {
//this.el.classList.add(this.animateClass);
$scope.animationEnabled = true;
$element[0].classList.add('menu-animated');
} else {
},
disableAnimation: function() {
//this.el.classList.remove(this.animateClass);
$scope.animationEnabled = false;
$element[0].classList.remove('menu-animated');
}
});
};
}