{"size": 1071, "ext": "js", "max_stars_repo_path": "deselectable-radio-buttons.js", "max_stars_repo_name": "reedhewitt/deselectable-radio-buttons", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "deselectable-radio-buttons.js", "max_issues_repo_name": "reedhewitt/deselectable-radio-buttons", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "deselectable-radio-buttons.js", "max_forks_repo_name": "reedhewitt/deselectable-radio-buttons", "max_forks_repo_forks_event_min_datetime": "2020-03-12T12:52:50.000Z", "max_forks_repo_forks_event_max_datetime": "2020-03-12T12:52:50.000Z"}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 38.25, "max_line_length": 92, "alphanum_fraction": 0.5294117647}
/*
* --------------------------------------------------------------------
* jQuery plugin to make radio buttons deselectable.
* by Reed Hewitt, reed@reedhewitt.com
* https://reedhewitt.com
* https://github.com/reedhewitt/deselectable-radio-buttons
* --------------------------------------------------------------------
*/

(function($){
  $(document).ready(function(){
    $(document.body).on('click mousedown keydown keyup', 'input[type="radio"]', function(e){
      let radioButton = $(e.target);
      if(('keydown' === e.type  && 32 === e.keyCode) || 'mousedown' === e.type){
        radioButton.data('originally_checked', radioButton.prop('checked'));
      }
      if(('keyup' === e.type && 32 === e.keyCode) || 'click' === e.type){
        if(radioButton.data('originally_checked')){
          radioButton.prop('checked', false).removeAttr('checked');
        } else {
          radioButton.prop('checked', true).attr('checked', 'checked');
        }
        radioButton.removeData('originally_checked').trigger('done_changing');
      }
    });
  });
}(jQuery));
