-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
46 lines (39 loc) · 1.39 KB
/
main.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
// Renders an error message
function showError(msg) {
const html = `<li><p class="error">${msg}</p></li>`;
document.querySelector('#results').innerHTML = html;
}
// Searches for books and returns a promise that resolves a JSON list
function searchForBooks(term) {
// TODO
}
// Generate HTML and sets #results's contents to it
function render() {
// TODO
}
window.onscroll = function () { scrollFunction() };
function scrollFunction() {
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
document.getElementById("backToTopBtn").style.display = "block";
} else {
document.getElementById("backToTopBtn").style.display = "none";
}
}
function topFunction() {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
}
var app = angular.module('googleBookApp', []);
app.controller('googleBookCtrl', function ($scope, $http) {
$scope.searchQuery = "";
$scope.maxResult = 39; // Google Book Api value must be between 0-40
$scope.key = 'Your Key';
$scope.searchBooks = function () {
if ($scope.searchQuery && $scope.searchQuery.length > 0) {
$http.get("https://www.googleapis.com/books/v1/volumes?q=" + $scope.searchQuery + "&key=" + $scope.key + "&maxResults=" + $scope.maxResult).then(function (response) {
$scope.results = response.data.items;
console.log("$scope.results", $scope.results);
});
}
}
});