Skip to content

Commit

Permalink
performance improvement for exposeAsideWhen directive that also fixes…
Browse files Browse the repository at this point in the history
… issue #3600
  • Loading branch information
msalcala11 committed Jul 29, 2015
1 parent bab6cad commit 8187367
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions js/angular/directive/exposeAsideWhen.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
* <ion-side-menus>
Expand All @@ -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);
Expand All @@ -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);
});

}
};
}]);

0 comments on commit 8187367

Please sign in to comment.