This repository has been archived by the owner on Mar 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.html
441 lines (421 loc) · 14.8 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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
<!--
@license
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<!DOCTYPE html>
<html>
<head>
<title>Book Search</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<script src="components/platform/platform.js"></script>
<link rel="import" href="components/polymer-jsonp/polymer-jsonp.html">
<link rel="import" href="components/polymer-selector/polymer-selector.html">
<link rel="import" href="components/polymer-grid-layout/polymer-grid-layout.html">
<link rel="import" href="components/polymer-flex-layout/polymer-flex-layout.html">
<link rel="import" href="components/polymer-localstorage/polymer-localstorage.html">
<link rel="import" href="components/polymer-ui-toolbar/polymer-ui-toolbar.html">
<link rel="import" href="components/polymer-ui-icon/polymer-ui-icon.html">
<link rel="import" href="components/polymer-ui-icon-button/polymer-ui-icon-button.html">
<link rel="import" href="components/polymer-ui-field/polymer-ui-field.html">
<link rel="import" href="components/polymer-ui-collapsible/polymer-ui-collapsible.html">
<link rel="import" href="components/polymer-ui-card/polymer-ui-card.html">
<link rel="import" href="components/polymer-ui-ratings/polymer-ui-ratings.html">
<link rel="import" href="components/polymer-ui-menu-button/polymer-ui-menu-button.html">
<link rel="import" href="components/polymer-ui-menu-item/polymer-ui-menu-item.html">
<link rel="import" href="components/polymer-ui-menu/polymer-ui-menu.html">
<link rel="import" href="components/polymer-ui-pages/polymer-ui-pages.html">
<link rel="stylesheet" href="components/polymer-ui-base/base.css">
</head>
<body class="polymer-ui-body-text">
<polymer-element name="gb-info-field" attributes="label value hideValue">
<template>
<style>
.title {
font-weight: 500;
opacity: 0.5;
padding: 20px 0 10px;;
}
</style>
<div hidden?="{{!value}}">
<div class="title">{{label}}</div>
<div hidden?="{{hideValue}}">{{value}}</div>
<content></content>
</div>
</template>
<script>
Polymer('gb-info-field', {
hideValue: false
});
</script>
</polymer-element>
<polymer-element name="gb-toggle-icon" attributes="active src activeSrc" on-tap="{{toggle}}">
<template>
<polymer-ui-icon id="icon"></polymer-ui-icon>
</template>
<script>
Polymer('gb-toggle-icon', {
active: false,
ready: function() {
this.activeChanged();
},
activeChanged: function() {
this.$.icon.src = this.resolvePath(
this.active ? this.activeSrc : this.src);
},
toggle: function(e) {
this.active = !this.active;
e.stopPropagation();
}
});
</script>
</polymer-element>
<polymer-element name="gb-book-info" attributes="book active hideFavoriteIcon">
<template>
<link rel="stylesheet" href="components/polymer-flex-layout/polymer-flex-layout.css">
<style>
:host {
}
.thumbnail {
width: 128px;
height: 195px;
}
.info {
height: 195px;
padding-left: 10px;
color: #555;
}
.title {
font-size: 16px;
font-weight: 600;
}
.authors {
padding-top: 10px;
opacity: 0.8;
}
.publisher {
opacity: 0.6;
}
gb-toggle-icon {
padding-left: 10px;
}
.more-info {
padding-top: 20px;
color: #666;
}
.link-icon-container {
position: relative;
height: 24px;
}
.link-icon-container a {
position: absolute;
top: 0;
right: 0;
}
polymer-ui-ratings {
pointer-events: none;
}
</style>
<div flexbox>
<img class="thumbnail" src="{{book.volumeInfo.imageLinks.thumbnail}}">
<div class="info" flex v-flexbox>
<div class="title" flexbox>
<div flex>{{book.volumeInfo.title}}</div>
<gb-toggle-icon src="assets/ic_favorite_darkalt.png"
activeSrc="assets/ic_favorite_darkreg.png" hidden?="{{hideFavoriteIcon}}"
on-tap="{{toggleFavorite}}"></gb-toggle-icon>
</div>
<div class="authors">{{book.volumeInfo.authors}}</div>
<div flex></div>
<div class="publisher">{{book.volumeInfo.publisher}}</div>
</div>
</div>
<polymer-ui-collapsible class="more-info" active="{{active}}">
<div class="link-icon-container">
<a target="_blank" href="{{book.volumeInfo.infoLink}}">
<polymer-ui-icon icon="shortcut" theme="polymer-ui-light-theme"></polymer-ui-icon>
</a>
</div>
<gb-info-field label="Description" value="{{book.volumeInfo.description}}"></gb-info-field>
<gb-info-field label="Categories" value="{{book.volumeInfo.categories}}"></gb-info-field>
<gb-info-field label="Published Date" value="{{book.volumeInfo.publishedDate}}"></gb-info-field>
<gb-info-field label="Page Count" value="{{book.volumeInfo.pageCount}}"></gb-info-field>
<gb-info-field label="Price" value="{{book.saleInfo.listPrice.amount}}" hideValue>
{{book.saleInfo.listPrice.amount}} {{book.saleInfo.listPrice.currencyCode}}
</gb-info-field>
<gb-info-field label="Ratings" value="{{book.volumeInfo.averageRating}}" hideValue>
<polymer-ui-ratings value="{{book.volumeInfo.averageRating}}"></polymer-ui-ratings>
( {{book.volumeInfo.ratingsCount}} reviews )
</gb-info-field>
</polymer-ui-collapsible>
</template>
<script>
Polymer('gb-book-info', {
hideFavoriteIcon: false,
toggleFavorite: function(e, detail, sender) {
this.fire('gb-book-favorite-toggle',
{book: this.book, active: sender.active});
}
});
</script>
</polymer-element>
<polymer-element name="gb-books-view" attributes="books selected hideFavoriteIcon swipeable">
<template>
<style>
:host {
display: block;
}
.book-lists {
display: block;
width: 960px;
margin: 0 auto;
}
.book-list {
display: inline-block;
width: 50%;
float: left;
vertical-align: top;
padding: 10px 0;
}
polymer-ui-card {
display: inline-block;
width: 420px;
min-height: 195px;
padding: 20px;
margin: 10px;
}
gb-book-info {
display: block;
width: 100%;
height: 100%;
}
@media screen and (max-width: 1000px) {
.book-lists {
width: 480px;
}
.book-list {
width: 100%;
padding: 0;
}
}
@media screen and (max-width: 500px) {
.book-lists {
width: auto;
}
.book-list {
display: block;
float: none;
}
polymer-ui-card {
display: block;
width: auto;
}
}
</style>
<polymer-selector target="{{$.bookLists}}" multi itemsSelector="gb-book-info"
selected="{{selected}}"></polymer-selector>
<div id="bookLists" class="book-lists">
<template repeat="{{column in columns}}">
<div class="book-list">
<template repeat="{{book in column}}">
<polymer-ui-card swipeable="{{swipeable}}" on-polymer-card-swipe-away="{{swipeAway}}">
<gb-book-info book="{{book}}" hideFavoriteIcon="{{hideFavoriteIcon}}"></gb-book-info>
</polymer-ui-card>
</template>
</div>
</template>
</div>
</template>
<script>
Polymer('gb-books-view', {
swipeable: false,
hideFavoriteIcon: false,
booksChanged: function() {
this.columns = [[], []];
this.books && this.books.forEach(function(b, i) {
this.columns[i & 1].push(b);
}, this);
},
swipeAway: function(e, detail, sender) {
this.fire('gb-book-favorite-remove',
{book: sender.templateInstance.model.book});
}
})
</script>
</polymer-element>
<polymer-element name="gb-app">
<template>
<style>
:host {
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
-webkit-tap-highlight-color: rgba(0,0,0,0);
-webkit-touch-callout: none;
}
#sidebar {
width: 200px;
-webkit-transition: left ease-in .1s;
transition: left ease-out .1s;
background: #fff;
z-index: 2;
}
.sidebar-title {
color: #999;
padding: 0 14px;
}
.sidebar-menu-selected {
color: #4285f4;
opacity: 1;
}
#scrim {
background-color: rgba(128, 128, 128, 0.5);
z-index: 1;
}
polymer-ui-toolbar#toolbar {
background: #4285f4 !important;
z-index: 1 !important;
}
polymer-ui-field {
background: white;
height: 40px;
width: 300px;
margin: 10px;
}
polymer-ui-menu-button {
padding-right: 10px;
}
polymer-ui-pages {
display: block;
height: 100%;
}
polymer-ui-pages > * {
display: block;
background: #f2f2f2;
overflow: auto;
-webkit-overflow-scrolling: touch;
}
.loading-icon {
display: none;
position: absolute;
bottom: 50%;
left: 50%;
width: 160px;
height: 160px;
margin: -80px;
background: url(assets/loading.png);
z-index: 1;
}
.loading-icon[loading] {
display: block;
}
[hidden] {
visibility: hidden;
}
</style>
<polymer-ui-toolbar id="toolbar" offscreen="basement" theme="polymer-ui-light-theme">
<polymer-ui-icon-button icon="menu" on-tap="{{toggleMenu}}" ></polymer-ui-icon-button>
<div flex></div>
<polymer-ui-field hidden?="{{viewSelected}}">
<polymer-ui-icon icon="search"></polymer-ui-icon>
<input id="input" placeholder="Search Books" value="{{query}}" flex x-webkit-speech on-change="{{search}}">
</polymer-ui-field>
<polymer-ui-menu-button selected="{{bookTypeSelected}}" halign="right" icon="filter" hidden?="{{viewSelected}}">
<polymer-ui-menu-item name="all" label="All"></polymer-ui-menu-item>
<polymer-ui-menu-item name="books" label="Books"></polymer-ui-menu-item>
<polymer-ui-menu-item name="magazines" label="Magazines"></polymer-ui-menu-item>
</polymer-ui-menu-button>
<div flex></div>
</polymer-ui-toolbar>
<div id="main" offscreen="basement">
<polymer-ui-pages selected="{{viewSelected}}">
<gb-books-view id="searchView" books="{{books}}" on-gb-book-favorite-toggle="{{toggleFavorite}}"></gb-books-view>
<gb-books-view id="favoritesView" books="{{favorites}}" hideFavoriteIcon swipeable
on-gb-book-favorite-remove="{{removeFavorite}}"></gb-books-view>
</polymer-ui-pages>
</div>
<div id="sidebar" offscreen="left" theme="polymer-ui-dark-icon">
<polymer-ui-toolbar><div class="sidebar-title">Books</div></polymer-ui-toolbar>
<polymer-ui-menu selected="{{viewSelected}}" on-polymer-activate="{{menuActivate}}" selectedClass="sidebar-menu-selected">
<polymer-ui-menu-item label="Search"></polymer-ui-menu-item>
<polymer-ui-menu-item label="Favorites"></polymer-ui-menu-item>
</polymer-ui-menu>
</div>
<div id="scrim" on-tap="{{toggleMenu}}" offscreen="right"></div>
<div class="loading-icon" loading?="{{loading}}"></div>
<polymer-grid-layout nodes="{{layoutNodes}}" layout="{{layout}}"></polymer-grid-layout>
<polymer-jsonp id="bookSearch"
url="https://www.googleapis.com/books/v1/volumes?q={{query}}&printType={{bookTypeSelected}}&maxResults=40&callback="
on-polymer-response="{{gotBooks}}"></polymer-jsonp>
<polymer-localstorage name="book-search" value="{{favorites}}"></polymer-localstorage>
</template>
<script>
Polymer('gb-app', {
viewSelected: 0,
query: '',
bookTypeSelected: 'all',
layouts: {
main:[
[1, 1],
[2, 2],
[2, 2]
],
menu: [
[3, 4],
[3, 4],
[3, 4]
]
},
ready: function() {
this.layoutNodes = [this.$.toolbar, this.$.main,
this.$.sidebar, this.$.scrim];
this.toggleMenu();
},
toggleMenu: function() {
this.layout = this.layout === this.layouts.main ?
this.layouts.menu : this.layouts.main;
},
menuActivate: function() {
this.async('toggleMenu');
},
bookTypeSelectedChanged: function() {
this.async('search');
},
search: function() {
this.loading = true;
this.$.input.blur();
this.$.bookSearch.go();
},
gotBooks: function(e, detail) {
this.loading = false;
this.$.searchView.selected = null;
this.$.searchView.scrollTop = 0;
this.books = detail.response.items;
},
toggleFavorite: function(e, detail) {
this.favorites = this.favorites || [];
if (detail.active) {
this.favorites.push(detail.book);
} else {
var i = this.favorites.indexOf(detail.book);
if (i >= 0) {
this.favorites.splice(i, 1);
}
}
},
removeFavorite: function(e, detail, sender) {
this.toggleFavorite(e, {active: false, book: detail.book});
}
});
</script>
</polymer-element>
<gb-app class="polymer-ui-fit"></gb-app>
</body>
</html>