<commit_before>require(['jquery', 'bootstrap'], function($) {
  $(document).ready(function() {
  
    // Fix the bad location of the dropdown menu when the trigger is close to the end of the screen.
    // See: http://jira.xwiki.org/browse/XWIKI-12609
    $(document).on('shown.bs.dropdown', function () {
      $('[aria-expanded="true"]').each( function() {
        var toggle    = $(this);
        var menu      = toggle.next('.dropdown-menu');
        var menuWidth = menu.outerWidth();
        // if the right corner of the menu is after the end of the screen
        if (menu.offset().left + menuWidth > $(document.body).outerWidth()) {
          // we put that corner at the same place than the toggle's right corner
          var newLocation = toggle.offset().left + toggle.outerWidth() - menuWidth;
          // but don't put it negative, or the user will have to scroll to the left!
          if (newLocation < 0) {
            newLocation = 0;
          }
          menu.offset({'left': newLocation});
        }
      });
    });
    
    // Some variables used in the next 2 functions
    var globalSearch = $('#globalsearch');
    var globalSearchInput = globalSearch.find('input');
    var globalSearchButton = globalSearch.find('button');
    
    // Open the global search when the user click on the global search button
    globalSearchButton.click(function(event) {
      if (!globalSearch.hasClass('globalsearch-close') && globalSearchInput.val().length > 0) {
        return true;
      }
      globalSearch.removeClass('globalsearch-close');
      globalSearchInput.focus();
      return false;
    });
    
    // Close the global search when the focus is lost
    globalSearchInput.focusout(function() {
      // In order to let the main thread setting the focus to the new element, we execute the following code
      // in a callback.
      setTimeout( function () {
        // We close the global search only if the focus is on the search inpur or the search button
        if (document.activeElement !== globalSearchButton[0] && document.activeElement !== globalSearchInput[0]) {
          globalSearch.addClass('globalsearch-close');
        }
      }, 1);
    });
    
    // When the drawer is close, collapse sub items
    $(body).on('drawer.closed', function() {
      $('.drawer-menu-sub-item').removeClass('in').attr('aria-expanded', 'false');
    });
  
  });
});<commit_msg>XWIKI-12635: Search input improvements on the top bar.<commit_after>require(['jquery', 'bootstrap'], function($) {
  $(document).ready(function() {
  
    // Fix the bad location of the dropdown menu when the trigger is close to the end of the screen.
    // See: http://jira.xwiki.org/browse/XWIKI-12609
    $(document).on('shown.bs.dropdown', function () {
      $('[aria-expanded="true"]').each( function() {
        var toggle    = $(this);
        var menu      = toggle.next('.dropdown-menu');
        var menuWidth = menu.outerWidth();
        // if the right corner of the menu is after the end of the screen
        if (menu.offset().left + menuWidth > $(document.body).outerWidth()) {
          // we put that corner at the same place than the toggle's right corner
          var newLocation = toggle.offset().left + toggle.outerWidth() - menuWidth;
          // but don't put it negative, or the user will have to scroll to the left!
          if (newLocation < 0) {
            newLocation = 0;
          }
          menu.offset({'left': newLocation});
        }
      });
    });
    
    // Some variables used in the next 2 functions
    var globalSearch = $('#globalsearch');
    var globalSearchInput = globalSearch.find('input');
    var globalSearchButton = globalSearch.find('button');
    
    // Open the global search when the user click on the global search button
    globalSearchButton.click(function(event) {
      if (!globalSearch.hasClass('globalsearch-close') && globalSearchInput.val().length > 0) {
        return true;
      }
      globalSearch.removeClass('globalsearch-close');
      globalSearchInput.focus();
      return false;
    });
    
    // Close the global search when the focus is lost
    globalSearchInput.focusout(function() {
      // In order to let the main thread setting the focus to the new element, we execute the following code
      // in a callback.
      setTimeout( function () {
        // We close the global search only if the focus is not on the search input or the search button.
        // Without this, the global search would be close each time the user click on the button (even when it's for
        // actually performing the search).
        if (document.activeElement !== globalSearchButton[0] && document.activeElement !== globalSearchInput[0]) {
          globalSearch.addClass('globalsearch-close');
        }
      }, 1);
    });
    
    // When the drawer is close, collapse sub items
    $(body).on('drawer.closed', function() {
      $('.drawer-menu-sub-item').removeClass('in').attr('aria-expanded', 'false');
    });
  
  });
});
{'fraction_non_alphanumeric': 0.12597014925373134, 'fraction_numerical': 0.005771144278606965, 'mean_word_length': 2.5469301340860975, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '4746670', 'n_tokens_mistral': 1354, 'n_tokens_neox': 1329, 'n_words': 448}