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

  angular.module('pickadate', []);

  angular.module('pickadate').provider('pickADate', pickADateProvider);

  angular.module('pickadate').provider('pickATime', pickATimeProvider);

  angular.module('pickadate').directive('pickADate', ['$parse', 'pickADate', function ($parse, pickADate) {
    return {
      restrict: 'A',
      link: function (scope, element, attrs) {
        var model = {
          pickADate: $parse(attrs.pickADate),
          minDate: $parse(attrs.minDate),
          maxDate: $parse(attrs.maxDate),
          pickADateOptions: $parse(attrs.pickADateOptions)
        };

        var defaultOptions = pickADate.getOptions() || {};
        var userOptions = model.pickADateOptions(scope) || {};
        var options = angular.extend({}, defaultOptions, userOptions);

        options.onSet = function (e) {
          var that = this,
              args = arguments,
              select = element.pickadate('picker').get('select'); // selected date

          scope.$evalAsync(function () {
            if (e.hasOwnProperty('clear')) {
              model.pickADate.assign(scope, null);
              return;
            }
            if (select) {
              var date = model.pickADate(scope);
              if (!date) {
                date = new Date(0);
                model.pickADate.assign(scope, date);
              }
              date.setFullYear(select.obj.getFullYear(), select.obj.getMonth(), select.obj.getDate());
            } else {
              model.pickADate.assign(scope, select);
            }
            if (userOptions && userOptions.onSet) {
              userOptions.onSet.apply(that, args);
            }
            if (defaultOptions && defaultOptions.onSet) {
              defaultOptions.onSet.apply(that, args);
            }
          });
        };

        options.onClose = function () {
          if (userOptions && userOptions.onClose) {
            userOptions.onClose.apply(this, arguments);
          }
          if (defaultOptions && defaultOptions.onClose) {
            defaultOptions.onClose.apply(that, args);
          }
          element.blur();
        };

        element.pickadate(options);
        function updateValue(newValue) {
          if (newValue) {
            var date = (newValue instanceof Date) ? newValue : new Date(newValue);
            element.pickadate('picker').set('select', date.getTime());
            model.pickADate.assign(scope, date);
          } else {
            element.pickadate('picker').clear();
            model.pickADate.assign(scope, null);
          }
        }

        updateValue(model.pickADate(scope));
        var minDate = model.minDate(scope);
        var maxDate = model.maxDate(scope);
        element.pickadate('picker').set('min', minDate ? minDate : false);
        element.pickadate('picker').set('max', maxDate ? maxDate : false);

        scope.$watchGroup([attrs.pickADate, attrs.minDate, attrs.maxDate], function(newValues, oldValues) {
          var newValue = newValues[0], newMin = newValues[1], newMax = newValues[2],
              oldValue = oldValues[0], oldMin = oldValues[1], oldMax = oldValues[2];

          if (newMin !== oldMin) {
            element.pickadate('picker').set('min', newValues[1] ? newValues[1] : false);
          }
          if (newMax !== oldMax) {
            element.pickadate('picker').set('max', newValues[2] ? newValues[2] : false);
          }
          if (newValue !== oldValue) {
            updateValue(newValues[0]);
          }
        }, true);
      }
    };
  }]);

  angular.module('pickadate').directive('pickATime', ['$parse', 'pickATime', function ($parse, pickATime) {
    return {
      restrict: 'A',
      link: function (scope, element, attrs) {
        var model = {
          pickATime: $parse(attrs.pickATime),
          pickATimeOptions: $parse(attrs.pickATimeOptions)
        };

        var defaultOptions = pickATime.getOptions() || {};
        var userOptions = model.pickATimeOptions(scope) || {};
        var options = angular.extend({}, defaultOptions, userOptions);

        options.onSet = function (e) {
          var that = this,
              args = arguments,
              select = element.pickatime('picker').get('select'); // selected date

          scope.$evalAsync(function () {
            if (e.hasOwnProperty('clear')) {
              model.pickATime.assign(scope, null);
              return;
            }
            if (select) {
              var date = model.pickATime(scope);
              if (!date) {
                date = new Date(0);
                model.pickATime.assign(scope, date);
              }
              date.setHours(select.hour);
              date.setMinutes(select.mins);
              date.setSeconds(0);
              date.setMilliseconds(0);
            } else {
              model.pickATime.assign(scope, select);
            }
            if (userOptions && userOptions.onSet) {
              userOptions.onSet.apply(that, args);
            }
            if (defaultOptions && defaultOptions.onSet) {
              defaultOptions.onSet.apply(that, args);
            }
          });
        };

        options.onClose = function () {
          if (userOptions && userOptions.onClose) {
            userOptions.onClose.apply(this, arguments);
          }
          if (defaultOptions && defaultOptions.onClose) {
            defaultOptions.onClose.apply(that, args);
          }<commit_msg>Add pickADate status indicators to ngModel<commit_after>(function (angular) {
  'use strict';

  angular.module('pickadate', []);

  angular.module('pickadate').provider('pickADate', pickADateProvider);

  angular.module('pickadate').provider('pickATime', pickATimeProvider);

  angular.module('pickadate').directive('pickADate', ['$parse', 'pickADate', function ($parse, pickADate) {
    return {
      restrict: 'A',
      require: '?ngModel',
      link: function (scope, element, attrs, ngModel) {
        var onSetRunCount = 0;
        var initOnSetRuns = 3;
        var model = {
          pickADate: $parse(attrs.pickADate),
          minDate: $parse(attrs.minDate),
          maxDate: $parse(attrs.maxDate),
          pickADateOptions: $parse(attrs.pickADateOptions)
        };

        var defaultOptions = pickADate.getOptions() || {};
        var userOptions = model.pickADateOptions(scope) || {};
        var options = angular.extend({}, defaultOptions, userOptions);

        if (ngModel) {
          ngModel.$setPickADatePristine = function () {
            ngModel.$pickADatePristine = true;
            ngModel.$pickADateDirty = false;
          }
          ngModel.$setPickADateDirty = function () {
            ngModel.$pickADatePristine = false;
            ngModel.$pickADateDirty = true;
          }
          ngModel.$setPickADateUntouched = function () {
            ngModel.$pickADateUntouched = true;
            ngModel.$pickADateTouched = false;
          }
          ngModel.$setPickADateTouched = function () {
            ngModel.$pickADateUntouched = false;
            ngModel.$pickADateTouched = true;
          }

          ngModel.$setPickADatePristine();
          ngModel.$setPickADateUntouched();
        }

        options.onSet = function (e) {
          var that = this,
              args = arguments,
              select = element.pickadate('picker').get('select'); // selected date

          scope.$evalAsync(function () {
            if (onSetRunCount < initOnSetRuns) {
              onSetRunCount += 1;
            } else {
              if (ngModel) {
                ngModel.$setPickADateDirty();
              }
            }
            if (e.hasOwnProperty('clear')) {
              model.pickADate.assign(scope, null);
              return;
            }
            if (select) {
              var date = model.pickADate(scope);
              if (!date) {
                date = new Date(0);
                model.pickADate.assign(scope, date);
              }
              date.setFullYear(select.obj.getFullYear(), select.obj.getMonth(), select.obj.getDate());
            } else {
              model.pickADate.assign(scope, select);
            }
            if (userOptions && userOptions.onSet) {
              userOptions.onSet.apply(that, args);
            }
            if (defaultOptions && defaultOptions.onSet) {
              defaultOptions.onSet.apply(that, args);
            }
          });
        };

        options.onClose = function () {
          if (ngModel) {
            scope.$applyAsync(function () {
              ngModel.$setPickADateTouched();
            });
          }
          if (userOptions && userOptions.onClose) {
            userOptions.onClose.apply(this, arguments);
          }
          if (defaultOptions && defaultOptions.onClose) {
            defaultOptions.onClose.apply(that, args);
          }
          element.blur();
        };

        element.pickadate(options);
        function updateValue(newValue) {
          if (newValue) {
            var date = (newValue instanceof Date) ? newValue : new Date(newValue);
            element.pickadate('picker').set('select', date.getTime());
            model.pickADate.assign(scope, date);
          } else {
            element.pickadate('picker').clear();
            model.pickADate.assign(scope, null);
          }
        }

        updateValue(model.pickADate(scope));
        var minDate = model.minDate(scope);
        var maxDate = model.maxDate(scope);
        element.pickadate('picker').set('min', minDate ? minDate : false);
        element.pickadate('picker').set('max', maxDate ? maxDate : false);

        scope.$watchGroup([attrs.pickADate, attrs.minDate, attrs.maxDate], function(newValues, oldValues) {
          var newValue = newValues[0], newMin = newValues[1], newMax = newValues[2],
              oldValue = oldValues[0], oldMin = oldValues[1], oldMax = oldValues[2];

          if (newMin !== oldMin) {
            element.pickadate('picker').set('min', newValues[1] ? newValues[1] : false);
          }
          if (newMax !== oldMax) {
            element.pickadate('picker').set('max', newValues[2] ? newValues[2] : false);
          }
          if (newValue !== oldValue) {
            updateValue(newValues[0]);
          }
        }, true);
      }
    };
  }]);

  angular.module('pickadate').directive('pickATime', ['$parse', 'pickATime', function ($parse, pickATime) {
    return {
      restrict: 'A',
      require: '?ngModel',
      link: function (scope, element, attrs, ngModel) {
        var onSetRunCount = 0;
        var initOnSetRuns = 3;
        var model = {
          pickATime: $parse(attrs.pickATime),
          pickATimeOptions: $parse(attrs.pickATimeOptions)
        };

        var defaultOptions = pickATime.getOptions() || {};
        var userOptions = model.pickATimeOptions(scope) || {};
        var options = angular.extend({}, defaultOptions, userOptions);

        if (ngModel) {
          ngModel.$setPickADatePristine = function () {
            ngModel.$pickADatePristine = true;
            ngModel.$pickADateDirty = false;
          }
          ngModel.$setPickADateDirty = function () {
            ngModel.$pickADatePristine = false;
            ngModel.$pickADateDirty = true;
          }
          ngModel.$setPickADateUntouched = function () {
            ngModel.$pickADateUntouched = true;
            ngModel.$pickADateTouched = false;
          }
          ngModel.$setPickADateTouched = function () {
            ngModel.$pickADateUntouched = false;
            ngModel.$pickADateTouched = true;
          }

          ngModel.$setPickADatePristine();
          ngModel.$setPickADateUntouched();
        }

        options.onSet = function (e) {
          var that = this,
              args = arguments,
              select = element.pickatime('picker').get('select'); // selected date

          scope.$evalAsync(function () {
            if (onSetRunCount < initOnSetRuns) {
              onSetRunCount += 1;
            } else {
              if (ngModel) {
                ngModel.$setPickADateDirty();
              }
            }
            if (e.hasOwnProperty('clear')) {
              model.pickATime.assign(scope, null);
              return;
            }
            if (select) {
              var date = model.pickATime(scope);
              if (!date) {
                date = new Date(0);
                model.pickATime.assign(scope, date);
              }
              date.setHours(select.hour);
              date.setMinutes(select.mins);
              date.setSeconds(0);
              date.setMilliseconds(0);
            } else {
              model.pickATime.assign(scope, select);
            }
            if (userOptions && userOptions.onSet) {
              userOptions.onSet.apply(that, args);
            }
            if (defaultOptions && defaultOptions.onSet) {
              defaultOptions.onSet.apply(that, args);
            }
          });
        };

        options.onClose = function () {
          if (ngModel) {
            scope.$applyAsync(function () {
              ngModel.$setPickADateTouched();
            });
          }
          if (userOptions && userOptions.onClose) {
            userOptions.onClose.apply(this, arguments);
          }
          if (defaultOptions && defaultOptions.onClose) {
            defaultOptions.onClose.apply(that, args);
          }
{'fraction_non_alphanumeric': 0.12822610635924137, 'fraction_numerical': 0.002677575306805504, 'mean_word_length': 1.797752808988764, 'pattern_counts': {'":': 0, '<': 5, '<?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': '2706100', 'n_tokens_mistral': 3770, 'n_tokens_neox': 3695, 'n_words': 637}