forked from ionic-team/ionic-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenuToggle.js
More file actions
60 lines (59 loc) · 1.82 KB
/
menuToggle.js
File metadata and controls
60 lines (59 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/**
* @ngdoc directive
* @name menuToggle
* @module ionic
* @restrict AC
*
* @description
* Toggle a side menu on the given side.
*
* @usage
* Below is an example of a link within a nav bar. Tapping this button
* would open the given side menu, and tapping it again would close it.
*
* ```html
* <ion-nav-bar>
* <ion-nav-buttons side="left">
* <!-- Toggle left side menu -->
* <button menu-toggle="left" class="button button-icon icon ion-navicon"></button>
* </ion-nav-buttons>
* <ion-nav-buttons side="right">
* <!-- Toggle right side menu -->
* <button menu-toggle="right" class="button button-icon icon ion-navicon"></button>
* </ion-nav-buttons>
* </ion-nav-bar>
* ```
*
* ### Button Hidden On Child Views
* By default, the menu toggle button will only appear on a root
* level side-menu page. Navigating in to child views will hide the menu-
* toggle button. They can be made visible on child pages by setting the
* enable-menu-with-back-views attribute of the {@link ionic.directive:ionSideMenus}
* directive to true.
*
* ```html
* <ion-side-menus enable-menu-with-back-views="true">
* ```
*/
IonicModule
.directive('menuToggle', function() {
return {
restrict: 'AC',
link: function($scope, $element, $attr) {
$scope.$on('$ionicView.beforeEnter', function(ev, viewData) {
if (viewData.enableBack) {
var sideMenuCtrl = $element.inheritedData('$ionSideMenusController');
if (!sideMenuCtrl.enableMenuWithBackViews()) {
$element.addClass('hide');
}
} else {
$element.removeClass('hide');
}
});
$element.bind('click', function() {
var sideMenuCtrl = $element.inheritedData('$ionSideMenusController');
sideMenuCtrl && sideMenuCtrl.toggle($attr.menuToggle);
});
}
};
});