<commit_before>// Copyright (c) 2013, Google Inc. Please see the AUTHORS file for details.
// All rights reserved. Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

library spark_widgets.menu_button;

import 'dart:html';

import 'package:polymer/polymer.dart';

import '../common/spark_widget.dart';
import '../spark_menu/spark_menu.dart';
// TODO(ussuri): Temporary. See the comment below.
import '../spark_overlay/spark_overlay.dart';

@CustomTag("spark-menu-button")
class SparkMenuButton extends SparkWidget {
  @published String src = "";
  @published dynamic selected;
  @published String valueAttr = "";
  @published bool opened = false;
  @published bool responsive = false;
  @published String valign = "center";

  SparkOverlay _overlay;
  SparkMenu _menu;

  SparkMenuButton.created(): super.created();

  @override
  void enteredView() {
    super.enteredView();

    _overlay = $['overlay'];
    _menu = $['menu'];
  }

  //* Toggle the opened state of the dropdown.
  void _toggle(bool inOpened) {
    if (inOpened != opened) {
      opened = inOpened;
      // TODO(ussuri): A temporary plug to make spark-overlay see changes
      // in 'opened' when run as deployed code. Just binding via {{opened}}
      // alone isn't detected and the menu doesn't open.
      if (IS_DART2JS) {
        _overlay.opened = opened;
      }
      if (opened) {
        // Enforce focused state so the button can accept keyboard events.
        focus();
        _menu.resetState();
      }
    }
  }

  void clickHandler(Event e) => _toggle(!opened);

  void focusHandler(Event e) => _toggle(true);

  void blurHandler(Event e) => _toggle(false);

  //* Handle the on-opened event from the dropdown. It will be fired e.g. when
  //* mouse is clicked outside the dropdown (with autoClosedDisabled == false).
  void overlayOpenedHandler(CustomEvent e) {
    // Autoclosing is the only event we're interested in.
    if (e.detail == false) {
      opened = false;
    }
  }

  void menuActivateHandler(CustomEvent e, var details) {<commit_msg>Fix spark-menu-button not opening menu on click<commit_after>// Copyright (c) 2013, Google Inc. Please see the AUTHORS file for details.
// All rights reserved. Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

library spark_widgets.menu_button;

import 'dart:html';

import 'package:polymer/polymer.dart';

import '../common/spark_widget.dart';
import '../spark_menu/spark_menu.dart';
// TODO(ussuri): Temporary. See the comment below.
import '../spark_overlay/spark_overlay.dart';

@CustomTag("spark-menu-button")
class SparkMenuButton extends SparkWidget {
  @published String src = "";
  @published dynamic selected;
  @published String valueAttr = "";
  @published bool opened = false;
  @published bool responsive = false;
  @published String valign = "center";

  SparkOverlay _overlay;
  SparkMenu _menu;

  SparkMenuButton.created(): super.created();

  @override
  void enteredView() {
    super.enteredView();

    _overlay = $['overlay'];
    _menu = $['menu'];
  }

  //* Toggle the opened state of the dropdown.
  void _toggle(bool inOpened) {
    if (inOpened != opened) {
      opened = inOpened;
      // TODO(ussuri): A temporary plug to make spark-overlay see changes
      // in 'opened'. Just binding via {{opened}} alone isn't detected and the
      // menu doesn't open.
      _overlay.opened = opened;
      if (opened) {
        // Enforce focused state so the button can accept keyboard events.
        focus();
        _menu.resetState();
      }
    }
  }

  void clickHandler(Event e) => _toggle(!opened);

  void focusHandler(Event e) => _toggle(true);

  void blurHandler(Event e) => _toggle(false);

  //* Handle the on-opened event from the dropdown. It will be fired e.g. when
  //* mouse is clicked outside the dropdown (with autoClosedDisabled == false).
  void overlayOpenedHandler(CustomEvent e) {
    // Autoclosing is the only event we're interested in.
    if (e.detail == false) {
      opened = false;
    }
  }

  void menuActivateHandler(CustomEvent e, var details) {
{'fraction_non_alphanumeric': 0.11458834857968224, 'fraction_numerical': 0.0021665864227250844, 'mean_word_length': 3.213995943204868, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '6982401', 'n_tokens_mistral': 1280, 'n_tokens_neox': 1195, 'n_words': 417}