<commit_before>/** 
 * @license
 * Copyright 2017 The FOAM Authors. All Rights Reserved.
 * http://www.apache.org/licenses/LICENSE-2.0
 */

foam.CLASS({
  package: 'foam.u2.md',
  name: 'OverlayDropdown',
  extends: 'foam.u2.Element',

  imports: [
    'window'
  ],

  exports: [
    'as dropdown'
  ],

  documentation: 'A popup overlay that grows from the top-right corner of ' +
      'its container. Useful for e.g. "..." overflow menus in action bars. ' +
      'Just $$DOC{ref:".add"} things to this container.',

  properties: [
    {
      class: 'Float',
      name: 'height',
      value: 0
    },
    {
      class: 'Boolean',
      name: 'opened',
      documentation: 'True when the overlay has been commanded to be open. ' +
          'It might still be animating; see $$DOC{ref:".animationComplete"}.',
    },
    {
      class: 'Boolean',
      name: 'animationComplete',
      documentation: 'True when an animation is running. The overlay hasn\'t ' +
          'really reached the state commanded by $$DOC{ref:".opened"} until ' +
          'this is true.',
      value: true
    },
    {
      name: 'dropdownE_',
      factory: function() {
        return this.E('dropdown');
      }
    },
    {
      name: 'addToSelf_',
      value: false
    }
  ],

  methods: [
    function add() {
      if ( this.addToSelf_ ) this.SUPER.apply(this, arguments);
      else this.dropdownE_.add.apply(this.dropdownE_, arguments);
      return this;
    },

    function open() {
      if ( this.opened ) return;
      this.opened = true;
      this.dropdownE_.style({ height: this.getFullHeight() + 'px' });
      this.animationComplete = false;
    },

    function close() {
      if ( ! this.opened ) return;
      this.height = 0;
      this.dropdownE_.style({ height: 0 + 'px' });
      this.opened = false;
    },

    function getFullHeight() {
      if ( this.state !== this.LOADED ) return;

      var myStyle = this.window.getComputedStyle(this.dropdownE_.el());

      var border = 0;
      ['border-top', 'border-bottom'].forEach(function(name) {
        var match = myStyle[name].match(/^([0-9]+)px/);
        if ( match ) border += parseInt(match[1]);
      });

      var last = this.dropdownE_.children[this.dropdownE_.children.length - 1].el();
      var margin = parseInt(this.window.getComputedStyle(last)['margin-bottom']);
      if ( Number.isNaN(margin) ) margin = 0;

      return Math.min(border + last.offsetTop + last.offsetHeight + margin,
          this.window.innerHeight - this.dropdownE_.el().getBoundingClientRect().top);
    },

    function initE() {
      this.addToSelf_ = true;
      this.addClass(this.myClass('container'));
      var view = this;

      this.addClass(this.slot(function(open) {
        this.shown = open;
      }, this.opened$));

      this.start('dropdown-overlay')
          .addClass(this.myClass('overlay'))
          .addClass(this.slot(function(open) {
            return ( open ) ? view.myClass('zeroOverlay') : view.myClass('initialOverlay')
          }, this.opened$))
          .on('click', this.onCancel)
          .end();

      this.dropdownE_.addClass(this.myClass())
          .addClass(this.slot(function(openComplete) {
            return openComplete ? this.myClass('open') : '';
          }, this.opened$ && this.animationComplete$))
          .on('transitionend', this.onTransitionEnd)
          .on('mouseleave', this.onMouseLeave)
          .on('click', this.onClick);

      this.add(this.dropdownE_);

      this.addToSelf_ = false;
    }
  ],

  axioms: [
    foam.u2.CSS.create({
      code: function CSS() {/*
      ^overlay {
        position: fixed;
        z-index: 1009;
      }

      ^container {
        position: relative;
        right: 0;<commit_msg>Updated spacing/indentation<commit_after>/** 
 * @license
 * Copyright 2017 The FOAM Authors. All Rights Reserved.
 * http://www.apache.org/licenses/LICENSE-2.0
 */

foam.CLASS({
  package: 'foam.u2.md',
  name: 'OverlayDropdown',
  extends: 'foam.u2.Element',

  imports: [
    'window'
  ],

  exports: [
    'as dropdown'
  ],

  documentation: 'A popup overlay that grows from the top-right corner of ' +
      'its container. Useful for e.g. "..." overflow menus in action bars. ' +
      'Just $$DOC{ref:".add"} things to this container.',

  properties: [
    {
      class: 'Float',
      name: 'height',
      value: 0
    },
    {
      class: 'Boolean',
      name: 'opened',
      documentation: 'True when the overlay has been commanded to be open. ' +
          'It might still be animating; see $$DOC{ref:".animationComplete"}.',
    },
    {
      class: 'Boolean',
      name: 'animationComplete',
      documentation: 'True when an animation is running. The overlay hasn\'t ' +
          'really reached the state commanded by $$DOC{ref:".opened"} until ' +
          'this is true.',
      value: true
    },
    {
      name: 'dropdownE_',
      factory: function() {
        return this.E('dropdown');
      }
    },
    {
      name: 'addToSelf_',
      value: false
    }
  ],

  methods: [
    function add() {
      if ( this.addToSelf_ ) this.SUPER.apply(this, arguments);
      else this.dropdownE_.add.apply(this.dropdownE_, arguments);
      return this;
    },

    function open() {
      if ( this.opened ) return;
      this.opened = true;
      this.dropdownE_.style({ height: this.getFullHeight() + 'px' });
      this.animationComplete = false;
    },

    function close() {
      if ( ! this.opened ) return;
      this.height = 0;
      this.dropdownE_.style({ height: 0 + 'px' });
      this.opened = false;
    },

    function getFullHeight() {
      if ( this.state !== this.LOADED ) return;

      var myStyle = this.window.getComputedStyle(this.dropdownE_.el());

      var border = 0;
      ['border-top', 'border-bottom'].forEach(function(name) {
        var match = myStyle[name].match(/^([0-9]+)px/);
        if ( match ) border += parseInt(match[1]);
      });

      var last = this.dropdownE_.children[this.dropdownE_.children.length - 1].el();
      var margin = parseInt(this.window.getComputedStyle(last)['margin-bottom']);
      if ( Number.isNaN(margin) ) margin = 0;

      return Math.min(border + last.offsetTop + last.offsetHeight + margin,
          this.window.innerHeight - this.dropdownE_.el().getBoundingClientRect().top);
    },

    function initE() {
      this.addToSelf_ = true;
      this.addClass(this.myClass('container'));
      var view = this;

      this.addClass(this.slot(function(open) {
        this.shown = open;
      }, this.opened$));

      this.start('dropdown-overlay')
        .addClass(this.myClass('overlay'))
        .addClass(this.slot(function(open) {
          return ( open ) ? view.myClass('zeroOverlay') : view.myClass('initialOverlay')
        }, this.opened$))
        .on('click', this.onCancel)
      .end();

      this.dropdownE_.addClass(this.myClass())
          .addClass(this.slot(function(openComplete) {
            return openComplete ? this.myClass('open') : '';
          }, this.opened$ && this.animationComplete$))
          .on('transitionend', this.onTransitionEnd)
          .on('mouseleave', this.onMouseLeave)
          .on('click', this.onClick);

      this.add(this.dropdownE_);

      this.addToSelf_ = false;
    }
  ],

  axioms: [
    foam.u2.CSS.create({
      code: function CSS() {/*
      ^overlay {
        position: fixed;
        z-index: 1009;
      }

      ^container {
        position: relative;
        right: 0;
{'fraction_non_alphanumeric': 0.15174527045030642, 'fraction_numerical': 0.0061284305888622435, 'mean_word_length': 2.2795980777632154, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '799683', 'n_tokens_mistral': 2384, 'n_tokens_neox': 2283, 'n_words': 494}