PageSourceSearch

https://www.archives.gov/sites/all/themes/nara/scripts/toc.js?tm9c8g

js archives.gov collected 2026-10-02 06:13:45 UTC 4,247 bytes, 162 lines download raw bytes

1/*!
2* toc - jQuery Table of Contents Plugin
3* v0.3.2
4* http://projects.jga.me/toc/
5* copyright Greg Allen 2014
6* MIT License
7*/
8/*!
9* smooth-scroller - Javascript lib to handle smooth scrolling
10* v0.1.2
11* https://github.com/firstandthird/smooth-scroller
12* copyright First+Third 2014
13* MIT License
14*/
15//smooth-scroller.js
16(function($) {
17$.fn.smoothScroller = function(options) {
18options = $.extend({}, $.fn.smoothScroller.defaults, options);
19var el = $(this);
20$(options.scrollEl).animate({
21scrollTop: el.offset().top /*- $(options.scrollEl).offset().top - options.offset*/
22}, options.speed, options.ease, function() {
23var hash = el.attr('id');
24if(hash.length) {
25if(history.pushState) {
26history.pushState(null, null, '#' + hash);
27} else {
28document.location.hash = hash;
29}
30}
31el.trigger('smoothScrollerComplete');
32});
33return this;
34};
35$.fn.smoothScroller.defaults = {
36speed: 400,
37ease: 'swing',
38scrollEl: 'body,html',
39offset: 0
40};
41$('body').on('click', '[data-smoothscroller]', function(e) {
42e.preventDefault();
43var href = $(this).attr('href');
44if(href.indexOf('#') === 0) {
45$(href).smoothScroller();
46}
47});
48}(jQuery));
49(function($) {
50var verboseIdCache = {};
51$.fn.toc = function(options) {
52var self = this;
53var opts = $.extend({}, jQuery.fn.toc.defaults, options);
54var container = $(opts.container);
55var headings = $(opts.selectors, container);
56var headingOffsets = [];
57var activeClassName = opts.activeClass;
58var scrollTo = function(e, callback) {
59if (opts.smoothScrolling && typeof opts.smoothScrolling === 'function') {
60e.preventDefault();
61var elScrollTo = $(e.target).attr('href');
62opts.smoothScrolling(elScrollTo, opts, callback);
63}
64$('li', self).removeClass(activeClassName);
65$(e.target).parent().addClass(activeClassName);
66};
67//highlight on scroll
68var timeout;
69var highlightOnScroll = function(e) {
70if (timeout) {
71clearTimeout(timeout);
72}
73timeout = setTimeout(function() {
74var top = $(window).scrollTop(),
75highlighted, closest = Number.MAX_VALUE, index = 0;
76for (var i = 0, c = headingOffsets.length; i < c; i++) {
77var currentClosest = Math.abs(headingOffsets[i] - top);
78if (currentClosest < closest) {
79index = i;
80closest = currentClosest;
81}
82}
83$('li', self).removeClass(activeClassName);
84highlighted = $('li:eq('+ index +')', self).addClass(activeClassName);
85opts.onHighlight(highlighted);
86}, 50);
87};
88if (opts.highlightOnScroll) {
89$(window).bind('scroll', highlightOnScroll);
90highlightOnScroll();
91}
92return this.each(function() {
93//build TOC
94var el = $(this);
95var ul = $(opts.listType);
96headings.each(function(i, heading) {
97var $h = $(heading);
98headingOffsets.push($h.offset().top - opts.highlightOffset);
99var anchorName = opts.anchorName(i, heading, opts.prefix);
100//add anchor
101if(heading.id !== anchorName) {
102var anchor = $('<span/>').attr('id', anchorName).insertBefore($h);
103}
104//build TOC item
105var a = $('<a/>')
106.text(opts.headerText(i, heading, $h))
107.attr('href', '#' + anchorName)
108.bind('click', function(e) {
109$(window).unbind('scroll', highlightOnScroll);
110scrollTo(e, function() {
111$(window).bind('scroll', highlightOnScroll);
112});
113el.trigger('selected', $(this).attr('href'));
114});
115var li = $('<li/>')
116.addClass(opts.itemClass(i, heading, $h, opts.prefix))
117.append(a);
118ul.append(li);
119});
120el.html(ul);
121});
122};
123jQuery.fn.toc.defaults = {
124container: 'body',
125listType: '<ul/>',
126selectors: 'h1,h2,h3',
127smoothScrolling: function(target, options, callback) {
128$(target).smoothScroller({
129offset: options.scrollToOffset
130}).on('smoothScrollerComplete', function() {
131callback();
132});
133},
134scrollToOffset: 0,
135prefix: 'toc',
136activeClass: 'toc-active',
137onHighlight: function() {},
138highlightOnScroll: true,
139highlightOffset: 100,
140anchorName: function(i, heading, prefix) {
141if(heading.id.length) {
142return heading.id;
143}
144var candidateId = $(heading).text().replace(/[^a-z0-9]/ig, ' ').replace(/\s+/g, '-').toLowerCase();
145if (verboseIdCache[candidateId]) {
146var j = 2;
147while(verboseIdCache[candidateId + j]) {
148j++;
149}
150candidateId = candidateId + '-' + j;
151}
152verboseIdCache[candidateId] = true;
153return prefix + '-' + candidateId;
154},
155headerText: function(i, heading, $heading) {
156return $heading.clone().children("small").remove().end().text();
157},
158itemClass: function(i, heading, $heading, prefix) {
159return prefix + '-' + $heading[0].tagName.toLowerCase();
160}
161};
162})(jQuery);

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.