<commit_before>/* global angular */
(function() {
  'use strict';
  
  function Radio($rootScope) {

    var Radio = {
      CheckedEvent: 'radio.checked',
      setCheckedView: function($element) {
        $element.attr('checked', 'checked');
        $element.find('.radio-toggle').addClass('checked');
      },
      setUncheckedView: function($element) {
        $element.removeAttr('checked');
        $element.find('.radio-toggle').removeClass('checked');
      },
      isChecked: function($element) {
        return $element.attr('checked') === 'checked';
      },
      isEnabled: function($element) {
        return $element.attr('disabled') !== 'disabled';
      },
      shouldCheck: function($element) {
        return (this.isEnabled($element) && !(this.isChecked($element)));
      },
      setEnabledView: function($element) {
        $element.removeAttr('disabled');
        $element.find('.radio-toggle').removeClass('disabled');
      },
      setDisabledView: function($element) {
        $element.attr('disabled', 'disabled');
        $element.find('.radio-toggle').addClass('disabled');
      }
    };
    
    function link($scope, $element, $attr, ctrls) {
      
      function ngModelLink($scope, $element, $attr, $ctrl) {
        $element.click(function() {
          if (Radio.shouldCheck($element)) {
            Radio.setCheckedView($element);
            $scope.$apply(function() {
              $ctrl.$setViewValue($attr.value);
            });
          }
        });

        $scope.$watch($attr.ngModel, function() {
          if (!angular.isDefined($ctrl.$viewValue) || $ctrl.$viewValue !== $attr.value) {
            Radio.setUncheckedView($element);
          } else if ($ctrl.$viewValue === $attr.value) {
            Radio.setCheckedView($element);
          }
        });
      }
      
      function doNative($scope, $element, $attr) {
        $element.click(function() {
          if (Radio.shouldCheck($element)) {
            $attr.$set('checked', 'checked');
          }
        });

        $scope.$on(Radio.CheckedEvent, function(event, value) {
          if ($element.attr('value') !== value) {
            Radio.setUncheckedViewA($element);
          }
        });

        $attr.$observe('checked', function() {
          if (Radio.isChecked($element)) {
            Radio.setCheckedView($element);
            $rootScope.$broadcast(Radio.CheckedEvent, $element.attr('value'));
          } else {
            Radio.uncheck(element);
          }
        });

        $attr.$observe('disabled', function() {
          if (Radio.isEnabled($element)) {
            Radio.setEnabledView($element);
          } else {
            Radio.setDisabledView($element);
          }
        });
      }
      
      if (Radio.isChecked($element)) {
        Radio.setCheckedView($element);
      }
      if (!Radio.isEnabled($element)) {
        Radio.setDisabledView($element);
      }
      if (ctrls[0]) {
        ngModelLink($scope, $element, $attr, ctrls[0]);
      } else {
        doNative($scope, $element, $attr);
      }
    }<commit_msg>Rename unclear 'doNative' method<commit_after>/* global angular */
(function() {
  'use strict';
  
  function Radio($rootScope) {

    var Radio = {
      CheckedEvent: 'radio.checked',
      setCheckedView: function($element) {
        $element.attr('checked', 'checked');
        $element.find('.radio-toggle').addClass('checked');
      },
      setUncheckedView: function($element) {
        $element.removeAttr('checked');
        $element.find('.radio-toggle').removeClass('checked');
      },
      isChecked: function($element) {
        return $element.attr('checked') === 'checked';
      },
      isEnabled: function($element) {
        return $element.attr('disabled') !== 'disabled';
      },
      shouldCheck: function($element) {
        return (this.isEnabled($element) && !(this.isChecked($element)));
      },
      setEnabledView: function($element) {
        $element.removeAttr('disabled');
        $element.find('.radio-toggle').removeClass('disabled');
      },
      setDisabledView: function($element) {
        $element.attr('disabled', 'disabled');
        $element.find('.radio-toggle').addClass('disabled');
      }
    };
    
    function link($scope, $element, $attr, ctrls) {
      
      function ngModelLink($scope, $element, $attr, $ctrl) {
        $element.click(function() {
          if (Radio.shouldCheck($element)) {
            Radio.setCheckedView($element);
            $scope.$apply(function() {
              $ctrl.$setViewValue($attr.value);
            });
          }
        });

        $scope.$watch($attr.ngModel, function() {
          if (!angular.isDefined($ctrl.$viewValue) || $ctrl.$viewValue !== $attr.value) {
            Radio.setUncheckedView($element);
          } else if ($ctrl.$viewValue === $attr.value) {
            Radio.setCheckedView($element);
          }
        });
      }
      
      function simulateNativeRadio($scope, $element, $attr) {
        $element.click(function() {
          if (Radio.shouldCheck($element)) {
            $attr.$set('checked', 'checked');
          }
        });

        $scope.$on(Radio.CheckedEvent, function(event, value) {
          if ($element.attr('value') !== value) {
            Radio.setUncheckedViewA($element);
          }
        });

        $attr.$observe('checked', function() {
          if (Radio.isChecked($element)) {
            Radio.setCheckedView($element);
            $rootScope.$broadcast(Radio.CheckedEvent, $element.attr('value'));
          } else {
            Radio.uncheck(element);
          }
        });

        $attr.$observe('disabled', function() {
          if (Radio.isEnabled($element)) {
            Radio.setEnabledView($element);
          } else {
            Radio.setDisabledView($element);
          }
        });
      }
      
      if (Radio.isChecked($element)) {
        Radio.setCheckedView($element);
      }
      if (!Radio.isEnabled($element)) {
        Radio.setDisabledView($element);
      }
      if (ctrls[0]) {
        ngModelLink($scope, $element, $attr, ctrls[0]);
      } else {
        simulateNativeRadio($scope, $element, $attr);
      }
    }
{'fraction_non_alphanumeric': 0.1687872443227573, 'fraction_numerical': 0.0006442261233693026, 'mean_word_length': 2.12374245472837, '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': '1152551', 'n_tokens_mistral': 1715, 'n_tokens_neox': 1707, 'n_words': 245}