-
Notifications
You must be signed in to change notification settings - Fork 0
/
books.html
85 lines (60 loc) · 1.92 KB
/
books.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
---
layout: default
---
<section class="main-content center">
<div id="booksInfo" class="booksInfo"></div>
<div id="booksfeed" class="booklist">
<img id="loader" src="{{ site.media_server }}/images/ajax-loader.gif" />
</div>
</article>
<script>
function addCommas(nStr)
{
nStr += '';
x = nStr.split('.');
x1 = x[0];
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '$1' + ',' + '$2');
}
return x1 + x2;
}
function jsonpcallback(data) {
var dataLen = data.totalItems;
var totalPageCount = 0;
var totalRetailPrice = 0.0;
$.each(data.items, function(i,item) {
title = item.volumeInfo.title;
authors = item.volumeInfo.authors;
thumbnail = item.volumeInfo.imageLinks.thumbnail;
pageCount = item.volumeInfo.pageCount;
if("saleInfo" in item && "retailPrice" in item.saleInfo && "amount" in item.saleInfo.retailPrice) {
totalRetailPrice += item.saleInfo.retailPrice.amount;
} else {totalRetailPrice += 14.99;}
if (!(isNaN(pageCount))) {
totalPageCount += pageCount;
}
else { totalPageCount += 300 } //just guessing}
div = '<div class="book" id="'+i+'"><img src="' + thumbnail + '"/><br> <span class="book_title">' + title + ' </span><br><span class="book_author">By: ' + authors + '</span></div>';
$("#booksfeed").append(div);
});
$("#booksInfo").append("<p>Books I've read through the years. Some good.. Some bad.. Some turned movies.</p>");
$("#booksInfo").append("<p><b>Total Books:</b> " +dataLen + " | <b>Total Pages Read:</b> " + addCommas(totalPageCount) + " | <b>Total Cost:</b> $" + totalRetailPrice.toFixed(2) + " </p>");
}
var url = "http://eguevara-api-services.appspot.com/books";
$.ajax({
type: "GET",
url: url,
datatype: 'callback',
dataType: "jsonp",
jsonp : "callback",
jsonpCallback: "callback",
error:function(){
console.log("falied");
},
success: function(response){
$('#loader').hide();
}
});
</script>