PageSourceSearch

https://www.scarsdalelibrary.org/themes/custom/website_theme/js/behaviors.js?tlwt2e

js scarsdalelibrary.org collected 2026-09-25 20:12:56 UTC 4,004 bytes, 129 lines download raw bytes

1"use strict";
2
3/**
4 * Handles JavaScript specific to the Website Theme.
5 */
6(function ($, _ref) {
7  var behaviors = _ref.behaviors;
8
9  /**
10   * Creates a `li` element to be used a Bootstrap 4 carousel indicator.
11   *
12   * @param {number} index
13   *   The index for this indicator, used to track which carousel item it is
14   *   assigned too,
15   *
16   * @return {HTMLLIElement}
17   *   The carousel indicator element.
18   */
19  function createCarouselIndicator(index) {
20    // Generate the carousel indicator item.
21    var li = document.createElement('li'); // Create the attributes the assign the indicator to a slide. This is
22    // based on the slide's index in the array.
23
24    var attrs = {
25      'data-target': '#slideshow-block',
26      'data-slide-to': index
27    }; // Set the first item as active.
28
29    if (index === 0) {
30      attrs["class"] = 'active';
31    } // Add the attributes to the indicator
32
33
34    Object.keys(attrs).forEach(function (attr) {
35      li.setAttribute(attr, attrs[attr]);
36    });
37    return li;
38  }
39  /**
40   * Create the carousel's indicators and add them to the DOM.
41   */
42
43
44  behaviors.createCarouselIndicators = {
45    attach: function attach(context) {
46      once('carousel-indicators', '#slideshow-block .carousel-indicators-container', context).forEach(function (element) {
47        // Create carousel indicators container.
48        var ol = document.createElement('ol'); // Define the carousel indicator class.
49
50        ol.setAttribute('class', 'carousel-indicators'); // For every carousel item available generate an indicator for navigating
51        // between the slides.
52
53        $('.carousel-item', context).each(function (i) {
54          // Append the indicator to the indicator container.
55          ol.appendChild(createCarouselIndicator(i));
56        });
57        $(element).prepend(ol);
58      });
59    }
60  };
61  /**
62   * Set the first carousel item as active.
63   */
64
65  behaviors.firstCarouselItem = {
66    attach: function attach(context) {
67      var carouselItems = once('first-carousel-item', '.carousel-item', context);
68
69      if (carouselItems.length) {
70        $(carouselItems[0]).addClass('active');
71      }
72    }
73  };
74  /**
75   * Initialize slideshow on elements with the class `.carousel`.
76   */
77
78  behaviors.initializeCarousel = {
79    attach: function attach(context) {
80      once('slideshow-block', '#slideshow-block', context).forEach(function (slideshow) {
81        $(slideshow).carousel({
82          interval: 5000,
83          touch: true
84        });
85      });
86    }
87  };
88  /**
89   * Initialize the carousel buttons.
90   *
91   * Since we can't get an ID to our carousel, our own click actions are
92   * required.
93   */
94
95  behaviors.initializeCarouselButtons = {
96    attach: function attach(context) {
97      once('carousel-buttons', '.carousel-control-prev, .carousel-control-next', context).forEach(function (button) {
98        $(button).on('click', function (event) {
99          event.preventDefault(); // Fetch the item that was clicked.
100
101          var $item = $(event.currentTarget); // The action, prev or next, is in a data attribute.
102
103          var action = $item.attr('data-slide'); // Move to the previous or next slideshow item depending on which button
104          // was clicked.
105
106          $('.carousel').carousel(action);
107        });
108      });
109    }
110  };
111  /**
112   * Adds an event to toggle between catalog and database forms.
113   */
114
115  behaviors.toggleSearch = {
116    attach: function attach(context) {
117      once('search-selector', 'input[name="search-switcher"]', context).forEach(function (searchSelector) {
118        $(searchSelector).on('change', function (event) {
119          // Determine the selected radio by it's data attributes.
120          var search = event.currentTarget.dataset.search; // Hide the forms that were not selected.
121
122          $(".lm-search-block:not(.".concat(search, ")"), context).collapse('hide'); // Show the selected form.
123
124          $(".".concat(search), context).collapse('show');
125        });
126      });
127    }
128  };
129})(jQuery, Drupal);

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.