PageSourceSearch

https://www.bnf.fr/modules/custom/toc_js/js/toc_js.js?tm77ui

js bnf.fr collected 2026-10-01 07:39:45 UTC 5,857 bytes, 171 lines download raw bytes

1/**
2 * @file
3 * Toc_js.
4 */
5
6(function ($) {
7  'use strict';
8
9  Drupal.behaviors.toc_js = {
10    attach: function(context, settings) {
11
12      var verboseIdCache = {};
13
14      $('.toc-js', context).each(function () {
15        var nav = $(this).find('nav');
16        var options = {
17          listType: $(this).data('list-type') == 'ol' ? '<ol/>' : '<ul/>',
18          selectors: $(this).data('selectors') || 'h2, h3',
19          container: $(this).data('container') || 'body',
20          scrollToOffset: $(this).data('scroll-to-offset') || 0,
21          prefix: $(this).data('prefix') || 'toc',
22          backToTop: !!$(this).data('back-to-top'),
23          backToTopLabel: $(this).data('back-to-top-label') || 'Back to top',
24          letterCase: $(this).data('letter-case') || 'lowercase',
25          highlightOnScroll: !!$(this).data('highlight-on-scroll'),
26          highlightOffset: $(this).data('highlight-offset') || 100,
27        };
28
29        if (!$(this).data('smooth-scrolling')) {
30          options.smoothScrolling = false;
31        }
32
33        // Fix a bug because anchorName are not unique if heading has same text.
34        // Override the anchorName function. See https://github.com/jgallen23/toc/pull/69
35        options.anchorName = function(i, heading, prefix) {
36          if (heading.id.length) {
37            return heading.id;
38          }
39          var candidateId = $(heading).text().replace(/[^a-z0-9]/ig, ' ').replace(/\s+/g, '-').toLowerCase();
40          if (verboseIdCache[candidateId]) {
41            var j = 2;
42            // Fix is here. Added '-' between candidateUd and j.
43            while (verboseIdCache[candidateId + '-' + j]) {
44              j++;
45            }
46            candidateId = candidateId + '-' + j;
47
48          }
49          verboseIdCache[candidateId] = true;
50
51          return prefix + '-' + candidateId;
52        };
53
54        nav.toc(options);
55
56        // Suppression des attributs non neccessaires suite au conseils ATALEN
57
58        // Add aria attributes on toc.
59        // nav.find('ul').attr('role', 'menubar');
60        // nav.find('li').each(function () {
61        //   $(this).attr('role', 'presentation');
62        // });
63        // nav.find('a').each(function () {
64        //   $(this).attr('aria-label', $(this).text());
65        // });
66
67
68        // Custom implementation.
69        // Add back to top link on headings and id to toc element.
70        // Remove when https://github.com/jgallen23/toc/pull/69 is merged.
71        var opts = $.extend({}, nav.toc.defaults, options);
72        if (opts.backToTop) {
73          var scrollTo = function(e, callback) {
74            if (opts.smoothScrolling && typeof opts.smoothScrolling === 'function') {
75              e.preventDefault();
76              var elScrollTo = $(e.target).attr('href');
77
78              opts.smoothScrolling(elScrollTo, opts, callback);
79            }
80            $('li', self).removeClass(opts.activeClass);
81            $(e.target).parent().addClass(opts.activeClass);
82          };
83
84          nav.find('a').each(function () {
85            var container = $(opts.container);
86            var anchor = $(this).attr('href').replace(/^#/, '');
87            var anchorNameToTop = anchor + '-to-top';
88            $(this).attr('id', anchorNameToTop);
89
90            var $span = container.find('span[id="' + anchor + '"]');
91            var anchorToTop = $('<a/>')
92              .attr('href', '#' + anchorNameToTop)
93              .addClass('back-to-top')
94              .text(opts.backToTopLabel)
95              .insertAfter($span)
96              .bind('click', function(e) {
97                scrollTo(e, function() {
98                });
99                nav.trigger('selected', $(this).attr('href'));
100              });
101          });
102        }
103
104      });
105      // End custom back to top implementation.
106
107      // Hide toc (and the title) if no heading found or minimum not reached.
108      $('.toc-js', context).each(function () {
109        var n = $(this).find('li').length;
110        if (!n) {
111          $(this).hide();
112        }
113        var minimum = $(this).data('selectors-minimum') || 0;
114        if (minimum > 0 && n < minimum) {
115          $(this).hide();
116        }
117      });
118
119      // Stick the toc.
120      function sticky_relocate() {
121        $('.toc-js.sticky', context).each(function () {
122          var sticky = $(this);
123          var stopSelector = $(this).data('sticky-stop') || '';
124          var stopPadding = $(this).data('sticky-stop-padding') || 0;
125          var windowTop = $(window).scrollTop();
126          var stickyTop = $('#sticky-anchor').offset().top;
127          var stickyHeight = sticky.height();
128          var stickOffset = $(this).data('sticky-offset') || 0;
129
130          if ($(stopSelector).length) {
131            var stickyStop = $(stopSelector).offset().top;
132          }
133          else {
134            stickyStop = 0;
135          }
136
137          if (stickyStop > 0 && (windowTop + stickyHeight + stickOffset > stickyStop - stopPadding))
138            sticky.css({top: (windowTop + stickyHeight - stickyStop + stopPadding) * -1});
139          else if (windowTop + stickOffset > stickyTop) {
140            sticky.addClass('is-sticked');
141            sticky.css({top: stickOffset})
142          } else {
143            sticky.removeClass('is-sticked').css({top: 'initial'});
144          }
145        });
146
147      }
148
149      $(window).scroll(sticky_relocate);
150      sticky_relocate();
151
152      /** RELOCATE STYCKY ON RESIZE JUST AT 1024 ANO #22430 **/
153      // $(window).on("resize", function(){
154      //   let windowWidth = $(window).width();
155      //   if (windowWidth == 1023 || windowWidth == 1024) {
156      //     sticky_relocate();
157      //   }
158      // });
159      /** END RELOCATE STYCKY ON RESIZE JUST AT 1024 ANO #22430 **/
160    }
161  };
162
163}(jQuery));
164
165// jQuery(document).ready(function(){
166//
167//   $(window).on("resize", function(){
168//     alert("RESIZE");
169//     sticky_relocate();
170//   });
171// });

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.