Created
April 7, 2017 20:23
-
-
Save zdenekhatak/861c6dfde45f0e55d8b4fdd0e6496b56 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var listeners = []; | |
function addListener(breakpointString, intention) { | |
if (window.matchMedia) { | |
var breakpointObj = window.matchMedia(mqBreakpoints[breakpointString]); | |
listeners.push({ | |
breakpoint: breakpointString, | |
intention: intention, | |
listener: breakpointObj | |
}); | |
breakpointObj.addListener(function() { | |
sendEvent(breakpointString, intention, breakpointObj); | |
}); | |
} | |
} | |
function sendEvent(bpoint, intention, obj) { | |
var entering = obj.matches ? true : false; | |
$rootScope.$broadcast('mq:' + bpoint + ':' + intention, entering); | |
} | |
$rootScope.$on('$stateChangeStart', function() { | |
angular.forEach(listeners, function(lis) { | |
lis.listener.removeListener(sendEvent); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment