The Gitlab instance will be restarted on Monday April 28th at 2AM. There will be a short interruption of service.

Skip to content
Snippets Groups Projects
Commit c09d0d8d authored by Demian Katz's avatar Demian Katz
Browse files

Style fixes.

parent 807fe320
No related merge requests found
function getBookPreviews() {
var skeys = '';
$('.previewBibkeys').each(function(){
skeys += $(this).attr('class');
});
skeys = skeys.replace(/previewBibkeys/g, '').replace(/^\s+|\s+$/g, '');
var bibkeys = skeys.split(/\s+/);
var script;
// fetch Google preview if enabled
if ($('.previewGBS').length > 0) {
// checks if query string might break URI limit - if not, run as normal
if (bibkeys.length <= 150){
script = 'https://encrypted.google.com/books?jscmd=viewapi&bibkeys='
+ bibkeys.join(',') + '&callback=processGBSBookInfo';
$.getScript(script);
} else {
// if so, break request into chunks of 100
var keyString = '';
// loop through array
for (var i=0; i < bibkeys.length; i++){
keyString += bibkeys[i] + ',';
// send request when there are 100 requests ready or when there are no
// more elements to be sent
if ((i > 0 && i % 100 == 0) || i == bibkeys.length-1) {
script = 'https://encrypted.google.com/books?jscmd=viewapi&bibkeys='
+ keyString + '&callback=processGBSBookInfo';
$.getScript(script);
keyString = '';
}
}
}
}
// fetch OpenLibrary preview if enabled
if ($('.previewOL').length > 0) {
script = 'http://openlibrary.org/api/books?bibkeys='
+ bibkeys.join(',') + '&callback=processOLBookInfo';
$.getScript(script);
}
// fetch HathiTrust preview if enabled
if ($('.previewHT').length > 0) {
getHTPreviews(skeys);
}
}
// functions to get rights codes for previews
function getHathiOptions() {
HathiOptions = $('[class*="hathiPreviewDiv"]').attr("class").split('__')[1].split(',');
......@@ -65,7 +19,7 @@ function getHTPreviews(skeys) {
// since hathitrust only allows 20 at a time
// as per http://vufind.org/jira/browse/VUFIND-317
var batch = [];
for(i = 0; i < bibkeys.length; i++) {
for(var i = 0; i < bibkeys.length; i++) {
batch.push(bibkeys[i]);
if ((i > 0 && i % 20 == 0) || i == bibkeys.length-1) {
var script = 'http://catalog.hathitrust.org/api/volumes/brief/json/'
......@@ -76,6 +30,21 @@ function getHTPreviews(skeys) {
}
}
function processBookInfo(booksInfo, previewClass) {
// assign the correct rights string depending on source
var viewOptions = (previewClass == 'previewGBS')
? getGoogleOptions() : getOLOptions();
for (var bibkey in booksInfo) {
var bookInfo = booksInfo[bibkey];
if (bookInfo) {
if (viewOptions.indexOf(bookInfo.preview)>= 0) {
var $link = $('.' + previewClass + '.' + bibkey);
$link.attr('href', bookInfo.preview_url).show();
}
}
}
}
function processGBSBookInfo(booksInfo) {
processBookInfo(booksInfo, 'previewGBS');
}
......@@ -85,7 +54,7 @@ function processOLBookInfo(booksInfo) {
}
function processHTBookInfo(booksInfo) {
for (b in booksInfo) {
for (var b in booksInfo) {
var bibkey = b.replace(/:/, '').toUpperCase();
var $link = $('.previewHT.' + bibkey);
var items = booksInfo[b].items;
......@@ -98,23 +67,6 @@ function processHTBookInfo(booksInfo) {
}
}
function processBookInfo(booksInfo, previewClass) {
// assign the correct rights string depending on source
if (previewClass == 'previewGBS') {
var viewOptions = getGoogleOptions();
} else {
var viewOptions = getOLOptions();
}
for (bibkey in booksInfo) {
var bookInfo = booksInfo[bibkey];
if (bookInfo) {
if (viewOptions.indexOf(bookInfo.preview)>= 0) {
$link = $('.' + previewClass + '.' + bibkey);
$link.attr('href', bookInfo.preview_url).show();
}
}
}
}
/**
* Array.indexOf is not universally supported
* We need to set it for users who don't have it.
......@@ -128,7 +80,9 @@ function setIndexOf() {
throw new TypeError();
}
var t = Object(this);
/*jslint bitwise: true*/
var len = t.length >>> 0;
/*jslint bitwise: false*/
if (len === 0) {
return -1;
}
......@@ -154,6 +108,53 @@ function setIndexOf() {
}
}
function getBookPreviews() {
var skeys = '';
$('.previewBibkeys').each(function(){
skeys += $(this).attr('class');
});
skeys = skeys.replace(/previewBibkeys/g, '').replace(/^\s+|\s+$/g, '');
var bibkeys = skeys.split(/\s+/);
var script;
// fetch Google preview if enabled
if ($('.previewGBS').length > 0) {
// checks if query string might break URI limit - if not, run as normal
if (bibkeys.length <= 150){
script = 'https://encrypted.google.com/books?jscmd=viewapi&bibkeys='
+ bibkeys.join(',') + '&callback=processGBSBookInfo';
$.getScript(script);
} else {
// if so, break request into chunks of 100
var keyString = '';
// loop through array
for (var i=0; i < bibkeys.length; i++){
keyString += bibkeys[i] + ',';
// send request when there are 100 requests ready or when there are no
// more elements to be sent
if ((i > 0 && i % 100 == 0) || i == bibkeys.length-1) {
script = 'https://encrypted.google.com/books?jscmd=viewapi&bibkeys='
+ keyString + '&callback=processGBSBookInfo';
$.getScript(script);
keyString = '';
}
}
}
}
// fetch OpenLibrary preview if enabled
if ($('.previewOL').length > 0) {
script = 'http://openlibrary.org/api/books?bibkeys='
+ bibkeys.join(',') + '&callback=processOLBookInfo';
$.getScript(script);
}
// fetch HathiTrust preview if enabled
if ($('.previewHT').length > 0) {
getHTPreviews(skeys);
}
}
$(document).ready(function() {
if (!Array.prototype.indexOf) {
setIndexOf();
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment