This repository has been archived by the owner on Oct 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
360link-reset.js
490 lines (401 loc) · 20.9 KB
/
360link-reset.js
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
/*
* 360Link Reset > 360link-reset.js
* Script for radically improving the Serials Solutions 360Link Link Resolver
*
* For more information, see http://github.com/gvsulib/360Link-Reset
*
* Author: Matthew Reidsma, [email protected], @mreidsma
* Version 3.1
*/
// Simplify the noConflict call since 360Link loads Prototype
window.$j = jQuery.noConflict();
$j(document).ready(function() { // Wait until the original page loads
// First, let's standardize the format types
if(format.indexOf('Format') > 0) {
formatType = format.split('Format');
itemType = formatType[0];
} else {
itemType = format;
}
console.log('This is a ' + itemType);
// ************************************************************************************
// Define your institution's local variables here
// ************************************************************************************
// Put the base URL for your catalog here, set for a title search. (Syntax set for Sierra -
// Include the ? )
var opacUrl = 'https://library.catalog.gvsu.edu/search/t?';
// What do you call the catalog?
var opacName = 'Library Catalog';
// If you have a consortial catalog in addition to your local OPAC, enter the base URL
// here set for a title search (syntax is set for Sierra - include ?)
var consortialUrl = 'http://elibrary.mel.org/search/t?'
// If you have a consortial catalog, enter the name you want to refer to it as here
var consortialName = 'other Michigan libraries';
// Put the base URL Illiad installation here. An OpenURL will be added for all ILL calls.
// Include the ?
var illBaseUrl = 'https://gvsu.illiad.oclc.org/illiad/illiad.dll/OpenURL?';
// What do you call your ILL/Document Delivery department?
var illName = 'Document Delivery';
// The troubleshooting email you'd like broken link reports to go to
var ermsEmail = '[email protected]';
// The short name of your library or school you want to use in dialogs
var libraryName = 'GVSU';
// Change this to read whatever 360Link says when your print holdings show up
var printLabel = 'Print Journal at GVSU Libraries';
// Do you want to show a tooltip pointing folks to Document Delivery or ILL if they click
// on more than 1 full text link? (Usually means broken links)
// true = yes, false = no
var docDelTooltip = true;
// Temporary patch to make Illiad requests work - this is custom to the GVSU install
var illiadLink = $j("table.CandyWrapper:last a.AnchorButton:contains('Document Delivery')").attr("href");
if((itemType == 'Book') || (itemType == 'Dissertation')) {
var titleEncode = encodeURIComponent($j('.CitationSource').text());
} else {
var titleEncode = encodeURIComponent($j('.CitationArticleOrSectionTitle').text());
}
console.log('The title is: ' + titleEncode);
// ************************************************************************************
// DON'T EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING!
// ************************************************************************************
// Define common variables
var problemUrl=encodeURIComponent(document.URL),authorFirst=$j(".given-name").text().trim(),authorLast=$j(".family-name").text().trim(),results="",articleLinkdata=new Array(),journalLinkdata=new Array(),BookLinkdata=new Array(),dateRangedata=new Array(),DatabaseNamedata=new Array(),DatabaseLinkdata=new Array(),clicks=0,refinerlink=$j("#RefinerLink0").find("a").attr("href"),hasPrint=false,newHref,i=0,illLabel='Order a copy from ' +illName,searchLabel='Search the ' + opacName + ' for this ',query = document.location.search,authorName = authorLast + ', ' + authorFirst,formatType,itemType;;
// Let's first record what type of item this is. Useful for knowing how many books folks are seeing here.
// First, let's standardize the format types
if(format.indexOf('Format') > 0) {
formatType = format.split('Format');
itemType = formatType[0];
} else {
itemType = format;
}
console.log('This is a ' + itemType);
// ACTIVATE MAGIC FAIRY DUST
// Remove existing styles
$j("head").find("link").remove();
// Function to grab items from the URL
function getQueryVariable(v) {
var sidquery = window.location.search.substring(1);
var vars = query.split('&');
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split('=');
if (decodeURIComponent(pair[0]) == v) {
return decodeURIComponent(pair[1]);
}
}
console.log('Query variable %s not found', v);
}
// Set variables from citation
if (format === "Journal" || format === "JournalFormat") { // Journals
var L="an electronic copy",A="1 – 3 days",O="article",resultsTable=$j("#JournalLinkTable"),illLabel='Order a copy from ' + illName;
}
if (format === "BookFormat" || format === "Book") { // Books
var L="this book",A="1 – 2 weeks",O="book",resultsTable=$j("#BookLinkTable"),vol='',issue='',pages='',article='';
}
if (format === "Dissertation" || format === "DissertationFormat") { // Dissertations
var L="this dissertation",A="1 – 2 weeks",O="dissertation",resultsTable=$j("#BookLinkTable"),vol='',issue='',pages='',article=''; // Encode the white space in the URL
}
if (format === "Patent" || format === "PatentFormat") { // Patents
var L="this patent",A="1 – 2 weeks",O = "patent",resultsTable=$j("#BookLinkTable");
}
if (format === "UnknownFormat" || format === "Unknown") { // Unknown Format
var L="this item",A="1 – 2 weeks",O="item",resultsTable=$j("#BookLinkTable");
}
var newPage = document.createElement('div');
newPage.id = 'link-reset-wrapper';
var newPageHeader = document.createElement('h2');
newPageHeader.style.textAlign = 'left';
newPageHeader.innerHTML = 'You are looking for:';
newPage.appendChild(newPageHeader);
// Where is the built-in APA citation format?
var citationDiv = document.body.querySelector('div.Citation');
// Build list element for searching catalog or Google Patents
var listOpac = document.createElement('li'),itemType=O;
listOpac.id = 'next-step-opac';
if(format === "Journal" || format === "JournalFormat") {
itemType = 'journal';
}
if(format === "Patent" || format === "PatentFormat") {
opacUrl = 'http://www.google.com/?tbm=pts#tbm=pts&q=';
searchLabel = 'Search Google Patents for this ';
}
listOpac.innerHTML = '<a href="'+opacUrl+titleEncode+'">'+searchLabel+itemType+'</a>';
if(format !== 'Journal' && format !== 'JournalFormat') {
// Build consortial link for this item
var listConsortium = document.createElement('li');
listConsortium.innerHTML = '<a href="'+consortialUrl+titleEncode+'">Search '+consortialName+' for this '+O+'</a>';
}
var listIll = document.createElement('li');
listIll.innerHTML = 'Not available online? <a href="'+illiadLink+'">'+illLabel+'</a>';
// Build the troubleshooting link
var listProblem = document.createElement('li');
listProblem.innerHTML = 'Found a problem? <a href="mailto:'+ermsEmail+'?subject=Bad%20Full%20Text%20Link&body=%0A%0AProblem%20URL:%20'+problemUrl+'">Let our crack team of link fixers know</a>!';
// Build the next steps list
var nextStepsList = document.createElement('div');
var nextStepsUl = document.createElement('ul');
nextStepsList.id = 'next-step';
nextStepsUl.appendChild(listOpac);
if(typeof listConsortium !== 'undefined') {
nextStepsUl.appendChild(listConsortium);
}
// Get data on all items in results list
$j(resultsTable).find("tr").each(function(index) { // Grab values from the results table
if(index !== 0) {
if(format === "Journal" || format === "JournalFormat") {
// Get the article link, if available
articleLinkdata[i] = $j(this).find("#ArticleCL").find("a").attr("href");
journalLinkdata[i] = $j(this).find("#JournalCL").find("a").attr("href");
} else { // Not a journal article
// Get the book link, if applicable
BookLinkdata[i] = $j(this).find("#BookCL").find("a").attr("href");
}
// Get the date range
dateRangedata[i] = $j(this).find("#DateCL").text();
// Get the database name
DatabaseNamedata[i] = $j(this).find("#DatabaseCL").text();
// Get the database link
DatabaseLinkdata[i] = $j(this).find("#DatabaseCL").find("a").attr("href");
i++;
}
results = index; // Get total number of results
});
if(results > 0) { // There are results
if(DatabaseNamedata[0] === printLabel) {
hasPrint = true;
}
// Develop link for top result
if((typeof articleLinkdata[0] === 'undefined') && (typeof BookLinkdata[0] === 'undefined')) { // Journal level link only
buttonText = 'Browse the Journal';
buttonLink = journalLinkdata[0];
} else {
buttonText = 'Full Text';
if(typeof articleLinkdata[0] === 'undefined') { // Book
buttonLink = BookLinkdata[0];
} else {
buttonLink = articleLinkdata[0];
buttonText += ' Online';
}
}
// Create the results DOM object
var resultsDiv = document.createElement('div');
resultsDiv.id = 'search-results';
var topResult = document.createElement('li'),topResultdiv = document.createElement('ul'),topResultMore = document.createElement('div'),topResultTrigger=document.createElement('span');
topResultdiv.id = 'top-result';
topResult.innerHTML = '<a href="' + buttonLink + '" class="btn btn-primary btn-lg lib-button" target="_blank">' + buttonText + '</a> in <a href="' + DatabaseLinkdata[0] + '" class="SS_DatabaseHyperLink">' + DatabaseNamedata[0].trim() + '</a>';
if(format === "Journal" || format === "JournalFormat") {
topResultTrigger.className = 'holding-details';
topResultTrigger.innerHTML = 'Details';
topResult.appendChild(topResultTrigger);
topResultMore.className = 'tooltip';
topResultMore.innerHTML = '<i>Dates covered: </i>' + dateRangedata[0] + ' <a href="' + journalLinkdata[0] + '" class="journal-button">Browse Journal</a>';
topResult.appendChild(topResultMore);
}
topResultdiv.appendChild(topResult);
resultsDiv.appendChild(topResultdiv);
if(i > 1) { // There are additional links
var extraResults = i-1;
if(extraResults === 1) { // Only 1 additional result
var showResultsLabel = "Show 1 More Result";
} else { // More than one result
var showResultsLabel = "Show " + extraResults + " More Results";
}
var additionalResultsTrigger = document.createElement('div');
additionalResultsTrigger.className = 'event-head';
additionalResultsTrigger.innerHTML = showResultsLabel;
// Create variables for additional results
var additionalResultsdiv = document.createElement('div'), onlineResultsdiv = document.createElement('ul'), printResultsdiv = document.createElement('ul'), newResult, newResultLink, newResultLabel, newResultHoldings, printHeading, onlineHeading;
for(var x = 1; x < results; x++) {
console.log(DatabaseNamedata[x].trim());
if(DatabaseNamedata[x].trim() === printLabel) { // Item is in print
printHeading = document.createElement('h4');
printHeading.innerHTML = 'Print';
hasPrint = true; // Toggle this setting to true
newResult = document.createElement('li');
newResult.innerHTML = '<a href="'+journalLinkdata[x]+'" target="blank">Available in Print</a> at ' + libraryName;
printResultsdiv.appendChild(newResult);
} else { // Item is online
onlineHeading = document.createElement('h4');
onlineHeading.innerHTML = 'Online';
newResult = document.createElement('li');
if(typeof articleLinkdata[x] === 'undefined') {
newResultLink = journalLinkdata[x];
newResultLabel = 'Browse the Journal';
} else {
newResultLink = articleLinkdata[x];
newResultLabel = 'Full Text Online';
}
newResult.innerHTML = '<a href="' + newResultLink + '" target="_blank">' + newResultLabel + '</a> in <a href="' + DatabaseLinkdata[x] + '" class="SS_DatabaseHyperLink">' + DatabaseNamedata[x] + '</a> <span class="holding-details">Details</span>';
newResultHoldings = document.createElement('div');
newResultHoldings.className = 'tooltip';
newResultHoldings.innerHTML = '<i>Dates covered: </i>' + dateRangedata[x] + ' <a href="' + journalLinkdata[x] + '" class="journal-button">Browse Journal</a>';
newResult.appendChild(newResultHoldings);
onlineResultsdiv.appendChild(newResult);
} // End item online loop
} // End for loop
var additionalResultsDiv = document.createElement('div');
additionalResultsDiv.className = 'event-body';
if(typeof onlineHeading !== 'undefined') {
additionalResultsDiv.appendChild(onlineHeading);
additionalResultsDiv.appendChild(onlineResultsdiv);
}
if(typeof printHeading !== 'undefined') {
additionalResultsDiv.appendChild(printHeading);
additionalResultsDiv.appendChild(printResultsdiv);
}
resultsDiv.appendChild(additionalResultsTrigger);
resultsDiv.appendChild(additionalResultsDiv);
} // End additional results loop
} else { // No results
// Create the results DOM object
var resultsDiv = document.createElement('div'),noResultsLabel = 'We’re sorry, but this item is not available online. <small style="font-size: .7em !important; font-weight: normal !important;"><i><a href="mailto:' + ermsEmail + '?subject=Bad%20Full%20Text%20Link&body=%0A%0AProblem%20URL:%20'+problemUrl+'">Think this is wrong?</a></i></small>',noResultsButton = '',noResultsButtonLabel = '',noResultsIll = document.createElement('div'),noResultsprc = document.createElement('div');
resultsDiv.id = 'ContentNotAvailableTable';
if(format !== "Journal" && format !== "JournalFormat") { // Requested item is not an article
noResultsLabel = 'This item may be available online <a href="' + opacUrl + titleEncode + '">through our ' + opacName + '</a>';
noResultsButtonLabel = '<a href="' + opacUrl + titleEncode + '" class="btn btn-primary btn-lg lib-button">Search the ' + opacName + '</a>';
noResultsButton = document.createElement('p');
noResultsButton.innerHTML = noResultsButtonLabel;
}
// Build no results message
noResultsMessage = document.createElement('p');
noResultsMessage.className = 'lib-big-text';
noResultsMessage.innerHTML = noResultsLabel;
resultsDiv.appendChild(noResultsMessage);
if(format !== "Journal" && format !== "JournalFormat") {
resultsDiv.appendChild(noResultsButton);
}
// Make a container to hold the help options
var noResultsHelp = document.createElement('div');
noResultsHelp.className = 'line';
// Build help options - first ILL/Document Delivery
noResultsIll.className = "span2 unit left";
var noResultsIllHeader = document.createElement('h4');
noResultsIllHeader.innerHTML = 'Need This Item?';
noResultsIll.appendChild(noResultsIllHeader);
var noResultsIllText = document.createElement('p');
noResultsIllText.style.fontSize = '1em';
noResultsIllText.innerHTML = 'We’ll get you '+L+" in "+A+'.'; // Uses terms from citation grabber
noResultsIll.appendChild(noResultsIllText);
var noResultsIllButton = document.createElement('p');
noResultsIllButton.innerHTML = '<a href="'+illiadLink+'" class="btn btn-default btn-lg lib-button-grey">Order a Copy</a>';
noResultsIll.appendChild(noResultsIllButton);
// Build help options - second Research Consultants
noResultsprc.className = "span2 unit left lastUnit";
var noResultsprcHeader = document.createElement('h4');
noResultsprcHeader.innerHTML = 'Need Research Help?';
noResultsprc.appendChild(noResultsprcHeader);
var noResultsprcText = document.createElement('p');
noResultsprcText.style.fontSize = '1em';
noResultsprcText.innerHTML = 'Meet with a research consultant to find similar ' + O + 's.'; // Uses term from citation grabber
noResultsprc.appendChild(noResultsprcText);
var noResultsprcButton = document.createElement('p');
noResultsprcButton.innerHTML = '<a href="http://gvsu.edu/library/prc" class="btn btn-default btn-lg lib-button-grey">Make an Appointment</a>';
noResultsprc.appendChild(noResultsprcButton);
noResultsHelp.appendChild(noResultsIll);
noResultsHelp.appendChild(noResultsprc);
resultsDiv.appendChild(noResultsHelp);
} // End no results
// Serials Solutions does a strange thing when 2 citations conflict. They ask the user to choose between them.
// This clunky fix tries to make it easier for the user to understand why they are being asked to choose
// between two seemingly identical things.
var idiotDiv = $j(".SS_HoldingText a").attr("href"); // This silly solution has appeared
if(typeof(idiotDiv) !== 'undefined') { // There is a choice between two different citations
// Set the variables needed
var whichCitationLink = new Array(),whichCitationJournal = new Array(), whichCitationIssn = new Array(),idiotResults,t=0,newResultItem;
// Cycle through the data on the page and populate the arrays
$j(".SS_HoldingText").each(function(n) {
whichCitationLink[t] = $j(this).find("a").attr("href");
whichCitationJournal[t] = $j(this).find(".SS_JournalTitle").text();
whichCitationIssn[t] = $j(this).find(".SS_IssnText").text();
t++;
});
idiotResults = t + 1;
var resultsDiv = document.createElement('div');
resultDiv.id = 'citation-choice';
var choiceHeading = document.createElement('h4');
choiceHeading.innerHTML = 'This item is available in the following publications:';
var choiceList = document.createElement('ul');
choiceList.id = 'top-result';
for(var j=0; j < idiotResults; j++) {
newResultItem = document.createElement('li');
newResultItem.innerHTML = '<a href="' + whichCitationLink[j] + '">' + whichCitationJournal[j] + ' ' + whichCitationIssn[j] + '</a>';
choiceList.appendChild(newResultItem);
}
resultsDiv.appendChild(choiceHeading);
resultsDiv.appendChild(choiceList);
} // End of Silly Choice Function
// Do the magic if this is a link resolver display page:
// Rewrite Serials Solutions terrible page with a nice semantic, clean div full of easy-to-follow markup
// So we need to add a div wrapper around the Serials Solutions content to add this HTML into
var pairvalues = query.split("&");
if(pairvalues[0] !== "?SS_Page=refiner") { // This is the citation form. Don't rewrite the page.
// Build the next steps list
nextStepsUl.appendChild(listIll);
nextStepsUl.appendChild(listProblem);
if(docDelTooltip === true) { // Show Doc Delivery Tooltip
// Let's show a tooltip highlighting Document Delivery when the user has tried a few sources.
var tooltip = document.createElement('li');
tooltip.id = 'doc-del-tooltip';
tooltip.innerHTML = 'Having trouble? You can order a copy from ' + illName +', and they’ll get it for you. It’s free!<br /><a href="'+illiadLink+'" class="btn btn-default btn-lg lib-button-grey">Order a Copy</a> <span id="cancel-doc-del">No Thanks</span><p style="clear:both;"><i><a href="mailto:'+ermsEmail+'?subject=Bad%20Full%20Text%20Link&body=%0A%0AProblem%20URL:%20'+problemUrl+'" class="doc-del-problem">Found an error? Let us know!</a></i>';
nextStepsUl.appendChild(tooltip);
}
nextStepsList.appendChild(nextStepsUl);
newPage.appendChild(citationDiv);
newPage.appendChild(resultsDiv);
newPage.appendChild(nextStepsList);
// Add a clear div to reset all floats at the bottom before the footer starts
newPageClear = document.createElement('div');
newPageClear.style.clear = 'both';
newPage.appendChild(newPageClear);
// Find the
var container = document.getElementById('CitationResults');
container.parentNode.replaceChild(newPage, container);
//check and see if there are print holdings for journal. If so, hide the search the catalog link
if (hasPrint === true && (format === "Journal" || format === "JournalFormat")) {
document.getElementById('next-step-opac').style.display = 'none';
}
if($j('.holding-details').length > 0) {
// There are results, so holding information should be hidden until asked for
$j('.tooltip').hide();
// Show or hide tooltip if holding details is clicked on
$j('span.holding-details').click(function() {
$j(this).next('.tooltip').toggle();
var currentLabel = $j(this).text();
if(currentLabel === "Details") {
$j(this).text('Hide Details');
} else {
$j(this).text('Details');
}
});
}
// Hide additional results until toggled
$j(".event-body").hide();
$j(".event-head").click(function() {
jQuery(".event-body").slideToggle(400);
var current_text = jQuery(".event-head").text();
if(current_text === "Hide Additional Results") {
jQuery(".event-head").text('Show More Results');
} else {
jQuery(".event-head").text('Hide Additional Results');
}
});
if(docDelTooltip === true) {
// Hide the tooltip for now
var docDelObject = document.getElementById('doc-del-tooltip');
docDelObject.style.display = 'none';
// User has hidden the document delivery tooltip
$j("#cancel-doc-del").click(function() {
docDelObject.style.display = 'none';
clicks = 0;
});
console.log(clicks);
// Let's count clicks to see when to show the document delivery tooltip
$j("#search-results").find("li").find("a").click(function() {
clicks++;
$j(".event-body").show();
$j(".event-head").text('Hide Additional Results');
console.log(clicks);
if(clicks > 1) {
docDelObject.style.display = 'block';
}
});
} // End doc del tooltip behavior code
} // End page rewrite
});