Skip to content

Instantly share code, notes, and snippets.

@zdenekhatak
Created April 7, 2017 20:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zdenekhatak/861c6dfde45f0e55d8b4fdd0e6496b56 to your computer and use it in GitHub Desktop.
Save zdenekhatak/861c6dfde45f0e55d8b4fdd0e6496b56 to your computer and use it in GitHub Desktop.
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