<commit_before><!--
Copyright 2013 The Toolkitchen Authors. All rights reserved.
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file.
-->
<script>
/**
 * g-selector is used to display a list of elements that can be selected.
 * The attribute "selected" indicates which element is being selected.
 * Tapping on the element to change selection would fire "activate"
 * event.
 *
 * Example:
 *
 *     <g-selector selected="0" on-activate="activateHandler">
 *       <div>Item 1</div>
 *       <div>Item 2</div>
 *       <div>Item 3</div>
 *     </g-selector>
 *
 * g-selector is not styled.  So one needs to use "selected" CSS class
 * to style the selected element.
 * 
 *     <style>
 *       .item.selected {
 *         background: #eee;
 *       }
 *     </style>
 *     ...
 *     <g-selector>
 *       <div class="item">Item 1</div>
 *       <div class="item">Item 2</div>
 *       <div class="item">Item 3</div>
 *     </g-selector>
 *
 * @class g-selector
 */
/**
 * Fired when selection is changed via tap.
 * 
 * @event activate
 */
</script>
<link rel="import" href="g-selection.html">
<element name="g-selector" attributes="selected multi" on-tap="activateHandler">
  <template>
    <g-selection id="selection" multi="{{multi}}" on-select="selectionSelect"></g-selection>
    <content id="items" select="*"></content>
  </template>
  <script>
    Toolkit.register(this, {
      /**
       * Gets or sets the selected element.  Default is to use the index
       * of the currently selected element.
       *
       * If you want a specific attribute value of the selected element to be
       * used instead of index, set "valueattr" to that attribute name.
       *
       * Example:
       *
       *     <g-selector valueattr="label" selected="foo">
       *       <div label="foo"></div>
       *       <div label="bar"></div>
       *       <div label="zot"></div>
       *     </g-selector>
       *
       * @attribute selected
       * @type string
       * @default null
       */
      selected: null,
      /**
       * If true, multiple selections are allowed.
       *
       * @attribute multi
       * @type boolean
       * @default false
       */
      multi: false,
      /**
       * Specifies the attribute to be used for "selected" attribute.
       *
       * @attribute valueattr
       * @type string
       * @default 'name'
       */
      valueattr: 'name',
      /**
       * Specifies the CSS class to be used to add to the selected element.
       * 
       * @attribute selectedClass
       * @type string
       * @default 'selected'
       */
      selectedClass: 'selected',
      ready: function() {
        this.setAttribute('touch-action', 'none');
      },
      get items() {
        return this.$.items.getDistributedNodes();
      },
      get selection() {
        return this.$.selection.getSelection();
      },
      valueForNode: function(inNode) {
        return inNode.getAttribute(this.valueattr);
      },
      valueToIndex: function(inValue) {
        // find an item with value == inValue and return it's index
        for (var i=0, items=this.items, c; (c=items[i]); i++) {
          if (this.valueForNode(c) == inValue) {
            return i;
          }
        }
        // if no item found, the value itself is probably the index
        return inValue;
      },
      selectedChanged: function() {
        this.valueToSelection(this.selected);
      },
      valueToSelection: function(inValue) {
        var item = this.items[this.valueToIndex(inValue)];
        if (item) {
          this.$.selection.select(item);
        }
      },
      // events fired from <g-selection> object
      selectionSelect: function(inEvent, inInfo) {
        if (inInfo.item) {
          inInfo.item.classList.toggle(this.selectedClass, inInfo.isSelected);
        }
      },
      // event fired from host
      activateHandler: function(inEvent) {
        var items = this.items;
        var i = Toolkit.findDistributedTarget(inEvent.target, items);
        if (i >= 0) {
          var selected = this.valueForNode(items[i]) || i;
          if (this.multi) {
            this.valueToSelection(selected);
          } else {
            this.selected = selected;
          }
          this.asend('activate');
        }
      }
    });
  </script>
