I am working in an app that require snap menu for mobile resolutions and mobile device.
I am using snapjs and angular-snap, snapjs by default set two drawers, left and right, I can disable one of this drawers using the service in the angular-snap directive with snapRemote.globalOptions.disable = 'right'; or using attribute snap-opt-disable="'right'" in snap-content element.
I need to disable all drawers in non mobile resolutions (>= 768px), actualy I have a directive that check this resolutions, but I don't know how disable both drawers, left and right instead only one drawer.
This is my directive:
angular.module('myApp').directive('mobileScreenSwitcher', function ($window, snapRemote) {
return {
restrict: 'E',
link: function (scope) {
$window.onresize = function () {
checkResolution();
};
checkResolution();
function checkResolution() {
var screenWidth = $window.innerWidth;
if (screenWidth >= 768) {
// I need disable all drawers at this line
snapRemote.globalOptions.disable = 'left';
}
}
}
}
});
This is my actual html code
<div ui-view="navBar" snap-drawer="left" ></div>
<div snap-content snap-opt-disable="'right'">
... content here
</div>
<div ui-view="navBar2" snap-drawer="right" ></div>
Try this,
angular.module('myApp').directive('mobileScreenSwitcher', function ($window, snapRemote) {
return {
restrict: 'E',
link: function (scope) {
snapRemote.getSnapper().then(function(snapper) {
function onResizeCallback() {
var screenWidth = $window.innerWidth;
if (screenWidth >= 768) {
snapper.close();
snapper.disable();
} else {
snapper.enable();
}
}
$window.addEventListener('resize', onResizeCallback);
onResizeCallback();
});
scope.$on('$destroy', function () {
$window.removeEventListener('resize' onResizeCallback);
});
}
};
});
The following approach has worked for me before:
.run(function ($rootScope, snapRemote) {
snapRemote.getSnapper().then(function(snapper) {
function onResizeCallback() {
if (window.innerWidth <= 1024) {
snapper.enable();
} else {
snapper.close();
snapper.disable();
}
}
onResizeCallback();
$(window).resize(onResizeCallback);
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With