{"size": 702, "ext": "js", "max_stars_repo_path": "src/scripts/directives/flexMonths.js", "max_stars_repo_name": "Ryanm14/Financier-Fork", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/scripts/directives/flexMonths.js", "max_issues_repo_name": "Ryanm14/Financier-Fork", "max_issues_repo_issues_event_min_datetime": "2022-03-02T08:27:25.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-02T08:27:25.000Z", "max_forks_repo_path": "src/scripts/directives/flexMonths.js", "max_forks_repo_name": "Ryanm14/Financier-Fork", "max_forks_repo_forks_event_min_datetime": "2020-05-17T11:54:08.000Z", "max_forks_repo_forks_event_max_datetime": "2020-05-17T11:54:08.000Z"}
{"max_stars_count": null, "max_issues_count": 1, "max_forks_count": 1, "avg_line_length": 28.08, "max_line_length": 72, "alphanum_fraction": 0.594017094}
import { throttle } from 'underscore';

angular.module('financier').directive('flexMonths', ($rootScope) => {
  return {
    restrict: 'A',
    link: function (scope, element) {
      let flexMonths = Math.floor((element[0].offsetWidth - 175) / 260);
      $rootScope.$emit('budget:columns', flexMonths);

      const onResize = throttle(() => {
        flexMonths = Math.floor((element[0].offsetWidth - 175) / 260);
        $rootScope.$emit('budget:columns', flexMonths);

        $rootScope.$apply();
      }, 250);

      window.addEventListener('resize', onResize, false);

      scope.$on('$destroy', () => {
        window.removeEventListener('resize', onResize, false);
      });
    }
  };
});
