PageSourceSearch

https://www.historytoday.com/modules/contrib/facets/js/soft-limit.js?v=10.4.7

js historytoday.com collected 2026-10-01 09:16:41 UTC 2,364 bytes, 73 lines download raw bytes

1/**
2 * @file
3 * Provides the soft limit functionality.
4 */
5
6(function ($, once) {
7
8  'use strict';
9
10  Drupal.behaviors.facetSoftLimit = {
11    attach: function (context, settings) {
12      if (settings.facets.softLimit !== 'undefined') {
13        $.each(settings.facets.softLimit, function (facet, limit) {
14          Drupal.facets.applySoftLimit(facet, limit, settings);
15        });
16      }
17    }
18  };
19
20  Drupal.facets = Drupal.facets || {};
21
22  /**
23   * Applies the soft limit UI feature to a specific facets list.
24   *
25   * @param {string} facet
26   *   The facet id.
27   * @param {string} limit
28   *   The maximum amount of items to show.
29   * @param {object} settings
30   *   Settings.
31   */
32  Drupal.facets.applySoftLimit = function (facet, limit, settings) {
33    var zero_based_limit = (limit - 1);
34    var facet_id = facet;
35    var facetsList = $('ul[data-drupal-facet-id="' + facet_id + '"]');
36
37    // In case of multiple instances of a facet, we need to key them.
38    if (facetsList.length > 1) {
39      facetsList.each(function (key, $value) {
40        $(this).attr('data-drupal-facet-id', facet_id + '-' + key);
41      });
42    }
43
44    // Hide facets over the limit.
45    facetsList.each(function () {
46      $(once('applysoftlimit', $(this).children('li:gt(' + zero_based_limit + ')'))).hide();
47    });
48
49    // Add "Show more" / "Show less" links.
50    $(once('applysoftlimit', facetsList.filter(function () {
51      return $(this).find('li').length > limit;
52    }))).each(function () {
53      var facet = $(this);
54      var showLessLabel = settings.facets.softLimitSettings[facet_id].showLessLabel;
55      var showMoreLabel = settings.facets.softLimitSettings[facet_id].showMoreLabel;
56      $('<a href="#" class="facets-soft-limit-link"></a>')
57        .text(showMoreLabel)
58        .on('click', function () {
59          if (facet.find('li:hidden').length > 0) {
60            facet.find('li:gt(' + zero_based_limit + ')').slideDown();
61            facet.find('li:lt(' + (zero_based_limit + 2) + ') a, li:lt(' + (zero_based_limit + 2) + ') input').focus();
62            $(this).addClass('open').text(showLessLabel);
63          }
64          else {
65            facet.find('li:gt(' + zero_based_limit + ')').slideUp();
66            $(this).removeClass('open').text(showMoreLabel);
67          }
68          return false;
69        }).insertAfter($(this));
70    });
71  };
72
73})(jQuery, once);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.