From 81873678e3a7aaf77d9826520b815ad0ea27c592 Mon Sep 17 00:00:00 2001 From: Marty Alcala Date: Wed, 29 Jul 2015 10:28:29 -0400 Subject: [PATCH] performance improvement for exposeAsideWhen directive that also fixes issue #3600 --- js/angular/directive/exposeAsideWhen.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/js/angular/directive/exposeAsideWhen.js b/js/angular/directive/exposeAsideWhen.js index 37e10734123..6e5101fff9d 100644 --- a/js/angular/directive/exposeAsideWhen.js +++ b/js/angular/directive/exposeAsideWhen.js @@ -23,7 +23,6 @@ * the most common use-case. However, for added flexibility, any valid media query could be added * as the value, such as `(min-width:600px)` or even multiple queries such as * `(min-width:750px) and (max-width:1200px)`. - * @usage * ```html * @@ -39,12 +38,21 @@ * For a complete side menu example, see the * {@link ionic.directive:ionSideMenus} documentation. */ + 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() { + onResize(); + }); + function checkAsideExpose() { var mq = $attr.exposeAsideWhen == 'large' ? '(min-width:768px)' : $attr.exposeAsideWhen; sideMenuCtrl.exposeAside($window.matchMedia(mq).matches); @@ -61,14 +69,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); - }); - } }; }]); -