PageSourceSearch

https://www.readingwithausten.com/javascripts/functions.js

js readingwithausten.com collected 2026-10-02 12:00:00 UTC 10,798 bytes, 275 lines download raw bytes

1// Returns wall based on page title
2function getWallFromTitle(){
3    let PAGE_TITLE = document.title;
4    let WALL = null;
5    let CASE = null;
6
7    if (PAGE_TITLE.indexOf('South') != -1) WALL = "South";
8    if (PAGE_TITLE.indexOf('East') != -1) WALL = "East";
9    if (PAGE_TITLE.indexOf('West') != -1) WALL = "West";
10    
11    if (PAGE_TITLE.indexOf('Left') != -1) CASE = "Left";
12    if (PAGE_TITLE.indexOf('Centre') != -1) CASE = "Centre";
13    if (PAGE_TITLE.indexOf('Right') != -1) CASE = "Right";
14    
15    return [WALL, CASE];
16}
17
18// Compile spine element and folder class
19function processBookHelper(WALL, CASE, book, isCase){
20    let folder_class = book.folder ? "has_folder" : "no_folder"
21
22    // Adjust spine resolution to perspective of wall
23    let default_width = 4;
24    if(isCase){
25        const default_case_widths = {
26            "East":  {"Left": 22, "Centre": 25, "Right": 22},
27            "South": {"Left": 17, "Centre": 15, "Right": 17},
28            "West":  {"Left": 15, "Centre": 12, "Right": 13}
29        }
30        default_width = default_case_widths[WALL][CASE];
31    }else{
32        switch(WALL){
33            case "South": default_width = 3.5; break; 
34            case "West": default_width = 5; break; 
35            case "East": default_width = 5; break; 
36            default: break; 
37        }
38    }
39
40    // Determine spine width; adjust spine width against volumes of book
41    let spine_width = default_width * parseInt(book.volumes);   
42    if(WALL === "South" && spine_width > 40) spine_width = 40;  // South wall has particular resolution/perspective
43    if(!spine_width || spine_width == 0){
44        folder_class += " no_volumes";
45        spine_width = 4;
46    }
47
48    // Determine img.src, determine stock usage
49    let spine_src = "images\\spines\\heylyn-theological-1749_spine-crop.png";    
50    if(book.spine){
51        spine_src = `images\\spines\\${book.folder}_spine-crop.png`;
52    }else{ 
53        let vols = parseInt(book.volumes);
54        let num_volumes = vols <= 20 ? vols : 20;
55        if(num_volumes === 0){
56            console.log(num_volumes)
57            console.log(book)
58        }
59        let stock = `stock-gray-${num_volumes}vol.png`;         // Stock spine naming convention
60        spine_src = `images\\spines\\stock_spines\\${stock}`;
61        folder_class += ` book__stock book__stock-${vols}`;   
62    }
63
64    let spine_image = `<img src='${spine_src}' class='book_spine'>`;
65
66    return [spine_image, spine_width, folder_class]
67}
68
69// Populates wall with books
70function populateWall(){
71    let [WALL,CASE] = getWallFromTitle();
72
73    // If page is library type page
74    // TODO:: find better way of determining this, done by looking at document title
75    if(WALL){
76        let CURRENT_LAYOUT = LAYOUT[WALL];
77        
78        // In case view
79        if(CASE){
80            populateCase(WALL, CASE, true)
81            
82            // In wall view
83        }else{
84            // TODO:: isCase deserves better handling downstream...
85            populateCase(WALL, "Left", false);
86            populateCase(WALL, "Centre", false);
87            populateCase(WALL, "Right", false);
88        }
89    }
90}
91
92// Describes the columns in each wall secion
93const WALL_LAYOUTS = {
94    "Left": [1,2],
95    "Centre": ["s1",3,"s2"],    // slips
96    "Right": [4,5]
97}
98
99// Foramat for HTML outpus
100const FORMAT_ATTR_NAME = {
101    "id": "Catalogue ID", 
102    "author": "Author",
103    "current_loc": "Current Location",
104    "edition": "Edition",
105    "format": "Format",
106    "EEBO": "EEBO Bib Number",
107    "ESTC": "ESTC Number",
108    "Gale": "Gale Doc Number",
109    "images": "Images",
110    "in_1908": "In 1908 Catalogue",
111    "in_1935": "In 1935 Catalogue",
112    "link": "Internet Link",
113    "missing": "Missing Volumes",
114    "notes": "Notes",
115    "permissions": "Permissions",
116    "publisher": "Publisher",
117    "pub_date": "Date Published",
118    "pub_loc": "Place Published",
119    "shelf": "Location",
120    "title": "Title",
121    "transcript": "Catalogue Transcript",
122    "volumes": "Number of Volumes"
123}
124
125function populateCase(WALL, CASE, isCase){
126    let CONTAINER = document.querySelector("#column_container");
127    // Generically describes each case/page view
128    
129    // Process layout and add to DOM
130    WALL_LAYOUTS[CASE].forEach(col=>{
131        let column_id = (typeof col == "string") ? `Slip-${col.slice(-1)}` : `Column-${col}`
132        let column_output = "";
133
134        // Process shelves
135        for (const [index, shelf] of Object.entries(LAYOUT[WALL][col])) {
136            let shelf_format = COMPLETE_DATA[shelf[0]].format;     // format of first book defines shelf size/format
137            let wall_section = isCase ? 'wall-section__' : '' ;
138            let shelf_output = `<ul class='shelf format_${wall_section + shelf_format}' id='shelf-${index}'>`;
139            
140            // Process shelf books
141            shelf.forEach( book_id =>{
142                let book = COMPLETE_DATA[book_id];
143                let title = book.title ? cropString(book.title, 10) : "Title Unavailable";
144                let author = book.author ? cropString(book.author, 5) : "Author Unavailable";
145                
146                let [spine_image, spine_width, folder_class] = processBookHelper(WALL, CASE, book, isCase);
147
148                let link = `${WALL.toLowerCase()}-wall-${CASE.toLowerCase()}.html?book-id=${book_id}#bookID-${book_id}`;
149                
150                let align_case = isCase ? `style='left:${spine_width + 30}px;` : '';
151                let tool_tip = 
152                `<div class='toolTip' ${align_case}>
153                    <p class='toolTip_title'>${title}</p>
154                    <p class='toolTip_author'>${author}</p>
155                    <p class='toolTip_date'>Published: ${book.pub_date}</p>
156                    <i>Catalogue ID: ${book_id}</i>
157                </div>`;
158
159                // DEBUG - remove from outputs
160                let extraClasses = () =>{return ""};
161                // let extraClasses = () => {
162                //     let newClass = "";
163                //     book.spine ? newClass += " hasSpine" : "";
164                //     book.images ? newClass += " hasImages" : "";
165                //     book.folder && BOOK_TO_FOLDER[book.folder] ? newClass += " hasFolder" : "";
166                //     return newClass;
167                // }
168
169                if(isCase){
170                    shelf_output += 
171                    `<li 
172                        onclick='populateModal(${book_id});' 
173                        class='book ${folder_class + extraClasses()}' 
174                        id='bookID-${book_id}' 
175                        data-id='${book_id}' 
176                        style='width:${spine_width}px'>
177                        ${spine_image + tool_tip}
178                    </li>`;
179                }else{
180                    shelf_output += 
181                    `<a href='${link}' class='book ${folder_class + extraClasses()}'>
182                        <li id='bookID-${book_id}' data-id='${book_id}' style='width:${spine_width}px'>
183                            ${spine_image + tool_tip}
184                        </li>
185                    </a>`;
186                }
187            })
188
189            shelf_output += "</ul>";
190            column_output = shelf_output + column_output;
191        }
192        let capstone = (!isCase) ? `<a class='column_capstone' href='${WALL.toLowerCase()}-wall-${CASE.toLowerCase()}.html' id='column_capstone-${column_id}'></a>`: '';
193
194        // #column_container is <ul>
195        CONTAINER.innerHTML += `<li class='column' id='${column_id}'>${capstone + column_output}</li>`;
196    })
197}
198
199// TODO:: Autorun every page?
200populateWall();
201
202// Create link to section, opens book modal
203// TODO:: refactor catalogue.js to no longer require this
204function makeBookViewInLibraryAnchor(bk) {
205    var wall = bk["shelf"].toLowerCase().substring(0, bk["shelf"].toLowerCase().search(" case:")).replace(" ", "-");
206    var section = bk["shelf"].substring(bk["shelf"].search(",") - 1, bk["shelf"].search(","));
207    if (bk["shelf"].toLowerCase().search('slip') > -1) {
208        section = "centre";
209    } else if (bk["shelf"].toLowerCase().search('column') > -1) {
210        if (section == 1 || section == 2) section = 'left';
211        if (section == 3) section = 'centre';
212        if (section == 4 || section == 5) section = 'right';
213    }
214    return wall + "-wall-" + section + ".html?book-id=" + bk["id"];
215}
216
217// Reduce size of string
218function cropString(_string, length) {
219    if (!_string) return "Unavailable";
220    var new_string = _string.split(' ');
221    var max_length = length;
222    if (new_string.length > max_length) {
223        new_string = new_string.slice(0, max_length).join(" ") + "...";
224    } else {
225        new_string = new_string.slice(0, _string.length).join(" ");
226    }
227    return new_string;
228}
229
230function removeSpinner(){
231document.getElementById('spinner').style.opacity = '0';
232setTimeout(function(){ 
233    document.getElementById('spinner').style.display = 'none';  
234}, 800);
235}
236
237// Fade-in content areas
238window.addEventListener('load', function(event) {
239    document.getElementById('content_body').classList.toggle('show-body');
240    var nav_secondary = document.getElementById('nav_secondary__container');
241    var nav_tertiary = document.getElementById('nav_tertiary__container');
242    if(nav_secondary){
243        nav_secondary.classList.toggle('show-body');
244        nav_tertiary.classList.toggle('show-body');
245    }
246    var column_container = document.getElementById('column_container');
247    if (column_container) {
248        column_container.classList.toggle('show-body');
249    }
250    var URL_BOOK_ID = getParameterByName('book-id');
251    if (URL_BOOK_ID) {
252        populateModal(URL_BOOK_ID);
253        document.getElementById('bookID-' + URL_BOOK_ID).classList.toggle('url_queried_book');
254    }
255    removeSpinner();
256});
257
258// Library - Checks for url queries
259// has modal already popped up
260function getParameterByName(name, url) {
261    if (!url) url = window.location.href;
262    name = name.replace(/[\[\]]/g, '\\$&');
263    var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
264        results = regex.exec(url);
265    if (!results) return null;
266    if (!results[2]) return '';
267    return decodeURIComponent(results[2].replace(/\+/g, ' '));
268}
269
270// Turns off Animations
271function toggleAnimation() {
272    document.getElementsByTagName('body')[0].classList.toggle('transitions-off');
273    document.getElementById('nav_accessability__pause').classList.toggle('nav_acccessability__hide');
274    document.getElementById('nav_accessability__play').classList.toggle('nav_acccessability__hide');
275}

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.