/**
 * Adds an onresize event attribtue that gets invokved when the size of the window changes.
 */
angular.module('quay').directive('onresize', function ($window, $parse) {
  return function (scope, element, attr) {
    var fn = $parse(attr.onresize);

    var notifyResized = function() {
      scope.$apply(function () {
        fn(scope);
      });
    };

    angular.element($window).on('resize', null, notifyResized);

    scope.$on('$destroy', function() {
      angular.element($window).off('resize', null, notifyResized);
    });
  };
});