/
sl-gallery-image.js
105 lines (89 loc) · 3.01 KB
/
sl-gallery-image.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
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
/**
@license
Copyright (c) 2016 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
*/
import { PolymerElement, html } from '@polymer/polymer/polymer-element.js';
class SLGalleryImage extends PolymerElement {
static get template() {
return html`
<style>
:host {
display: inline-block;
overflow: hidden;
cursor: pointer;
/* Placeholder bg color */
background-color: rgba(0, 0, 0, 0.0);
background-size: cover;
background-position: center center;
background-repeat: no-repeat;
/* Required for IE 10 */
-ms-flex: 1 1 100%;
-webkit-flex: 1;
flex: 1;
/* The width for an item is: (100% - subPixelAdjustment - gutter * columns) / columns */
-webkit-flex-basis: calc((100% - 0.1px - (var(--sl-gallery-gutter, 0px) * var(--sl-gallery-columns, 1))) / var(--sl-gallery-columns, 1));
flex-basis: calc((100% - 0.1px - (var(--sl-gallery-gutter, 0px) * var(--sl-gallery-columns, 1))) / var(--sl-gallery-columns, 1));
max-width: calc((100% - 0.1px - (var(--sl-gallery-gutter, 0px) * var(--sl-gallery-columns, 1))) / var(--sl-gallery-columns, 1));
margin-bottom: var(--sl-gallery-gutter, 0px);
margin-right: var(--sl-gallery-gutter, 0px);
height: var(--sl-gallery-item-height);
box-sizing: border-box;
position: relative;
}
:host::before {
display: block;
content: "";
padding-top: var(--sl-gallery-item-height, 100%);
}
/* [TODO] Use or remove. Used only if a inner container is added to this element */
:host > * {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
:host([hidden]) {
display: none;
}
</style>
`;
}
static get is() { return 'sl-gallery-image'; }
static get properties() {
return {
_image: {
type: String,
computed: '_computeImage(src, small)',
observer: '_imageChanged',
},
_hasCaption: {
type: Boolean,
computed: '_computeHasCaption(caption)',
},
src: String,
small: String,
title: String,
caption: String,
};
}
_computeImage(src, small) {
if (small) {
return small;
} else {
return src;
}
}
_computeHasCaption(caption) {
return Boolean(caption);
}
_imageChanged(image) {
this.style.backgroundImage = `url(${image})`;
}
}
window.customElements.define(SLGalleryImage.is, SLGalleryImage);