<commit_before>(function() {
  'use strict';

  var app = angular.module('radar.forms');

  app.directive('frmDatePicker', function() {
    return {
      require: 'ngModel',
      link: function(scope, element, attrs, ngModelCtrl) {
        var options = {
          changeMonth: true,
          changeYear: true,
          dateFormat: 'dd/mm/yy',
          minDate: getDate(attrs.datePickerMinDate),
          maxDate: getDate(attrs.datePickerMaxDate),
          defaultDate: getDate(attrs.defaultDate),
          yearRange: '1900:+10'
        };

        element.datepicker(options);

        attrs.$observe('datePickerMinDate', function(value) {
          setOption('minDate', getDate(value));
        });

        attrs.$observe('datePickerMaxDate', function(value) {
          setOption('maxDate', getDate(value));
        });

        attrs.$observe('datePickerDefaultDate', function(value) {
          setOption('defaultDate', getDate(value));
        });

        function getDate(value) {
          return value ? new Date(value) : null;
        }

        function setOption(key, value) {
          // Setting some options (e.g. minDate) will cause the input value to change without firing a change event.
          // To work round this we keep track of the value before and after updating the option and then manually
          // update the model controller if the value changed.
          var oldValue = element.val();
          element.datepicker('option', key, value);
          var newValue = element.val();

          if (oldValue !== newValue) {
            ngModelCtrl.$setViewValue(newValue);
          }
        }
      }
    };
  });
})();
<commit_msg>Fix date picker leak<commit_after>(function() {
  'use strict';

  var app = angular.module('radar.forms');

  app.directive('frmDatePicker', function() {
    return {
      require: 'ngModel',
      link: function(scope, element, attrs, ngModelCtrl) {
        var options = {
          changeMonth: true,
          changeYear: true,
          dateFormat: 'dd/mm/yy',
          minDate: getDate(attrs.datePickerMinDate),
          maxDate: getDate(attrs.datePickerMaxDate),
          defaultDate: getDate(attrs.defaultDate),
          yearRange: '1900:+10'
        };

        element.datepicker(options);

        element.on('$destroy', function() {
            element.datepicker('hide');
            element.datepicker('destroy');
        });

        attrs.$observe('datePickerMinDate', function(value) {
          setOption('minDate', getDate(value));
        });

        attrs.$observe('datePickerMaxDate', function(value) {
          setOption('maxDate', getDate(value));
        });

        attrs.$observe('datePickerDefaultDate', function(value) {
          setOption('defaultDate', getDate(value));
        });

        function getDate(value) {
          return value ? new Date(value) : null;
        }

        function setOption(key, value) {
          // Setting some options (e.g. minDate) will cause the input value to change without firing a change event.
          // To work round this we keep track of the value before and after updating the option and then manually
          // update the model controller if the value changed.
          var oldValue = element.val();
          element.datepicker('option', key, value);
          var newValue = element.val();

          if (oldValue !== newValue) {
            ngModelCtrl.$setViewValue(newValue);
          }
        }
      }
    };
  });
})();

{'fraction_non_alphanumeric': 0.12289225492997999, 'fraction_numerical': 0.003429551300371535, 'mean_word_length': 2.2051282051282053, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '396445', 'n_tokens_mistral': 955, 'n_tokens_neox': 923, 'n_words': 231}