<commit_before><link rel="import" href="../polymer/polymer.html">
<link rel="import" href="collapsible-container.html">

<!--
`accordion-container`
Polymer 1.X and 2.X accordion container

### Usage
```html
<accordion-container>
  <collapsible-container header="Test">
    Content goes here
  </collapsible-container>
  <collapsible-container header="Test 2">
    Content goes here
  </collapsible-container>
  <collapsible-container header="Test 3">
    Content goes here
  </collapsible-container>
</accordion-container>
```

@demo demo/accordion.html
-->

<dom-module id="accordion-container">
  <template>
    <style>
      :host {
        display: block;
      }
    </style>
    <slot></slot>
  </template>
  <script>
    Polymer({
      is: "accordion-container",

      _collapsibleToggled: function(evt, self) {
        var containers = self.getAllCollapsibles();
        containers.forEach(function(item) {
          if (item.open && item != evt.target) {
            item.close();
          }
        });
      },

      attached: function() {
        var self = this;
        var containers = this.getAllCollapsibles();

        if (!containers || containers.length === 0) {
          throw 'No collapsible-containers could be found inside ' + this + ' !';
        }

        if (!this.getOpenCollapsible()) {
          containers[0].set('open', true);
        }

        containers.forEach(function(item) {
          item.addEventListener('collapsibleopened', function(evt) {
            self._collapsibleToggled(evt, self);
          }, false);
        });
      },

      /**
      * Get array of all the `collapsible-container` nodes
      * @return Array
      */
      getAllCollapsibles: function() {<commit_msg>Change forEach => for loops (browser compatibility)<commit_after><link rel="import" href="../polymer/polymer.html">
<link rel="import" href="collapsible-container.html">

<!--
`accordion-container`
Polymer 1.X and 2.X accordion container

### Usage
```html
<accordion-container>
  <collapsible-container header="Test">
    Content goes here
  </collapsible-container>
  <collapsible-container header="Test 2">
    Content goes here
  </collapsible-container>
  <collapsible-container header="Test 3">
    Content goes here
  </collapsible-container>
</accordion-container>
```

@demo demo/accordion.html
-->

<dom-module id="accordion-container">
  <template>
    <style>
      :host {
        display: block;
      }
    </style>
    <slot></slot>
  </template>
  <script>
    Polymer({
      is: "accordion-container",

      _collapsibleToggled: function(evt, self) {
        var containers = self.getAllCollapsibles();
        
        if (containers && containers.length) {
          for (var i = 0; i < containers.length; i++) {
            var item = containers[i];
             
            if (item.open && item != evt.target) {
              item.close();
            }
          }
        }
      },

      attached: function() {
        var self = this;
        var containers = this.getAllCollapsibles();

        if (!containers || containers.length === 0) {
          throw 'No collapsible-containers could be found inside ' + this + ' !';
        }

        if (!this.getOpenCollapsible()) {
          containers[0].set('open', true);
        }

        if (containers && containers.length) {
          for (var i = 0; i < containers.length; i++) {
            var item = containers[i];

            item.addEventListener('collapsibleopened', function (evt) {
              self._collapsibleToggled(evt, self);
            }, false);
          }
        }
      },

      /**
      * Get array of all the `collapsible-container` nodes
      * @return Array
      */
      getAllCollapsibles: function() {
{'fraction_non_alphanumeric': 0.14022927219408157, 'fraction_numerical': 0.003732338043188483, 'mean_word_length': 2.262608695652174, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 42, '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': '6309739', 'n_tokens_mistral': 1139, 'n_tokens_neox': 1102, 'n_words': 242}