PageSourceSearch

https://theanarchistlibrary.org/static/js/amuse.js?v=6

js theanarchistlibrary.org collected 2026-09-24 08:35:03 UTC 4,271 bytes, 117 lines download raw bytes

1function use_named_toc () {
2    if (!$('#js-site-settings').data('use-named-toc')) {
3        return;
4    }
5    var toc_entries = Object.create(null);
6
7    var regexp = "[^"
8        + "\\u0030-\\u0039" // 0-9
9        + "\\u0041-\\u005A" // A-Z
10        + "\\u0061-\\u007A" // a-z
11        + "\\u00C0-\\u00D6" // À Ö
12        + "\\u00D8-\\u00F6" // Ø ö
13        + "\\u00F8-\\u02B8" // until ʸ
14        + "\\u0391-\\u03A1" // greek uppercase
15        + "\\u03A3-\\u03F5" // greek lower
16        + "\\u03F7-\\u0481" // cryrillic  lower
17        + "\\u048A-\\u052F" // cyrillic
18        + "]";
19    // console.log(regexp);
20    var all_but_chars = new RegExp(regexp, 'g');
21    $('.tableofcontentline').each(function() {
22        var el = $(this);
23        var text = el.text();
24        var anchor = el.find('a');
25        var old_id;
26        var new_id = text.replace(all_but_chars, '-')
27            .replace(/^-+/, '')
28            .replace(/-+$/, '')
29            .replace(/--+/, '-');
30        var base_id = new_id;
31        var count = 1;
32        while (toc_entries[new_id]) {
33            new_id = base_id + '-' + count;
34            count++;
35        }
36        if (toc_entries[new_id]) {
37            console.log(new_id + ' is already taken');
38        }
39        else {
40            toc_entries[new_id] = 1;
41        }
42        if (anchor) {
43            old_id = anchor.attr('href');
44            if (old_id && !old_id.match(/^#text-amuse-label/)) {
45                /* console.log(new_id + ' => ' + old_id); */
46                $(old_id).prepend($('<span>', { id: 'amw-toc-' + new_id }));
47                anchor.attr('href', '#amw-toc-' + new_id);
48            }
49        }
50    });
51    console.log(toc_entries);
52}
53
54$(document).ready(function(){
55    $("p").each(function(i) {
56        if(!$(this).attr('class')) {
57            $(this).addClass("text-justify");
58        }
59    });
60    $("div#thework table").addClass("table table-bordered");
61    /* preview as well */
62    $("div#htmltextbody table").addClass("table table-bordered");
63    $(".center p").removeClass("text-justify").addClass("text-center");
64    $(".right p").removeClass("text-justify").addClass("text-right");
65    var has_toc = $("div.table-of-contents").length;
66    var has_cover = $("#text-cover-img").length;
67    if (has_toc > 0) {
68        $('.tableofcontentline').each(function() {
69            var el = $(this);
70            var anchor = el.find('a');
71            /* console.log(el.text() + anchor.length); */
72            if (anchor.length) {
73                $('#amw-top-nav-toc').append($('<li>').append($('<a>', { "href": anchor.attr('href') })
74                                                              .text(el.text())));
75            }
76        })
77
78        $(".hidden-when-no-toc").show();
79        var originaltoc = $("div.table-of-contents").remove();
80        originaltoc.addClass("well well-lg");
81        var toc = $('<div>', { "class": "row" });
82        if (has_cover) {
83            toc.append($('<div>', { "class": "col-sm-6" }).append(originaltoc));
84            var img = $('#text-cover-img').attr('src');
85            $('#text-cover-img-container').remove();
86            toc.append($('<div>', { "class": "col-sm-6" })
87                       .append($('<img>', { "src": img,
88                                            "id": 'text-cover-img-relocated',
89                                            "class": "img img-responsive mb-1",
90                                            "alt": img })));
91        }
92        else {
93            toc.append($('<div>', { "class": "col-sm-12" }).append(originaltoc));
94        }
95        toc.insertAfter('#amw-blog-container-prepended');
96    }
97
98    // with this div we signal that the teaser contains the whole text
99    $("div.amw-teaser-no-ellipsis").closest('.amw-listing-item').find(".amw-read-more-link").remove();
100
101    // alt images if available
102    $("#htmltextbody img").each(function() {
103        var el = $(this);
104        var img_name = el.attr('alt');
105        if (img_name) {
106            $.get('/api/attachment/' + img_name, function(data) {
107                // console.log(data);
108                var alt_text = data.alt_text || data.title_muse;
109                if (alt_text) {
110                    el.attr('alt', alt_text);
111                }
112            });
113        }
114    });
115
116});
117

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.