<commit_before>/*
 * Artefact Web Extensions
 *
 * Copyright 2012, Artefact Group LLC
 * Licensed under MIT.
 */
(function(Awe, global, document, undefined) {

  // Stack of popups and their associated state
  var _popupStack = [];
    
  /* 
   * purpose: Helper function to ensure that we have an element. Allows called 
   * of ui* functions to pass in either an HTML element object or an id string, 
   * in which case we will look it up by id.
   */
  var ensureElement = function(element) {
    if(typeof(element) == "string") {
      var el = document.getElementById(element);
      if(!el) throw "cannot find element with id '" + element + "'";
      return el;
    } else {
      return element;
    }
  }
  
  
  /* 
   * purpose: safely get the top of _popupStack. Returns null if stack is empty.
   */
  var getTopOfPopupStack = function() {
    return (_popupStack.length > 0) ? _popupStack[_popupStack.length-1] : null;
  }
  
  
  /*
   * purpose: listens to mousedown events in the document and handles the 
   * dismissing of popups. Curent implemenation dismisses the top-most popup
   * if the mousedown occured outside its boundary.
   */
  var onMouseDown = function(e) {
    var t = getTopOfPopupStack();
    if(t) {
      e = e || window.event;
      if (!xHasPoint(t.element, e.pageX, e.pageY)) {
        Awe.hidePopup(t.element, true);
      }
    }
    return;
  }
  
  
  /*
   * purpose: listen to keypress events and dismiss the top-most popup if the
   * ESC key is pressed.
   */
  var onKeyDown = function(e) {
    var t = getTopOfPopupStack();
    if(t) {
      e = e || window.event;
      if (e.keyCode == 27)
      {
        Awe.hidePopup(t.element, true);
      }
    }
    return;
  }
  
  
  /* 
   * method: Awe.uiPopup<commit_msg>Update popup dismiss logic to dismiss all popups when a mousedown occurs outside the bounds of any open popups.<commit_after>/*
 * Artefact Web Extensions
 *
 * Copyright 2012, Artefact Group LLC
 * Licensed under MIT.
 */
(function(Awe, global, document, undefined) {

  // Stack of popups and their associated state
  var _popupStack = [];
    
  /* 
   * purpose: Helper function to ensure that we have an element. Allows called 
   * of ui* functions to pass in either an HTML element object or an id string, 
   * in which case we will look it up by id.
   */
  var ensureElement = function(element) {
    if(typeof(element) == "string") {
      var el = document.getElementById(element);
      if(!el) throw "cannot find element with id '" + element + "'";
      return el;
    } else {
      return element;
    }
  }
  
  
  /* 
   * purpose: safely get the top of _popupStack. Returns null if stack is empty.
   */
  var getTopOfPopupStack = function() {
    return (_popupStack.length > 0) ? _popupStack[_popupStack.length-1] : null;
  }
  
  
  /*
   * purpose: listens to mousedown events in the document and handles the 
   * dismissing of popups. If the mousedown even occured inside the bounds of 
   * an open popup, all popups up to, but not including it are dismissed.
   * If the mousedown was outside the bounds of all popups, the entire popup
   * stack will be dismissed.
   */
  var onMouseDown = function(e) {
    var t = getTopOfPopupStack();
    while(t) {
      e = e || window.event;
      if (!xHasPoint(t.element, e.pageX, e.pageY)) {
        Awe.hidePopup(t.element, true);
        t = getTopOfPopupStack();
      } else {
        break;
      }
    }
    return;
  }
  
  
  /*
   * purpose: listen to keypress events and dismiss the top-most popup if the
   * ESC key is pressed.
   */
  var onKeyDown = function(e) {
    var t = getTopOfPopupStack();
    if(t) {
      e = e || window.event;
      if (e.keyCode == 27)
      {
        Awe.hidePopup(t.element, true);
      }
    }
    return;
  }
  
  
  /* 
   * method: Awe.uiPopup
{'fraction_non_alphanumeric': 0.1034392912975508, 'fraction_numerical': 0.004168837936425221, 'mean_word_length': 2.355769230769231, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3124376', 'n_tokens_mistral': 1254, 'n_tokens_neox': 1219, 'n_words': 413}