-
Notifications
You must be signed in to change notification settings - Fork 0
/
sourceCode.html
93 lines (93 loc) · 6.15 KB
/
sourceCode.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<!-- Author: George Martin, Senior Design Spring FY23, Journals Search -->
<!-- Load Bootstrap CSS -->
<div class="container">
<!-- Welcome text and information for users. -->
<p><strong>Welcome </strong>to the George Eliot Journals page! <br />Here you can search through all 1,876 of George Eliot's journal entries encompassing multiple books and dates. We hope you find this feature helpful and easy to use. </p>
<p><strong>Displayed Information:</strong><br />Every query will return 4 columns of information. The date of the journal entry, the source which correlates to what diary the journal entry can be found, a reference page number from the book <TITLE INFORMATION HERE> for ease of cross referencing, and the journal entry itself. </p>
<p>Journal entries displayed from keyword or key-phrase queries will display a maximum of 3 sentences before and after the found query. For the full entry, search by date.</p>
<p><strong>Note</strong>: All journal entries can be displayed at once by pressing the search button with no words or dates. An empty query will return all 1,876 entries. Please allow up to 15 seconds for the results to populate. Your browser may not appear to be loading the results. </p>
<p><strong>How to use:<br /></strong>Using the search box below, enter keywords, key-phrases, or dates in YYYY or MM-DD-YYYY format to view all results matching your entry.<strong></strong></p>
<!-- Instantiate searchbox and search button. -->
<form id="searchForm" class="form-inline">
<div class="form-group"><strong></strong></div>
<div class="form-group"><label for="searchTerm"><strong>Search Term:</strong></label> <input type="text" class="form-control" id="searchTerm" name="searchTerm" placeholder="Enter search term" /> <button type="submit" class="btn btn-primary">Search</button></div>
</form>
<p id="resultCount"></p>
<!-- Parameterize display. -->
<table class="table table-striped" style="border-style: groove; border-color: black; background-color: bisque; table-layout: fixed;"><colgroup> <col width="130px" /> <col width="150px" /> <col width="100px" /> </colgroup>
<thead>
<tr>
<!-- Setup display column headers. -->
<th>Date</th>
<th>Source</th>
<th>Page #</th>
<th>Journal Entry</th>
</tr>
</thead>
<tbody id="data"></tbody>
</table>
</div>
<!-- Load jQuery and Papa.parse() -->
<p>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/PapaParse/5.3.0/papaparse.min.js"></script>
<script>
//Read in data from the searchbox.
$(document).ready(function() {
$("#searchForm").submit(function(event) {
event.preventDefault();
var searchTerm = $("#searchTerm").val();
searchTerm = searchTerm.trim();
//Note: the URLs utilize Okema's search feature and are filtered to display Journal Entries only. Removing '&outlook=csv' will allow you to see the search page in your browser.
//If a keyword, phrase, or date is entered, pull from this url with filtered (Journal Entry Items) from the Collections.
if (searchTerm.length !== 0) {
var url = "https://georgeeliotarchive.org/admin/items/browse?search=" + encodeURIComponent(searchTerm) + "&advanced%5B0%5D%5Bjoiner%5D=and&advanced%5B0%5D%5Belement_id%5D=&advanced%5B0%5D%5Btype%5D=&advanced%5B0%5D%5Bterms%5D=&range=&collection=&type=20&output=csv";
//If an emoty query is entered, remove the 'search term' element and pull all Journal Entries.
} else {
var url = "https://georgeeliotarchive.org/admin/items/browse?search=&advanced%5B0%5D%5Bjoiner%5D=and&advanced%5B0%5D%5Belement_id%5D=&advanced%5B0%5D%5Btype%5D=&advanced%5B0%5D%5Bterms%5D=&range=&collection=17&type=20&tags=&public=&featured=&submit_search=Search+for+items&output=csv";
}
$.get(url, function(data) {
var parsedData = Papa.parse(data).data;
parsedData.shift(); // Remove header row
parsedData.sort(function(a, b) {
return new Date(a[8]) - new Date(b[8]); // Sort by date column in ascending order.
});
var html = "";
var resultCount = 0;
for (var i = 0; i < parsedData.length; i++) {
if ((parsedData[i][8] && parsedData[i][8].toLowerCase().includes(searchTerm.toLowerCase())) || (parsedData[i][31] && parsedData[i][31].toLowerCase().includes(searchTerm.toLowerCase()))) {
var content = parsedData[i][31];
//For date queries, show entire Journal Entry.
if (parsedData[i][8] && (parsedData[i][8].toLowerCase().includes(searchTerm.toLowerCase()) || searchTerm.match(/^\d{4}(-\d{2}){0,2}$/))) {
content = parsedData[i][31];
//For non-dated entries, display a max of 3 sentences before and after the query term.
} else {
content = parsedData[i][31].replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/\n/g, '<br>');
var sentenceArray = content.split(/(?<!\w\.\w.)(?<![A-Z][a-z]\.)(?<=\.|\?)\s/g);
var keywordIndex = sentenceArray.findIndex(function(sentence) {
return sentence.toLowerCase().includes(searchTerm.toLowerCase());
});
var startIndex = Math.max(0, keywordIndex - 3);
var endIndex = Math.min(sentenceArray.length - 1, keywordIndex + 3);
var previewArray = sentenceArray.slice(startIndex, endIndex + 1);
var preview = previewArray.join(' ');
preview = preview.replace(new RegExp(searchTerm, "gi"), '<span class="highlight">$&</span>');
content = preview;
}
//Display the HTML entities in the Journal Entry colum from csv file index[31] as elements and not strings. This corrects the empty search (display all) formatting errors.
content = $("<div/>").html(content).text();
var pageNumber = parsedData[i][6].split("^^")[1];
var source = parsedData[i][6].split("^^")[0];
html += "<tr><td>" + parsedData[i][8] + "</td><td>" + source + "</td><td>" + pageNumber + "</td><td>" + content.replace(new RegExp(searchTerm, "gi"), '<span class="highlight">$&</span>') + "</td></tr>";
//Calculate the number of returned items on the webpage.
resultCount++;
}
}
$("#data").html(html);
$("#resultCount").
html(resultCount + " results found.");
});
});
});
</script>
</p>