<commit_before>(function () {

  var currentScript = document._currentScript || document.currentScript;

  var BrickActionMenuElementPrototype = Object.create(HTMLElement.prototype);

  // Element attribute handlers
  var attrs = {

    "visible": function (oldVal, newVal) {
      // Be very particular about what values of "visible" mean not visible.
      newVal = ('undefined' !== typeof newVal) &&
               (null !== newVal) &&
               (false !== newVal);

      if (oldVal === newVal) {
        return;
      } else if (newVal === true) {
        this.show(null, true);
      } else if (newVal === false) {
        this.hide(true);
      }
    }

  };

  // Custom methods
  
  BrickActionMenuElementPrototype.show = function (callback, immediate) {
    if (this.ns.visible) { return; }
    this.ns.visible = true;
    this.ns.callback = callback;
    this.root.classList.remove('fade-out');
    this.root.classList.remove('hide');
    this.root.classList.add(immediate ? 'show' : 'fade-in');
  };

  BrickActionMenuElementPrototype.hide = function (immediate) {
    if (!this.ns.visible) { return; }
    this.ns.visible = false;
    this.ns.callback = null;
    this.root.classList.remove('fade-in');
    this.root.classList.remove('show');
    this.root.classList.add(immediate ? 'hide' : 'fade-out');
  };

  var EV_PICK = 'pick';
  var RE_BUTTON = /^button$/i;

  // Lifecycle methods

  BrickActionMenuElementPrototype.createdCallback = function () {

    var importDoc = currentScript.ownerDocument;
    var template = importDoc.getElementById('brick-action-menu-template');

    this.ns = {
      visible: false
    };

    // create shadowRoot and append template to it.
    var shadowRoot = this.createShadowRoot();
    shadowRoot.appendChild(template.content.cloneNode(true));

    this.root = shadowRoot.querySelector('form');

    // HACK: Annotate the menu for styling if there's a cancel button
    if (this.querySelector('button.cancel')) {
      this.root.setAttribute('data-with-cancel', 'true');
    }

    // Squelch the form submission process
    this.addEventListener('submit', function (e) {
      e.preventDefault();
      e.stopPropagation();
    });

    // Event delegation for all buttons in the menu
    this.addEventListener('click', function (e) {
      if (!RE_BUTTON.test(e.target.tagName)) { return; }

      // Do we have a callback supplied from show()?
      if (this.ns.callback) {
        // HACK: Defer the callback, yielding for animations & etc.
        (function (cb) {
          setTimeout(function () { cb(e.target); }, 0.1);
        })(this.ns.callback);
        
        // Clear the callback (which is why we just used a closure to defer)
        this.ns.callback = null;
      }

      // Dispatch a custom event for the menu item pick
      e.target.dispatchEvent(new CustomEvent(EV_PICK, {
        bubbles: true
      }));

      // Finish up by hiding the menu.
      return this.hide();
    });
  };

  BrickActionMenuElementPrototype.attachedCallback = function () {
    for (var k in attrs) {
      if (this.hasAttribute(k)) {
        attrs[k].call(this, undefined, this.getAttribute(k));
      }
    }
  };

  BrickActionMenuElementPrototype.attributeChangedCallback = function (attr, oldVal, newVal) {
    if (attr in attrs) {
      attrs[attr].call(this, oldVal, newVal);
    }
  };

  BrickActionMenuElementPrototype.detachedCallback = function () {
    // TODO: Do I really need to do this? Memory leak superstition.
    this.root = this.ns = null;
  };

  // Property handlers, magically boilerplated from attribute handlers.
  var props = {};
  function makeProp (name) {
    return {
      get: function () {
        return this.ns[name];
      },
      set: function (newVal) {
        return this.attributeChangedCallback(name, this.ns[name], newVal);
      }
    };
  }
  for (var name in attrs) {
    props[name] = makeProp(name);
  }
  Object.defineProperties(BrickActionMenuElementPrototype, props);

  // Register the element<commit_msg>Stop carrying an element reference around<commit_after>(function () {

  var currentScript = document._currentScript || document.currentScript;

  var BrickActionMenuElementPrototype = Object.create(HTMLElement.prototype);

  // Element attribute handlers
  var attrs = {

    "visible": function (oldVal, newVal) {
      // Be very particular about what values of "visible" mean not visible.
      newVal = ('undefined' !== typeof newVal) &&
               (null !== newVal) &&
               (false !== newVal);

      if (oldVal === newVal) {
        return;
      } else if (newVal === true) {
        this.show(null, true);
      } else if (newVal === false) {
        this.hide(true);
      }
    }

  };

  // Custom methods
  
  BrickActionMenuElementPrototype.show = function (callback, immediate) {
    if (this.ns.visible) { return; }
    
    this.ns.visible = true;
    this.ns.callback = callback;
    
    var form = shadowRoot.querySelector('form');
    form.classList.remove('fade-out');
    form.classList.remove('hide');
    form.classList.add(immediate ? 'show' : 'fade-in');
  };

  BrickActionMenuElementPrototype.hide = function (immediate) {
    if (!this.ns.visible) { return; }
    
    this.ns.visible = false;
    this.ns.callback = null;

    var form = shadowRoot.querySelector('form');
    form.classList.remove('fade-in');
    form.classList.remove('show');
    form.classList.add(immediate ? 'hide' : 'fade-out');
  };

  var EV_PICK = 'pick';
  var RE_BUTTON = /^button$/i;

  // Lifecycle methods

  BrickActionMenuElementPrototype.createdCallback = function () {

    var importDoc = currentScript.ownerDocument;
    var template = importDoc.getElementById('brick-action-menu-template');

    this.ns = {
      visible: false
    };

    // create shadowRoot and append template to it.
    var shadowRoot = this.createShadowRoot();
    shadowRoot.appendChild(template.content.cloneNode(true));

    // HACK: Annotate the menu for styling if there's a cancel button
    if (this.querySelector('button.cancel')) {
      shadowRoot.querySelector('form')
        .setAttribute('data-with-cancel', 'true');
    }

    // Squelch the form submission process
    this.addEventListener('submit', function (e) {
      e.preventDefault();
      e.stopPropagation();
    });

    // Event delegation for all buttons in the menu
    this.addEventListener('click', function (e) {
      if (!RE_BUTTON.test(e.target.tagName)) { return; }

      // Do we have a callback supplied from show()?
      if (this.ns.callback) {
        // HACK: Defer the callback, yielding for animations & etc.
        (function (cb) {
          setTimeout(function () { cb(e.target); }, 0.1);
        })(this.ns.callback);
        
        // Clear the callback (which is why we just used a closure to defer)
        this.ns.callback = null;
      }

      // Dispatch a custom event for the menu item pick
      e.target.dispatchEvent(new CustomEvent(EV_PICK, {
        bubbles: true
      }));

      // Finish up by hiding the menu.
      return this.hide();
    });
  };

  BrickActionMenuElementPrototype.attachedCallback = function () {
    for (var k in attrs) {
      if (this.hasAttribute(k)) {
        attrs[k].call(this, undefined, this.getAttribute(k));
      }
    }
  };

  BrickActionMenuElementPrototype.attributeChangedCallback = function (attr, oldVal, newVal) {
    if (attr in attrs) {
      attrs[attr].call(this, oldVal, newVal);
    }
  };

  BrickActionMenuElementPrototype.detachedCallback = function () {
  };

  // Property handlers, magically boilerplated from attribute handlers.
  var props = {};
  function makeProp (name) {
    return {
      get: function () {
        return this.ns[name];
      },
      set: function (newVal) {
        return this.attributeChangedCallback(name, this.ns[name], newVal);
      }
    };
  }
  for (var name in attrs) {
    props[name] = makeProp(name);
  }
  Object.defineProperties(BrickActionMenuElementPrototype, props);

  // Register the element
{'fraction_non_alphanumeric': 0.1297700435052828, 'fraction_numerical': 0.0004972032318210068, 'mean_word_length': 2.6756509821836456, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, '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': '4175869', 'n_tokens_mistral': 2400, 'n_tokens_neox': 2373, 'n_words': 577}