feat($ionicBody): service to simplify body ele interaction

Many services/directives have to interact with the body element, and
each one has to write the same long code. The $ionicBody service
provides some useful methods to clean up and reduce redundant code.
This commit is contained in:
Adam Bradley
2014-08-26 22:23:07 -05:00
parent b69aa5485f
commit 2c3f1c9f02
10 changed files with 203 additions and 45 deletions

View File

@@ -4,8 +4,8 @@ IonicModule
'$attrs',
'$ionicSideMenuDelegate',
'$ionicPlatform',
'$document',
function($scope, $attrs, $ionicSideMenuDelegate, $ionicPlatform, $document) {
'$ionicBody',
function($scope, $attrs, $ionicSideMenuDelegate, $ionicPlatform, $ionicBody) {
var self = this;
var rightShowing, leftShowing, isDragging;
var startX, lastX, offsetX, isAsideExposed;
@@ -132,11 +132,9 @@ function($scope, $attrs, $ionicSideMenuDelegate, $ionicPlatform, $document) {
self.openAmount(self.right.width * p);
}
if(percentage !== 0) {
$document[0].body.classList.add('menu-open');
} else {
$document[0].body.classList.remove('menu-open');
}
// add the CSS class "menu-open" if the percentage does not
// equal 0, otherwise remove the class from the body element
$ionicBody.enableClass( (percentage !== 0), 'menu-open');
};
/**
@@ -269,11 +267,7 @@ function($scope, $attrs, $ionicSideMenuDelegate, $ionicPlatform, $document) {
};
self.activeAsideResizing = function(isResizing) {
if(isResizing) {
$document[0].body.classList.add('aside-resizing');
} else {
$document[0].body.classList.remove('aside-resizing');
}
$ionicBody.enableClass(isResizing, 'aside-resizing');
};
// End a drag with the given event