<commit_before><!--
@license
Copyright (c) 2017 Vaadin Ltd.
This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
-->

<link rel="import" href="../../polymer/polymer-element.html">
<link rel="import" href="../../vaadin-overlay/src/vaadin-overlay.html">
<link rel="import" href="../../iron-resizable-behavior/iron-resizable-behavior.html">

<dom-module id="vaadin-combo-box-dropdown">
  <template>
    <style>
      :host {
        display: block;
      }

      :host > #overlay {
        display: none;
      }
    </style>
    <vaadin-combo-box-overlay id="overlay" hidden$="[[hidden]]" opened="[[opened]]" template="{{template}}" style="align-items: stretch; margin: 0">
      <slot></slot>
    </vaadin-combo-box-overlay>
  </template>
</dom-module>

<script>
  (function() {
    /**
     * The overlay element.
     *
     * ### Styling
     *
     * See [`<vaadin-overlay>` documentation](https://github.com/vaadin/vaadin-overlay/blob/master/src/vaadin-overlay.html)
     * for `<vaadin-combo-box-overlay>` parts.
     *
     * See [ThemableMixin – how to apply styles for shadow parts](https://github.com/vaadin/vaadin-themable-mixin/wiki)
     *
     * @memberof Vaadin
     * @private
     */
    class ComboBoxOverlayElement extends Vaadin.OverlayElement {
      static get is() {
        return 'vaadin-combo-box-overlay';
      }
    }

    customElements.define(ComboBoxOverlayElement.is, ComboBoxOverlayElement);

    /**
     * Element for internal use only.
     *
     * @memberof Vaadin
     * @private
     */
    class ComboBoxDropdownElement extends Polymer.mixinBehaviors(Polymer.IronResizableBehavior, Polymer.Element) {
      static get is() {
        return 'vaadin-combo-box-dropdown';
      }

      static get properties() {
        return {
          opened: {
            type: Boolean,
            notify: true
          },

          template: {
            type: Object,
            notify: true
          },

          /**
           * True if the device supports touch events.
           */
          touchDevice: {
            type: Boolean,
            reflectToAttribute: true,
            value: () => {
              try {
                document.createEvent('TouchEvent');
                return true;
              } catch (e) {
                return false;
              }
            }
          },

          /**
           * The element to position/align the dropdown by.
           */
          positionTarget: {
            type: Object
          },

          /**
           * If `true`, overlay is aligned above the `positionTarget`
           */
          alignedAbove: {
            type: Boolean,
            value: false
          }
        };
      }

      static get observers() {
        return ['_openedChanged(opened)'];
      }

      constructor() {
        super();
        this._boundSetPosition = this._setPosition.bind(this);
      }

      connectedCallback() {
        super.connectedCallback();
        this.addEventListener('iron-resize', this._boundSetPosition);
      }

      ready() {
        super.ready();

        // Preventing the default modal behaviour of the overlay on input clicking
        this.$.overlay.addEventListener('vaadin-overlay-outside-click', e => {
          e.preventDefault();
        });
      }

      disconnectedCallback() {
        super.disconnectedCallback();
        this.removeEventListener('iron-resize', this._boundSetPosition);

        // Making sure the overlay is closed and removed from DOM after detaching the dropdown.
        this.opened = false;
      }

      notifyResize() {
        super.notifyResize();

        if (this.positionTarget && this.opened) {
          this._setPosition();
          // Schedule another position update (to cover virtual keyboard opening for example)
          requestAnimationFrame(this._setPosition.bind(this));
        }
      }

      /**
       * Fired after the `vaadin-combo-box-dropdown` opens.
       *
       * @event vaadin-combo-box-dropdown-opened
       */
      /**
       * Fired after the `vaadin-combo-box-dropdown` closes.
       *
       * @event vaadin-combo-box-dropdown-closed
       */

      _openedChanged(opened) {
        if (opened) {
          this.$.overlay.style.position = this._isPositionFixed(this.positionTarget) ? 'fixed' : 'absolute';
          this._setPosition();

          window.addEventListener('scroll', this._boundSetPosition, true);
          document.addEventListener('click', this._outsideClickListener.bind(this), true);
          this.dispatchEvent(new CustomEvent('vaadin-combo-box-dropdown-opened', {bubbles: true, composed: true}));
        } else {
          window.removeEventListener('scroll', this._boundSetPosition, true);
          document.removeEventListener('click', this._outsideClickListener.bind(this), true);
          this.dispatchEvent(new CustomEvent('vaadin-combo-box-dropdown-closed', {bubbles: true, composed: true}));
        }
      }


      // We need to listen on 'click' event and capture it and close the overlay before
      // propagating the event to the listener in the button. Otherwise, if the clicked button would call
      // open(), this would happen: https://www.youtube.com/watch?v=Z86V_ICUCD4
      _outsideClickListener(event) {<commit_msg>Make `removeEventListener` to remove the actual listener<commit_after><!--
@license
Copyright (c) 2017 Vaadin Ltd.
This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
-->

<link rel="import" href="../../polymer/polymer-element.html">
<link rel="import" href="../../vaadin-overlay/src/vaadin-overlay.html">
<link rel="import" href="../../iron-resizable-behavior/iron-resizable-behavior.html">

<dom-module id="vaadin-combo-box-dropdown">
  <template>
    <style>
      :host {
        display: block;
      }

      :host > #overlay {
        display: none;
      }
    </style>
    <vaadin-combo-box-overlay id="overlay" hidden$="[[hidden]]" opened="[[opened]]" template="{{template}}" style="align-items: stretch; margin: 0">
      <slot></slot>
    </vaadin-combo-box-overlay>
  </template>
</dom-module>

<script>
  (function() {
    /**
     * The overlay element.
     *
     * ### Styling
     *
     * See [`<vaadin-overlay>` documentation](https://github.com/vaadin/vaadin-overlay/blob/master/src/vaadin-overlay.html)
     * for `<vaadin-combo-box-overlay>` parts.
     *
     * See [ThemableMixin – how to apply styles for shadow parts](https://github.com/vaadin/vaadin-themable-mixin/wiki)
     *
     * @memberof Vaadin
     * @private
     */
    class ComboBoxOverlayElement extends Vaadin.OverlayElement {
      static get is() {
        return 'vaadin-combo-box-overlay';
      }
    }

    customElements.define(ComboBoxOverlayElement.is, ComboBoxOverlayElement);

    /**
     * Element for internal use only.
     *
     * @memberof Vaadin
     * @private
     */
    class ComboBoxDropdownElement extends Polymer.mixinBehaviors(Polymer.IronResizableBehavior, Polymer.Element) {
      static get is() {
        return 'vaadin-combo-box-dropdown';
      }

      static get properties() {
        return {
          opened: {
            type: Boolean,
            notify: true
          },

          template: {
            type: Object,
            notify: true
          },

          /**
           * True if the device supports touch events.
           */
          touchDevice: {
            type: Boolean,
            reflectToAttribute: true,
            value: () => {
              try {
                document.createEvent('TouchEvent');
                return true;
              } catch (e) {
                return false;
              }
            }
          },

          /**
           * The element to position/align the dropdown by.
           */
          positionTarget: {
            type: Object
          },

          /**
           * If `true`, overlay is aligned above the `positionTarget`
           */
          alignedAbove: {
            type: Boolean,
            value: false
          }
        };
      }

      static get observers() {
        return ['_openedChanged(opened)'];
      }

      constructor() {
        super();
        this._boundSetPosition = this._setPosition.bind(this);
        this._boundOutsideClickListener = this._outsideClickListener.bind(this);
      }

      connectedCallback() {
        super.connectedCallback();
        this.addEventListener('iron-resize', this._boundSetPosition);
      }

      ready() {
        super.ready();

        // Preventing the default modal behaviour of the overlay on input clicking
        this.$.overlay.addEventListener('vaadin-overlay-outside-click', e => {
          e.preventDefault();
        });
      }

      disconnectedCallback() {
        super.disconnectedCallback();
        this.removeEventListener('iron-resize', this._boundSetPosition);

        // Making sure the overlay is closed and removed from DOM after detaching the dropdown.
        this.opened = false;
      }

      notifyResize() {
        super.notifyResize();

        if (this.positionTarget && this.opened) {
          this._setPosition();
          // Schedule another position update (to cover virtual keyboard opening for example)
          requestAnimationFrame(this._setPosition.bind(this));
        }
      }

      /**
       * Fired after the `vaadin-combo-box-dropdown` opens.
       *
       * @event vaadin-combo-box-dropdown-opened
       */
      /**
       * Fired after the `vaadin-combo-box-dropdown` closes.
       *
       * @event vaadin-combo-box-dropdown-closed
       */

      _openedChanged(opened) {
        if (opened) {
          this.$.overlay.style.position = this._isPositionFixed(this.positionTarget) ? 'fixed' : 'absolute';
          this._setPosition();

          window.addEventListener('scroll', this._boundSetPosition, true);
          document.addEventListener('click', this._boundOutsideClickListener, true);
          this.dispatchEvent(new CustomEvent('vaadin-combo-box-dropdown-opened', {bubbles: true, composed: true}));
        } else {
          window.removeEventListener('scroll', this._boundSetPosition, true);
          document.removeEventListener('click', this._boundOutsideClickListener, true);
          this.dispatchEvent(new CustomEvent('vaadin-combo-box-dropdown-closed', {bubbles: true, composed: true}));
        }
      }


      // We need to listen on 'click' event and capture it and close the overlay before
      // propagating the event to the listener in the button. Otherwise, if the clicked button would call
      // open(), this would happen: https://www.youtube.com/watch?v=Z86V_ICUCD4
      _outsideClickListener(event) {
{'fraction_non_alphanumeric': 0.12402597402597403, 'fraction_numerical': 0.0018552875695732839, 'mean_word_length': 2.034337179848016, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 43, 'https://': 8, 'lorem ipsum': 0, 'www.': 2, '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': '2345268', 'n_tokens_mistral': 3051, 'n_tokens_neox': 2864, 'n_words': 640}