<commit_before>(function($) {
  'use strict';
 
  $.fn.extend({
    ///////////////////////////////
    // Initialize Segmented Control
    ///////////////////////////////
    UISegmented : function ( options ) {
      if (this.hasClass('paging')) return;
      var callback = (options && options.callback) ? options.callback : $.noop;
      var selected;
      if (options && options.selected) selected = options.selected;
      if (options && options.callback) {
        callback = options.callback;
      }
      this.find('a').each(function(idx, ctx) {
        $(ctx).find('a').attr('role','radio');
        if (selected === 0 && idx === 0) {
          ctx.setAttribute('aria-checked', 'true');
          ctx.classList.add('selected');
        }
        if (idx === selected) {
          ctx.setAttribute('aria-checked', 'true');
          ctx.classList.add('selected');
        }
      });
      if (!selected) {
        if (!this.find('.selected')[0]) {
          this.children().eq(0).addClass('selected');
        }
      }
      this.on('singletap', '.button', function(e) {
        var $this = $(this);
        if (this.parentNode.classList.contains('paging')) return;
        $this.siblings('a').removeClass('selected');
        $this.siblings('a').removeAttr('aria-checked');
        $this.addClass('selected');
        $this.attr('aria-checked', true);
        callback.call(this, e);
      });
    }
  });

  $.extend({ 
    ///////////////////////////
    // Create Segmented Control
    ///////////////////////////
    UICreateSegmented : function ( options ) {
      /* 
        options = {
          id : '#myId',
          className : 'special' || '',
          labels : ['first','second','third'],
          selected : 0 based number of selected button
        }
      */
      var className = (options && options.className) ? options.className : '';
      var labels = (options && options.labels) ? options.labels : [];
      var selected = (options && options.selected) ? options.selected : 0;
      var _segmented = ['<div class="segmented'];
      if (className) _segmented.push(' ' + className);
      _segmented.push('">');
      labels.forEach(function(ctx, idx) {
        _segmented.push('<a role="radio" class="button');
        if (selected === idx) {
          _segmented.push(' selected" aria-checked="true"');
        } else {
          _segmented.push('"');
        }
        _segmented.push('>');
        _segmented.push(ctx);
        _segmented.push('</a>');
      });
      _segmented.push('</div>');
      return _segmented.join('');
    }
  });

  $(function() {
    /////////////////////////////////////
    // Handle Existing Segmented Buttons:
    /////////////////////////////////////
    $('.segmented').UISegmented();
  });
})(window.jQuery);<commit_msg>Refactor UISegmented to fix state.<commit_after>(function($) {
  'use strict';
 
  $.fn.extend({
    ///////////////////////////////
    // Initialize Segmented Control
    ///////////////////////////////
    UISegmented : function ( options ) {
      if (this.hasClass('paging')) return;
      var callback = (options && options.callback) ? options.callback : $.noop;
      var selected;
      if (options && options.selected >= 0) selected = options.selected;
      if (options && options.callback) {
        callback = options.callback;
      }
      this.find('a').each(function(idx, ctx) {
        $(ctx).find('a').attr('role','radio');
        if (idx === selected) {
          ctx.setAttribute('aria-checked', 'true');
          ctx.classList.add('selected');
        }
      });
      this.on('singletap', '.button', function(e) {
        var $this = $(this);
        if (this.parentNode.classList.contains('paging')) return;
        $this.siblings('a').removeClass('selected');
        $this.siblings('a').removeAttr('aria-checked');
        $this.addClass('selected');
        $this.attr('aria-checked', true);
        callback.call(this, e);
      });
    }
  });

  $.extend({ 
    ///////////////////////////
    // Create Segmented Control
    ///////////////////////////
    UICreateSegmented : function ( options ) {
      /* 
        options = {
          id : '#myId',
          className : 'special' || '',
          labels : ['first','second','third'],
          selected : 0 based number of selected button
        }
      */
      var className = (options && options.className) ? options.className : '';
      var labels = (options && options.labels) ? options.labels : [];
      var selected = (options && options.selected) ? options.selected : 0;
      var _segmented = ['<div class="segmented'];
      if (className) _segmented.push(' ' + className);
      _segmented.push('">');
      labels.forEach(function(ctx, idx) {
        _segmented.push('<a role="radio" class="button');
        if (selected === idx) {
          _segmented.push(' selected" aria-checked="true"');
        } else {
          _segmented.push('"');
        }
        _segmented.push('>');
        _segmented.push(ctx);
        _segmented.push('</a>');
      });
      _segmented.push('</div>');
      return _segmented.join('');
    }
  });
})(window.jQuery);
{'fraction_non_alphanumeric': 0.22788983708301008, 'fraction_numerical': 0.0017455391776570986, 'mean_word_length': 1.8413223140495867, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 12, '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': '1033236', 'n_tokens_mistral': 1434, 'n_tokens_neox': 1412, 'n_words': 267}