<commit_before>(function($) {

  var focusClass = 'focused';

  /*
    Plugin to create nav menus, show/hide delays, etc.
    Accessible by keyboard too!
  */
  $.fn.mozMenu = function(options) {

    var settings = $.extend({
      showDelay: 100,
      hideDelay: 100,
      submenu: null,
      focusOnOpen: false,
      brickOnClick: false,
      onOpen: function(){},
      onClose: function() {}
    }, options);

    var closeTimeout;
    var showTimeout;

    return $(this).each(function() {
      var $self = $(this);
      var $li = $self.parent();
      var initialized;

      // Brick on click?
      var brick = settings.brickOnClick;
      if(brick) {
        $self.on('click', function(e) {
          if(typeof brick != 'function' || brick(e)) e.preventDefault();
        });
      }

      // Find a submenu.  If one doesn't exist, no need to go further
      var $submenu = (settings.submenu || $li.find('.submenu'));

      // Add a mouseenter / focus event to get the showing of the submenu in motion
      $self.on('mouseenter focus', function() {
        // If this is a fake focus set by us, ignore this
        if($submenu.ignoreFocus) return;

        // If no submenu, go
        if(!$submenu.length) {
          clear(showTimeout);
          $.fn.mozMenu.$openMenu && closeSubmenu($.fn.mozMenu.$openMenu.parent().find('.submenu'));
          return;
        }

        // Lazy-initialize events that aren't needed until an item is entered.
        if(!initialized) {
          initialized = 1;

          // Hide the submenu when the main menu is blurred for hideDelay
          $self.on('mouseleave', function() {
            clear(showTimeout);
            closeSubmenu($submenu);
          });

          // Hide the submenu when the submenu is blurred for hideDelay
          $submenu.on('mouseleave', function() {
            clear(showTimeout);
            closeSubmenu($submenu);
          });

          // Cancel the close timeout if moving from main menu item to submenu
          $submenu.on('mouseenter', function() {
            clear(closeTimeout);
          });

          // Close if it's the last link and they press tab *or* the hit escape
          $submenu.on('keyup', function(e) {
            if(e.keyCode == 27) { // Escape
              closeSubmenu($submenu);
              $submenu.ignoreFocus = true;
              setTimeout(function() { $submenu.ignoreFocus = false; }, 10);
              $self[0].focus();
            }
            else if(e.keyCode == 9) { // Tab
              if(e.target == $submenu.find('a').last().get(0)) {
                closeSubmenu($submenu);
              }
            }
          });
        }

        // If there's an open submenu and it's not this one, close it
        // Used for tab navigation from submenu to the next menu item
        if($.fn.mozMenu.$openMenu && $.fn.mozMenu.$openMenu != $self) {
          clear(showTimeout);
          closeSubmenu($.fn.mozMenu.$openMenu.parent().find('.submenu'));
        }
        else if($.fn.mozMenu.$openMenu == $self) {
          clear(closeTimeout);
        }

        // Keep the open menu on this fn itself so only one menu can be open at any time,
        // regardless of the instance or menu group
        $.fn.mozMenu.$openMenu = $self;

        // Show my submenu after the showDelay
        showTimeout = setTimeout(function() {<commit_msg>fixes Bug 939981 - focus on the last submenu link closes the submenu<commit_after>(function($) {

  var focusClass = 'focused';

  /*
    Plugin to create nav menus, show/hide delays, etc.
    Accessible by keyboard too!
  */
  $.fn.mozMenu = function(options) {

    var settings = $.extend({
      showDelay: 100,
      hideDelay: 100,
      submenu: null,
      focusOnOpen: false,
      brickOnClick: false,
      onOpen: function(){},
      onClose: function() {}
    }, options);

    var closeTimeout;
    var showTimeout;

    return $(this).each(function() {
      var $self = $(this);
      var $li = $self.parent();
      var initialized;

      // Brick on click?
      var brick = settings.brickOnClick;
      if(brick) {
        $self.on('click', function(e) {
          if(typeof brick != 'function' || brick(e)) e.preventDefault();
        });
      }

      // Find a submenu.  If one doesn't exist, no need to go further
      var $submenu = (settings.submenu || $li.find('.submenu'));

      // Add a mouseenter / focus event to get the showing of the submenu in motion
      $self.on('mouseenter focus', function() {
        // If this is a fake focus set by us, ignore this
        if($submenu.ignoreFocus) return;

        // If no submenu, go
        if(!$submenu.length) {
          clear(showTimeout);
          $.fn.mozMenu.$openMenu && closeSubmenu($.fn.mozMenu.$openMenu.parent().find('.submenu'));
          return;
        }

        // Lazy-initialize events that aren't needed until an item is entered.
        if(!initialized) {
          initialized = 1;

          // Hide the submenu when the main menu is blurred for hideDelay
          $self.on('mouseleave focusout', function() {
            clear(showTimeout);
            closeSubmenu($submenu);
          });

          // Hide the submenu when the submenu is blurred for hideDelay
          $submenu.on('mouseleave', function() {
            clear(showTimeout);
            closeSubmenu($submenu);
          });

          // Cancel the close timeout if moving from main menu item to submenu
          $submenu.on('mouseenter focusin', function() {
            clear(closeTimeout);
          });

          // Close if it's the last link and they press tab *or* the hit escape
          $submenu.on('keyup', function(e) {
            if(e.keyCode == 27) { // Escape
              closeSubmenu($submenu);
              $submenu.ignoreFocus = true;
              setTimeout(function() { $submenu.ignoreFocus = false; }, 10);
              $self[0].focus();
            }
          });
        }

        // If there's an open submenu and it's not this one, close it
        // Used for tab navigation from submenu to the next menu item
        if($.fn.mozMenu.$openMenu && $.fn.mozMenu.$openMenu != $self) {
          clear(showTimeout);
          closeSubmenu($.fn.mozMenu.$openMenu.parent().find('.submenu'));
        }
        else if($.fn.mozMenu.$openMenu == $self) {
          clear(closeTimeout);
        }

        // Keep the open menu on this fn itself so only one menu can be open at any time,
        // regardless of the instance or menu group
        $.fn.mozMenu.$openMenu = $self;

        // Show my submenu after the showDelay
        showTimeout = setTimeout(function() {
{'fraction_non_alphanumeric': 0.12518740629685157, 'fraction_numerical': 0.0047976011994002995, 'mean_word_length': 1.899174272055628, 'pattern_counts': {'":': 0, '<': 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': '2112694', 'n_tokens_mistral': 1914, 'n_tokens_neox': 1836, 'n_words': 560}