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 ionic-team#3600
  • Loading branch information
msalcala11 committed Jul 29, 2015
1 parent bab6cad commit ecdeb0d
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions js/angular/directive/exposeAsideWhen.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,36 +39,37 @@
* 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);
sideMenuCtrl.activeAsideResizing(false);
}

function onResize() {
debouncedCheck();
sideMenuCtrl.activeAsideResizing(true);
debouncedCheck();
}

var debouncedCheck = ionic.debounce(function() {
$scope.$apply(checkAsideExpose);
}, 300, false);

$scope.$evalAsync(checkAsideExpose);

ionic.on('resize', onResize, $window);

$scope.$on('$destroy', function() {
ionic.off('resize', onResize, $window);
});

}
};
}]);

}]);

0 comments on commit ecdeb0d

Please sign in to comment.