require(['jquery'], function($) {
  // See Bootstrap's @screen-sm-min
  var smallScreenMinWidth = 768;
  $('.navbar-nav a.dropdown-toggle').not('.dropdown-split-left').each(function() {
    // Add dedicated CSS classes.
    $(this).addClass('dropdown-split-left').closest('li.dropdown').addClass('dropdown-split');
    // Insert the caret/toggle that will be used for tablet and desktop.
    $(this).after('<a href="#" class="dropdown-toggle dropdown-split-right hidden-xs"'
      + ' data-toggle="dropdown"><b class="caret"></b></a>');
    // Enable the default action (navigation link) if the screen is not too small (horizontal menu).
    $(this).click(function(event) {
      if ($(window).width() >= smallScreenMinWidth) {
        // Prevent the menu from opening.
        event.stopPropagation();
        window.location = $(this).attr('href');
      }
    });
  });
});