</element><commit_msg>g-selector: include the selected item in the activate event<commit_after><!--
Copyright 2013 The Toolkitchen Authors. All rights reserved.
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file.
-->
<script>
/**
 * g-selector is used to display a list of elements that can be selected.
 * The attribute "selected" indicates which element is being selected.
 * Tapping on the element to change selection would fire "activate"
 * event.
 *
 * Example:
 *
 *     <g-selector selected="0" on-activate="activateHandler">
 *       <div>Item 1</div>
 *       <div>Item 2</div>
 *       <div>Item 3</div>
 *     </g-selector>
 *
 * g-selector is not styled.  So one needs to use "selected" CSS class
 * to style the selected element.
 * 
 *     <style>
 *       .item.selected {
 *         background: #eee;
 *       }
 *     </style>
 *     ...
 *     <g-selector>
 *       <div class="item">Item 1</div>
 *       <div class="item">Item 2</div>
 *       <div class="item">Item 3</div>
 *     </g-selector>
 *
 * @class g-selector
 */
/**
 * Fired when an element is selected via tap.
 * 
 * @event activate
 * @param {Object} inDetail
 *   @param {Object} inDetail.item the selected element
 */
</script>
<link rel="import" href="g-selection.html">
<element name="g-selector" attributes="selected multi" on-tap="activateHandler">
  <template>
    <g-selection id="selection" multi="{{multi}}" on-select="selectionSelect"></g-selection>
    <content id="items" select="*"></content>
  </template>
  <script>
    Toolkit.register(this, {
      /**
       * Gets or sets the selected element.  Default is to use the index
       * of the currently selected element.
       *
       * If you want a specific attribute value of the selected element to be
       * used instead of index, set "valueattr" to that attribute name.
       *
       * Example:
       *
       *     <g-selector valueattr="label" selected="foo">
       *       <div label="foo"></div>
       *       <div label="bar"></div>
       *       <div label="zot"></div>
       *     </g-selector>
       *
       * @attribute selected
       * @type string
       * @default null
       */
      selected: null,
      /**
       * If true, multiple selections are allowed.
       *
       * @attribute multi
       * @type boolean
       * @default false
       */
      multi: false,
      /**
       * Specifies the attribute to be used for "selected" attribute.
       *
       * @attribute valueattr
       * @type string
       * @default 'name'
       */
      valueattr: 'name',
      /**
       * Specifies the CSS class to be used to add to the selected element.
       * 
       * @attribute selectedClass
       * @type string
       * @default 'selected'
       */
      selectedClass: 'selected',
      ready: function() {
        this.setAttribute('touch-action', 'none');
      },
      get items() {
        return this.$.items.getDistributedNodes();
      },
      get selection() {
        return this.$.selection.getSelection();
      },
      valueForNode: function(inNode) {
        return inNode.getAttribute(this.valueattr);
      },
      valueToIndex: function(inValue) {
        // find an item with value == inValue and return it's index
        for (var i=0, items=this.items, c; (c=items[i]); i++) {
          if (this.valueForNode(c) == inValue) {
            return i;
          }
        }
        // if no item found, the value itself is probably the index
        return inValue;
      },
      selectedChanged: function() {
        this.valueToSelection(this.selected);
      },
      valueToSelection: function(inValue) {
        var item = this.items[this.valueToIndex(inValue)];
        if (item) {
          this.$.selection.select(item);
        }
      },
      // events fired from <g-selection> object
      selectionSelect: function(inEvent, inInfo) {
        if (inInfo.item) {
          inInfo.item.classList.toggle(this.selectedClass, inInfo.isSelected);
        }
      },
      // event fired from host
      activateHandler: function(inEvent) {
        var items = this.items;
        var i = Toolkit.findDistributedTarget(inEvent.target, items);
        if (i >= 0) {
          var selected = this.valueForNode(items[i]) || i;
          if (this.multi) {
            this.valueToSelection(selected);
          } else {
            this.selected = selected;
          }
          this.asend('activate', {item: items[i]});
        }
      }
    });
  </script>
</element>
{'fraction_non_alphanumeric': 0.12972547254725472, 'fraction_numerical': 0.0029252925292529252, 'mean_word_length': 2.0020263424518743, 'pattern_counts': {'":': 0, '<': 85, '<?xml version=': 0, '>': 87, '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': '6687790', 'n_tokens_mistral': 2556, 'n_tokens_neox': 2525, 'n_words': 725}