23
23
* the most common use-case. However, for added flexibility, any valid media query could be added
24
24
* as the value, such as `(min-width:600px)` or even multiple queries such as
25
25
* `(min-width:750px) and (max-width:1200px)`.
26
-
27
26
* @usage
28
27
* ```html
29
28
* <ion-side-menus>
39
38
* For a complete side menu example, see the
40
39
* {@link ionic.directive:ionSideMenus} documentation.
41
40
*/
41
+
42
42
IonicModule . directive ( 'exposeAsideWhen' , [ '$window' , function ( $window ) {
43
43
return {
44
44
restrict : 'A' ,
45
45
require : '^ionSideMenus' ,
46
46
link : function ( $scope , $element , $attr , sideMenuCtrl ) {
47
47
48
+ // Setup a match media query listener that triggers a ui change only when a change
49
+ // in media matching status occurs
50
+ var mq = $attr . exposeAsideWhen == 'large' ? '(min-width:768px)' : $attr . exposeAsideWhen ;
51
+ var mql = $window . matchMedia ( mq ) ;
52
+ mql . addListener ( function ( ) {
53
+ onResize ( ) ;
54
+ } ) ;
55
+
48
56
function checkAsideExpose ( ) {
49
57
var mq = $attr . exposeAsideWhen == 'large' ? '(min-width:768px)' : $attr . exposeAsideWhen ;
50
58
sideMenuCtrl . exposeAside ( $window . matchMedia ( mq ) . matches ) ;
@@ -61,14 +69,6 @@ IonicModule.directive('exposeAsideWhen', ['$window', function($window) {
61
69
} , 300 , false ) ;
62
70
63
71
$scope . $evalAsync ( checkAsideExpose ) ;
64
-
65
- ionic . on ( 'resize' , onResize , $window ) ;
66
-
67
- $scope . $on ( '$destroy' , function ( ) {
68
- ionic . off ( 'resize' , onResize , $window ) ;
69
- } ) ;
70
-
71
72
}
72
73
} ;
73
74
} ] ) ;
74
-
0 commit comments