-
Notifications
You must be signed in to change notification settings - Fork 1
/
auto-paginated-image-gallery.html
429 lines (388 loc) · 10.8 KB
/
auto-paginated-image-gallery.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
<!--
Copyright 2017 Next Century Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../paginated-image-gallery/paginated-image-gallery.html">
<!--
A Polymer Element showing a paginated-image-gallery element that automatically handles pagination.
### Example
```html
<auto-paginated-image-gallery
images="[[images]]">
</auto-paginated-image-gallery>
```
### Styling
`<auto-paginated-image-gallery>` provides the following custom properties and mixins for styling:
Custom property | Description | Default
--------------------------------------------------|----------------------------------------------|--------
`--auto-paginated-image-gallery-hovering-color` | The background color of the hovering images. | none
`--auto-paginated-image-gallery-loading-spinner` | Mixin applied to the loading-spinner. | none
`--auto-paginated-image-gallery-max-height` | Maximum height of the gallery. | 160px
`--auto-paginated-image-gallery-scroll-threshold` | Mixin applied to the iron-scroll-threshold. | none
`--auto-paginated-image-gallery-selected-color` | The background color of the selected images. | none
`--auto-paginated-image-gallery-show-more-button` | Mixin applied to the show more button. | none
@demo demo/index.html
-->
<dom-module id="auto-paginated-image-gallery">
<template>
<style>
:host {
display: block;
}
paginated-image-gallery {
--paginated-image-gallery-hovering-color: var(--auto-paginated-image-gallery-hovering-color);
--paginated-image-gallery-loading-spinner: var(--auto-paginated-image-gallery-loading-spinner);
--paginated-image-gallery-scroll-threshold: var(--auto-paginated-image-gallery-scroll-threshold);
--paginated-image-gallery-selected-color: var(--auto-paginated-image-gallery-selected-color);
--paginated-image-gallery-show-more-button: var(--auto-paginated-image-gallery-show-more-button);
/* By default, the height of 1 row of images. */
--paginated-image-gallery-max-height: var(--auto-paginated-image-gallery-max-height, 160px);
}
</style>
<paginated-image-gallery
image-items="[[_pageImages]]"
total-items="[[images.length]]"
image-id-property="[[imageIdProperty]]"
image-link-property="[[imageLinkProperty]]"
image-name-property="[[imageNameProperty]]"
image-source-property="[[imageSourceProperty]]"
large-image-style-class="[[largeImageStyleClass]]"
new-tab="[[newTab]]"
page-size="[[pageSize]]"
select-icon="[[selectIcon]]"
select-word="[[selectWord]]"
selected-property="[[selectedProperty]]"
show-labels="[[showLabels]]"
show-select="[[showSelect]]"
show-select-preceding="[[showSelectPreceding]]"
small-image-style-class="[[smallImageStyleClass]]"
unselect="[[unselect]]"
unselect-icon="[[unselectIcon]]"
unselect-word="[[unselectWord]]"
page="{{_page}}"
hovering="{{hovering}}"
selected="{{selected}}"
shown-items="{{loadedImages}}">
</paginated-image-gallery>
</template>
<script>
(function() {
'use strict';
Polymer({
is: 'auto-paginated-image-gallery',
properties: {
/**
* (Output)
*
* The list of image IDs targeted by a hover event.
*
* @type {Array}
*/
hovering: {
notify: true,
type: Array
},
/**
* (Required)
*
* The list of all images available across all pages in the gallery.
*
* @type {Array}
*/
images: {
type: Array
},
/**
* (Optional)
*
* The property of the image objects for their unique IDs.
*
* @type {String}
* @default 'id'
*/
imageIdProperty: {
type: String,
value: 'id'
},
/**
* (Optional)
*
* The property of the image objects for their link URL to open information within the application.
*
* @type {String}
* @default 'link'
*/
imageLinkProperty: {
type: String,
value: 'link'
},
/**
* (Optional)
*
* The property of the image objects for their name.
*
* @type {String}
* @default 'name'
*/
imageNameProperty: {
type: String,
value: 'name'
},
/**
* (Optional)
*
* The property of the image objects for their source URL.
*
* @type {String}
* @default 'source'
*/
imageSourceProperty: {
type: String,
value: 'source'
},
/**
* (Optional)
*
* The style class for any image in a popup.
*
* @type {String}
* @default ''
*/
largeImageStyleClass: {
type: String,
value: ''
},
/**
* (Output)
*
* The list of all the images loaded in the image gallery (shown on the current and prior pages).
*
* @type {Array}
*/
loadedImages: {
notify: true,
type: Array
},
/**
* (Optional)
*
* Whether to open a link in a new tab.
*
* @type {Boolean}
* @default false
*/
newTab: {
type: Boolean,
value: false
},
/**
* (Optional)
*
* The page size.
*
* @type {Number}
* @default 25
*/
pageSize: {
type: Number,
value: 25
},
/**
* (Optional|Output)
*
* The list of selected image IDs. Either a list or an object containing a list at its `selectedProperty` property.
*
* @type {Array|Object}
* @default []
*/
selected: {
notify: true,
type: Array,
value: function() {
return [];
}
},
/**
* (Optional)
*
* The property in the `selected` object containing the list of selected string IDs. If undefined, assumes that `selected` itself is a list.
*
* @type {String}
*/
selectedProperty: {
type: String
},
/**
* (Optional)
*
* The icon for the "select" button if the image is unselected.
*
* @type {String}
* @default 'done'
*/
selectIcon: {
type: String,
value: 'done'
},
/**
* (Optional)
*
* The word for the "select" button text if the image is unselected.
*
* @type {String}
* @default 'Select'
*/
selectWord: {
type: String,
value: 'Select'
},
/**
* (Optional)
*
* Whether to show the labels for the images.
*
* @type {Boolean}
* @default false
*/
showLabels: {
type: Boolean,
value: false
},
/**
* (Optional)
*
* Whether to show the "select" buttons.
*
* @type {Boolean}
* @default false
*/
showSelect: {
type: Boolean,
value: false
},
/**
* (Optional)
*
* Whether to show the "select preceding" buttons.
*
* @type {Boolean}
* @default false
*/
showSelectPreceding: {
type: Boolean,
value: false
},
/**
* (Optional)
*
* The style class for all the images in the gallery.
*
* @type {String}
* @default ''
*/
smallImageStyleClass: {
type: String,
value: ''
},
/**
* (Optional)
*
* Whether clicking the "select" button for a selected image will unselect it.
*
* @type {Boolean}
* @default false
*/
unselect: {
type: Boolean,
value: false
},
/**
* (Optional)
*
* The icon for the "select" button if the image is selected.
*
* @type {String}
* @default 'done'
*/
unselectIcon: {
type: String,
value: 'done'
},
/**
* (Optional)
*
* The word for the "select" button text if the image is selected.
*
* @type {String}
* @default 'Unselect'
*/
unselectWord: {
type: String,
value: 'Unselect'
},
/**
* The current page.
*
* @type {Number}
* @default 1
* @private
*/
_page: {
type: Number,
value: 1
},
/**
* The images to show on the current page in the image gallery.
*
* @type {Array}
* @default []
* @private
*/
_pageImages: {
type: Array,
value: function() {
return [];
}
}
},
observers: [
'_updatePageImages(_page, pageSize)',
'_updatePage(images)'
],
/**
* Updates the images to show on the current page based on the page and page size.
*
* @param {Number} pageSize
* @param {Number} page
* @private
*/
_updatePageImages: function(page, pageSize) {
var startIndex = pageSize * (page - 1);
var images = this.images || [];
this.set('_pageImages', images.slice(startIndex, startIndex + pageSize));
},
/**
* Updates the page to show a new set of images.
*
* @private
*/
_updatePage: function() {
if(this._page === 1) {
this._updatePageImages(this._page, this.pageSize);
} else {
this.set('_page', 1);
}
}
});
})();
</script>
</dom-module>