diff --git a/js/angular/directive/exposeAsideWhen.js b/js/angular/directive/exposeAsideWhen.js index 37e10734123..cf7bec4734a 100644 --- a/js/angular/directive/exposeAsideWhen.js +++ b/js/angular/directive/exposeAsideWhen.js @@ -39,12 +39,21 @@ * For a complete side menu example, see the * {@link ionic.directive:ionSideMenus} documentation. */ -IonicModule.directive('exposeAsideWhen', ['$window', function($window) { + +IonicModule.directive('exposeAsideWhen', ['$window', function($window) { return { restrict: 'A', require: '^ionSideMenus', link: function($scope, $element, $attr, sideMenuCtrl) { + // Setup a match media query listener that triggers a ui change only when a change + // in media matching status occurs + var mq = $attr.exposeAsideWhen == 'large' ? '(min-width:768px)' : $attr.exposeAsideWhen; + var mql = $window.matchMedia(mq); + mql.addListener(function (mql) { + onResize(); + }) + function checkAsideExpose() { var mq = $attr.exposeAsideWhen == 'large' ? '(min-width:768px)' : $attr.exposeAsideWhen; sideMenuCtrl.exposeAside($window.matchMedia(mq).matches); @@ -52,8 +61,8 @@ IonicModule.directive('exposeAsideWhen', ['$window', function($window) { } function onResize() { + debouncedCheck(); sideMenuCtrl.activeAsideResizing(true); - debouncedCheck(); } var debouncedCheck = ionic.debounce(function() { @@ -61,14 +70,6 @@ IonicModule.directive('exposeAsideWhen', ['$window', function($window) { }, 300, false); $scope.$evalAsync(checkAsideExpose); - - ionic.on('resize', onResize, $window); - - $scope.$on('$destroy', function() { - ionic.off('resize', onResize, $window); - }); - } }; -}]); - +}]); \ No newline at end of file