Here is the list of the answers for the questions in the AM1 description.
https://www.googleapis.com/books/v1/volumes?q=search+terms
.
We then can supply different values for the search terms. (Note: The plus sign
is used to concatenate multiple words, so that no space is used in the URL). For example, if you
click on this link:
https://www.googleapis.com/books/v1/volumes?q=wellesley+college we will get the results
for Wellesley College.totalItems
will be used in our page. In addition, we will be looking at the objects in the list for
the property items
. Each item in this list is itself an object with several properties.
The properties we need are all in the volumeInfo
object, such as title, authors,
publishedDate, description, and imageLinks.smallThumbnails
.wc.js
,
then we can link to this file from a html page using the <script>
tag.
You can see this by looking the source code for this HTML page.
If you already installed the JSON Formatter plugin, the parsed view of the JS file will not show the variable
results
. If you switch the button to "Raw", you can see it at the top of the file.
results
was
declared in our Javascript file, by typing it in the console, we get back everything is stored in it.
See how this looks in the screenshot below. The statements in blue were entered by me, the rest is
the output in the console.var book = results.items[0]
, then, we use
the dot notation to access the desired properties.
console.log
is used to print results in the console. Notice that
it can take an unlimited number of arguments, this way we can concatenate many things together
to have an idea of how our code is behaving or what is in our data.
h1
or h2
, an input text field, using the tag input
and
a button using the tag button
. Here is how the completed code looks like
(this code goes within the body
pair of tags.
<h1>Searching Books</h1> <input> <button>Search books</button>
h2
), then another header to
show the author name (e.g. h3
), an img
tag to show the cover,
and a p
tag to show the book description. In order for all these elements to
stay together, we will nest them in a div
tag. Here is the markup for one book:
<div> <h2>First Book Title</h2> <h3>First Author</h3> <img src="aFileName.png" alt="book cover"> <p>Here is a book description. This can be long with several sentences, but for the moment we will just have a long list of blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah </p> </div>If we copy this for three times and use some real images, our page so far will look like this one here.
a
and img
, which display inline). To change this default
layout, we can use different
CSS techniques, the most powerful being the property float
. An
element can float either left or right (never top, bottom, center, etc.)
Read more about float in our book (Head First HTML), Chapter 11, pages 471-480.
class
attribute to the div
element that we
used to wrap the content for each book. This will looks like this:
<div class="book"> <h2>First Book Title</h2> ... </div>
.book
.
This will look like this:
.book { border: 1px solid gray; width: 300px; height: 300px; margin: 5px; /* set some space to other elements */ padding: 5px; /* set space between content and border */ float: left; }
link
tag to refer to the newly created CSS file from
within the HTML file. This instruction will be put in the head
element. It will look like this, given you named the file style.css
<head> <link href="style.css" rel="stylesheet"> </head>
overflow
to
fix this problem.
h2
elements within the "book" class, we will write:
.book h2 { color: blue; }For our app, we will need to write such rules for
h2, h3, p
, since they
are all descendant of "book". A descendant selector like this makes the style specific
to apply only to these elements and not other elements of the same kind in the page.
color
, font-size
,
font-style
, and text-align
. You can find different values
for these properties in the CSS Reference.
transform
. This performs different transformation using functions (instead of
values). There is a function rotate, translate, skew, scale, etc. To learn about
the transform property, you can read its documentation.
To see how the rule for our case was written, consult this jsFiddle example
I created.
text-align: center;
in the body
element. Our page will look like here if we do that. As
you can notice, most things have been centered, but not the div elements.
body
to a certain value
in pixels (or %), and then specify the margin for the left and right as "auto". This does the
following: finds the width of the browser window, subtracts the width we used for body
and then divides in two the difference and assigns it to the left and right margin.
We can set the margin for all four sides of an element, by writing:
body { width: 800px; margin: 10px auto; }This will set the top and bottom margin to 10 pixels and the right and left margin to auto. You can see the result of this in this last version of our page. Can we figure out what we did to change the font? It consist of one change in the HTML file and one in the CSS file.