Skip to content

Commit 8187367

Browse files
committed
performance improvement for exposeAsideWhen directive that also fixes issue #3600
1 parent bab6cad commit 8187367

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

Diff for: js/angular/directive/exposeAsideWhen.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
* the most common use-case. However, for added flexibility, any valid media query could be added
2424
* as the value, such as `(min-width:600px)` or even multiple queries such as
2525
* `(min-width:750px) and (max-width:1200px)`.
26-
2726
* @usage
2827
* ```html
2928
* <ion-side-menus>
@@ -39,12 +38,21 @@
3938
* For a complete side menu example, see the
4039
* {@link ionic.directive:ionSideMenus} documentation.
4140
*/
41+
4242
IonicModule.directive('exposeAsideWhen', ['$window', function($window) {
4343
return {
4444
restrict: 'A',
4545
require: '^ionSideMenus',
4646
link: function($scope, $element, $attr, sideMenuCtrl) {
4747

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+
4856
function checkAsideExpose() {
4957
var mq = $attr.exposeAsideWhen == 'large' ? '(min-width:768px)' : $attr.exposeAsideWhen;
5058
sideMenuCtrl.exposeAside($window.matchMedia(mq).matches);
@@ -61,14 +69,6 @@ IonicModule.directive('exposeAsideWhen', ['$window', function($window) {
6169
}, 300, false);
6270

6371
$scope.$evalAsync(checkAsideExpose);
64-
65-
ionic.on('resize', onResize, $window);
66-
67-
$scope.$on('$destroy', function() {
68-
ionic.off('resize', onResize, $window);
69-
});
70-
7172
}
7273
};
7374
}]);
74-

0 commit comments

Comments
 (0)