/
index.html
202 lines (165 loc) · 7.42 KB
/
index.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
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
$def with (stats=None, blog_posts=None, lending_list=None, returncart_list=None, user=None, loans=None, popular_books=None, waitlisted_books=None)
$var title: $_("Welcome to Open Library")
<div class="page-banner page-banner-home">
Learn more about our Open Libraries Project: bringing millions of ebooks to billions of people: <a href="http://openlibraries.online">OpenLibraries.online</a>
</div>
<div id="contentBody">
$:render_template("home/categories")
<div class="clearfix"></div>
$:render_template("home/popular", books=popular_books)
<div class="clearfix"></div>
$:render_template("home/returncart")
<div class="clearfix"></div>
$:render_template("home/read")
<div class="clearfix"></div>
$:render_template("home/subject_carousel", "textbooks", title="Educational", options={}, delay=1500)
<div class="clearfix"></div>
$:render_template("home/subject_carousel", "success", title="Business Success", options={}, delay=2000)
<div class="clearfix"></div>
$:render_template("home/subject_carousel", "science_fiction", title="Science Fiction", options={}, delay=2500)
<div class="clearfix"></div>
$:render_template("home/subject_carousel", "biographies", title="Biographies", options={"published_in": "2000-2018", "sort": "edition_count"}, delay=3000)
<div class="clearfix"></div>
$:render_template("home/subject_carousel", "mystery_and_detective_stories", title="Mysteries", options={"published_in": "2000-2018", "sort": "edition_count"}, delay=3500)
<div class="clearfix"></div>
$:render_template("home/subject_carousel", "popular_print_disabled_books", title="Print Disabled (Blind Accessible)", options={"sort": "new"}, delay=3500)
<div class="clearfix"></div>
$:render_template("home/subject_carousel", "romance", title="Romance", options={"published_in": "2000-2018", "sort": "edition_count"}, delay=4000)
<div class="clearfix"></div>
$:render_template("home/subject_carousel", "Authors_Alliance", title="Author's Alliance", options={}, delay=3500, type="publishers")
<div class="clearfix"></div>
$:render_template("home/waitlist", books=waitlisted_books)
<div class="clearfix"></div>
$:render_template("home/loans", loans)
<div class="clearfix"></div>
$:render_template("home/stats", stats)
<div class="clearfix"></div>
$:render_template("home/about", blog_posts)
</div>
<script>
\$(function(){
var CHUNK_SIZE = 100; // check popular books for availability 100 at a time
var CAROUSEL_SLOTS = 36; // 6 pages of 6 books
/**
* Shuffles array in place.
* @param {Array} a items The array containing the items.
*/
function shuffle(a) {
var j, x, i;
for (i = a.length; i; i--) {
j = Math.floor(Math.random() * i);
x = a[i - 1];
a[i - 1] = a[j];
a[j] = x;
}
}
var getPopularEditionIds = function(start, limit, callback) {
var url = '/popular?start=' + start + '&limit=' + CHUNK_SIZE;
\$.ajax({
url: url,
type: "GET",
dataType: "json",
contentType: "application/json",
beforeSend: function(xhr) {
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("Accept", "application/json");
},
success: function(result) {
return callback(result);
}
});
};
var recursivelyGetPopularEditions = function(all_books, available,
waitlist, num_slots, start, limit, callback) {
if (available.length >= num_slots) {
return callback(all_books, available, waitlist);
} else {
getPopularEditionIds(start, limit, function(editions) {
if (editions.error) {
return callback(available, waitlist);
}
var batch = editions.books;
shuffle(batch);
// maintain a list of all books we know about, lookup
// table for later
for (var b in batch) {
var edition = batch[b];
var ocaid = edition[0];
var ol_key = edition[1];
all_books[ocaid] = ol_key;
}
var ocaids = batch.map(function(e) { return e[0] });
getAvailability(ocaids, function(responses) {
var books = responses;
start += limit;
for (var b in books) {
var book = books[b];
if (book.status === "available") {
available.push(b);
} else if (book.status === "unavailable" && waitlist.length < num_slots) {
waitlist.push(b);
}
if (available.length >= num_slots) {
return callback(available, waitlist);
}
}
return recursivelyGetPopularEditions(
all_books, available, waitlist, num_slots, start,
limit, callback);
});
});
}
}
function load_covers(carousel, state) {
for (var i = carousel.first; i <= carousel.last; i++) {
if (carousel.has(i)) {
carousel.get(i).find(".coverMagic").removeClass("hiddenCoverMagic");
var cover = carousel.get(i).find("img.cover");
if (cover.length > 0) {
cover.attr("src", cover.attr("xsrc"));
}
}
}
}
var updateCarousel = function(cssid, books) {
var books = books.books;
\$('#' + cssid).empty();
for (var b in books) {
\$('#' + cssid).append('<li>' + books[b] + '</li>');
}
\$('#' + cssid + ' li').each(function(index, elem) {
\$(elem).find(".coverMagic").removeClass("hiddenCoverMagic");
var cover = \$(elem).find("img.cover");
if (cover.length > 0) {
cover.attr("src", cover.attr("xsrc"));
}
});
\$("#" + cssid).jcarousel({
scroll: 6, // scroll 6 book results (1 page) at a time
itemLoadCallback: {onBeforeAnimation: load_covers}
});
\$('#' + cssid).data('jcarousel').reload();
}
var populatePopularCarousel = function() {
var all_books = {};
var available_ocaids = [];
var waitlisted_ocaids = [];
var start = 0;
recursivelyGetPopularEditions(all_books, available_ocaids,
waitlisted_ocaids, CAROUSEL_SLOTS, start, CHUNK_SIZE,
function(available, waitlist) {
var available_olkeys = available.map(function(e) { return all_books[e] });
var waitlist_olkeys = waitlist.map(function(e) { return all_books[e] });
getEditions(available_olkeys, function(books) {
updateCarousel('popular_carousel', books);
getEditions(waitlist_olkeys, function(books) {
updateCarousel('waitlist_carousel', books);
// finalize, rerun availability to get correct icons
updateBookAvailability();
}, 'carousel_item', 'CarouselWaitlist');
}, 'carousel_item', 'CarouselPopular');
});
}
populatePopularCarousel();
});
</script>